]> git.ipfire.org Git - thirdparty/squid.git/blob - src/client_side_reply.h
3e551c1cc79838de13afca2e1473a5d93407d2ff
[thirdparty/squid.git] / src / client_side_reply.h
1 /*
2 * Copyright (C) 1996-2019 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
78 /* StoreClient API */
79 virtual void created (StoreEntry *newEntry);
80 virtual LogTags *loggingTags();
81
82 ClientHttpRequest *http;
83 /// Base reply header bytes received from Store.
84 /// Compatible with ClientHttpRequest::Out::offset.
85 /// Not to be confused with ClientHttpRequest::Out::headers_sz.
86 int headers_sz;
87 store_client *sc; /* The store_client we're using */
88 StoreIOBuffer tempBuffer; /* For use in validating requests via IMS */
89 int old_reqsize; /* ... again, for the buffer */
90 size_t reqsize;
91 size_t reqofs;
92 char tempbuf[HTTP_REQBUF_SZ]; ///< a temporary buffer if we need working storage
93 #if USE_CACHE_DIGESTS
94
95 const char *lookup_type; /* temporary hack: storeGet() result: HIT/MISS/NONE */
96 #endif
97
98 struct Flags {
99 Flags() : storelogiccomplete(0), complete(0), headersSent(false) {}
100
101 unsigned storelogiccomplete:1;
102 unsigned complete:1; ///< we have read all we can from upstream
103 bool headersSent;
104 } flags;
105 clientStreamNode *ourNode; /* This will go away if/when this file gets refactored some more */
106
107 private:
108 /* StoreClient API */
109 virtual void fillChecklist(ACLFilledChecklist &) const;
110
111 clientStreamNode *getNextNode() const;
112 void makeThisHead();
113 bool errorInStream(StoreIOBuffer const &result, size_t const &sizeToProcess)const ;
114 void sendStreamError(StoreIOBuffer const &result);
115 void pushStreamData(StoreIOBuffer const &result, char *source);
116 clientStreamNode * next() const;
117 StoreIOBuffer holdingBuffer;
118 HttpReply *reply;
119 void processReplyAccess();
120 static ACLCB ProcessReplyAccessResult;
121 void processReplyAccessResult(const Acl::Answer &accessAllowed);
122 void cloneReply();
123 void buildReplyHeader ();
124 bool alwaysAllowResponse(Http::StatusCode sline) const;
125 int checkTransferDone();
126 void processOnlyIfCachedMiss();
127 bool processConditional(StoreIOBuffer &result);
128 void cacheHit(StoreIOBuffer result);
129 void handleIMSReply(StoreIOBuffer result);
130 void sendMoreData(StoreIOBuffer result);
131 void triggerInitialStoreRead();
132 void sendClientOldEntry();
133 void purgeAllCached();
134 void forgetHit();
135 bool blockedHit() const;
136
137 void sendBodyTooLargeError();
138 void sendPreconditionFailedError();
139 void sendNotModified();
140 void sendNotModifiedOrPreconditionFailedError();
141
142 StoreEntry *old_entry;
143 /* ... for entry to be validated */
144 store_client *old_sc;
145 time_t old_lastmod;
146 String old_etag;
147
148 bool deleting;
149
150 typedef enum {
151 crNone = 0, ///< collapsed revalidation is not allowed for this context
152 crInitiator, ///< we initiated collapsed revalidation request
153 crSlave ///< we collapsed on the existing revalidation request
154 } CollapsedRevalidation;
155
156 CollapsedRevalidation collapsedRevalidation;
157 };
158
159 #endif /* SQUID_CLIENTSIDEREPLY_H */
160