]> git.ipfire.org Git - thirdparty/squid.git/blob - src/client_side_reply.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / client_side_reply.h
1 /*
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_CLIENTSIDEREPLY_H
10 #define SQUID_CLIENTSIDEREPLY_H
11
12 #include "acl/forward.h"
13 #include "client_side_request.h"
14 #include "ip/forward.h"
15 #include "RequestFlags.h"
16 #include "StoreClient.h"
17
18 class ErrorState;
19
20 /* XXX make static method */
21
22 class clientReplyContext : public RefCountable, public StoreClient
23 {
24 CBDATA_CLASS(clientReplyContext);
25
26 public:
27 static STCB CacheHit;
28 static STCB HandleIMSReply;
29 static STCB SendMoreData;
30
31 clientReplyContext(ClientHttpRequest *);
32 ~clientReplyContext();
33
34 void saveState();
35 void restoreState();
36 void purgeRequest ();
37 void purgeRequestFindObjectToPurge();
38 void purgeDoMissPurge();
39 void purgeFoundGet(StoreEntry *newEntry);
40 void purgeFoundHead(StoreEntry *newEntry);
41 void purgeFoundObject(StoreEntry *entry);
42 void sendClientUpstreamResponse();
43 void purgeDoPurgeGet(StoreEntry *entry);
44 void purgeDoPurgeHead(StoreEntry *entry);
45 void doGetMoreData();
46 void identifyStoreObject();
47 void identifyFoundObject(StoreEntry *entry);
48 int storeOKTransferDone() const;
49 int storeNotOKTransferDone() const;
50 /// replaces current response store entry with the given one
51 void setReplyToStoreEntry(StoreEntry *e, const char *reason);
52 /// builds error using clientBuildError() and calls setReplyToError() below
53 void setReplyToError(err_type, Http::StatusCode, const HttpRequestMethod&, char const *, Ip::Address &, HttpRequest *, const char *,
54 #if USE_AUTH
55 Auth::UserRequest::Pointer);
56 #else
57 void * unused);
58 #endif
59 /// creates a store entry for the reply and appends err to it
60 void setReplyToError(const HttpRequestMethod& method, ErrorState *err);
61 /// creates a store entry for the reply and appends error reply to it
62 void setReplyToReply(HttpReply *reply);
63 void createStoreEntry(const HttpRequestMethod& m, RequestFlags flags);
64 void removeStoreReference(store_client ** scp, StoreEntry ** ep);
65 void removeClientStoreReference(store_client **scp, ClientHttpRequest *http);
66 void startError(ErrorState * err);
67 void processExpired();
68 clientStream_status_t replyStatus();
69 void processMiss();
70 void traceReply(clientStreamNode * node);
71 const char *storeId() const { return (http->store_id.size() > 0 ? http->store_id.termedBuf() : http->uri); }
72
73 Http::StatusCode purgeStatus;
74
75 /* state variable - replace with class to handle storeentries at some point */
76 int lookingforstore;
77 virtual void created (StoreEntry *newEntry);
78
79 ClientHttpRequest *http;
80 int headers_sz;
81 store_client *sc; /* The store_client we're using */
82 StoreIOBuffer tempBuffer; /* For use in validating requests via IMS */
83 int old_reqsize; /* ... again, for the buffer */
84 size_t reqsize;
85 size_t reqofs;
86 char tempbuf[HTTP_REQBUF_SZ]; ///< a temporary buffer if we need working storage
87 #if USE_CACHE_DIGESTS
88
89 const char *lookup_type; /* temporary hack: storeGet() result: HIT/MISS/NONE */
90 #endif
91
92 struct Flags {
93 Flags() : storelogiccomplete(0), complete(0), headersSent(false) {}
94
95 unsigned storelogiccomplete:1;
96 unsigned complete:1; ///< we have read all we can from upstream
97 bool headersSent;
98 } flags;
99 clientStreamNode *ourNode; /* This will go away if/when this file gets refactored some more */
100
101 private:
102 clientStreamNode *getNextNode() const;
103 void makeThisHead();
104 bool errorInStream(StoreIOBuffer const &result, size_t const &sizeToProcess)const ;
105 void sendStreamError(StoreIOBuffer const &result);
106 void pushStreamData(StoreIOBuffer const &result, char *source);
107 clientStreamNode * next() const;
108 StoreIOBuffer holdingBuffer;
109 HttpReply *reply;
110 void processReplyAccess();
111 static ACLCB ProcessReplyAccessResult;
112 void processReplyAccessResult(const allow_t &accessAllowed);
113 void cloneReply();
114 void buildReplyHeader ();
115 bool alwaysAllowResponse(Http::StatusCode sline) const;
116 int checkTransferDone();
117 void processOnlyIfCachedMiss();
118 bool processConditional(StoreIOBuffer &result);
119 void cacheHit(StoreIOBuffer result);
120 void handleIMSReply(StoreIOBuffer result);
121 void sendMoreData(StoreIOBuffer result);
122 void triggerInitialStoreRead();
123 void sendClientOldEntry();
124 void purgeAllCached();
125 void forgetHit();
126 bool blockedHit() const;
127
128 void sendBodyTooLargeError();
129 void sendPreconditionFailedError();
130 void sendNotModified();
131 void sendNotModifiedOrPreconditionFailedError();
132
133 StoreEntry *old_entry;
134 store_client *old_sc; /* ... for entry to be validated */
135 bool deleting;
136
137 typedef enum {
138 crNone = 0, ///< collapsed revalidation is not allowed for this context
139 crInitiator, ///< we initiated collapsed revalidation request
140 crSlave ///< we collapsed on the existing revalidation request
141 } CollapsedRevalidation;
142
143 CollapsedRevalidation collapsedRevalidation;
144 };
145
146 #endif /* SQUID_CLIENTSIDEREPLY_H */
147