]>
Commit | Line | Data |
---|---|---|
88a1614b | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
88a1614b | 3 | * |
bbc27441 AJ |
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. | |
88a1614b | 7 | */ |
8 | ||
ff9d9458 FC |
9 | #ifndef SQUID_SRC_CLIENT_SIDE_REPLY_H |
10 | #define SQUID_SRC_CLIENT_SIDE_REPLY_H | |
88a1614b | 11 | |
92ae4c86 | 12 | #include "acl/forward.h" |
f206b652 | 13 | #include "client_side_request.h" |
5cc71155 | 14 | #include "ip/forward.h" |
f206b652 | 15 | #include "RequestFlags.h" |
88a1614b | 16 | #include "StoreClient.h" |
aa839030 | 17 | |
18 | class ErrorState; | |
19 | ||
88a1614b | 20 | /* XXX make static method */ |
21 | ||
22 | class clientReplyContext : public RefCountable, public StoreClient | |
23 | { | |
5c2f68b7 | 24 | CBDATA_CLASS(clientReplyContext); |
88a1614b | 25 | |
26 | public: | |
88a1614b | 27 | static STCB CacheHit; |
28 | static STCB HandleIMSReply; | |
29 | static STCB SendMoreData; | |
30 | ||
59a1efb2 | 31 | clientReplyContext(ClientHttpRequest *); |
337b9aa4 | 32 | ~clientReplyContext() override; |
88a1614b | 33 | |
34 | void saveState(); | |
35 | void restoreState(); | |
36 | void purgeRequest (); | |
88a1614b | 37 | void doGetMoreData(); |
38 | void identifyStoreObject(); | |
7976fed3 | 39 | void identifyFoundObject(StoreEntry *entry, const char *detail); |
88a1614b | 40 | int storeOKTransferDone() const; |
41 | int storeNotOKTransferDone() const; | |
7a957a93 | 42 | /// replaces current response store entry with the given one |
f0baf149 | 43 | void setReplyToStoreEntry(StoreEntry *e, const char *reason); |
7a957a93 | 44 | /// builds error using clientBuildError() and calls setReplyToError() below |
eb026889 | 45 | void setReplyToError(err_type, Http::StatusCode, char const *, const ConnStateData *, HttpRequest *, const char *, |
2f1431ea | 46 | #if USE_AUTH |
c7baff40 | 47 | Auth::UserRequest::Pointer); |
2f1431ea | 48 | #else |
9d2b8284 | 49 | void * unused); |
2f1431ea | 50 | #endif |
7a957a93 AR |
51 | /// creates a store entry for the reply and appends err to it |
52 | void setReplyToError(const HttpRequestMethod& method, ErrorState *err); | |
eacfca83 AR |
53 | /// creates a store entry for the reply and appends error reply to it |
54 | void setReplyToReply(HttpReply *reply); | |
f206b652 | 55 | void createStoreEntry(const HttpRequestMethod& m, RequestFlags flags); |
88a1614b | 56 | void removeStoreReference(store_client ** scp, StoreEntry ** ep); |
86a2f789 | 57 | void removeClientStoreReference(store_client **scp, ClientHttpRequest *http); |
88a1614b | 58 | void startError(ErrorState * err); |
88a1614b | 59 | void processExpired(); |
60 | clientStream_status_t replyStatus(); | |
61 | void processMiss(); | |
122a6e3c | 62 | void traceReply(); |
a8a0b1c2 | 63 | const char *storeId() const { return (http->store_id.size() > 0 ? http->store_id.termedBuf() : http->uri); } |
88a1614b | 64 | |
955394ce | 65 | Http::StatusCode purgeStatus; |
88a1614b | 66 | |
d2a6dcba | 67 | /* StoreClient API */ |
337b9aa4 | 68 | LogTags *loggingTags() const override; |
88a1614b | 69 | |
59a1efb2 | 70 | ClientHttpRequest *http; |
f53969cc | 71 | store_client *sc; /* The store_client we're using */ |
122a6e3c AR |
72 | |
73 | /// Buffer dedicated to receiving storeClientCopy() responses to generated | |
74 | /// revalidation requests. These requests cannot use next()->readBuffer | |
75 | /// because the latter keeps the contents of the stale HTTP response during | |
76 | /// revalidation. sendClientOldEntry() uses that contents. | |
77 | char tempbuf[HTTP_REQBUF_SZ]; | |
88a1614b | 78 | |
cc8c4af2 AJ |
79 | struct Flags { |
80 | Flags() : storelogiccomplete(0), complete(0), headersSent(false) {} | |
88a1614b | 81 | |
26ac0430 | 82 | unsigned storelogiccomplete:1; |
cc8c4af2 | 83 | unsigned complete:1; ///< we have read all we can from upstream |
88a1614b | 84 | bool headersSent; |
2fadd50d | 85 | } flags; |
f53969cc | 86 | clientStreamNode *ourNode; /* This will go away if/when this file gets refactored some more */ |
88a1614b | 87 | |
88 | private: | |
819be284 | 89 | /* StoreClient API */ |
337b9aa4 | 90 | void fillChecklist(ACLFilledChecklist &) const override; |
819be284 | 91 | |
88a1614b | 92 | clientStreamNode *getNextNode() const; |
93 | void makeThisHead(); | |
122a6e3c AR |
94 | bool errorInStream(const StoreIOBuffer &result) const; |
95 | bool matchesStreamBodyBuffer(const StoreIOBuffer &) const; | |
88a1614b | 96 | void sendStreamError(StoreIOBuffer const &result); |
122a6e3c | 97 | void pushStreamData(const StoreIOBuffer &); |
88a1614b | 98 | clientStreamNode * next() const; |
7dc5f514 | 99 | HttpReply *reply; |
88a1614b | 100 | void processReplyAccess(); |
2efeb0b7 | 101 | static ACLCB ProcessReplyAccessResult; |
329c128c | 102 | void processReplyAccessResult(const Acl::Answer &accessAllowed); |
b297bcd0 | 103 | void cloneReply(); |
88a1614b | 104 | void buildReplyHeader (); |
955394ce | 105 | bool alwaysAllowResponse(Http::StatusCode sline) const; |
88a1614b | 106 | int checkTransferDone(); |
107 | void processOnlyIfCachedMiss(); | |
8b082ed9 | 108 | bool processConditional(); |
122a6e3c | 109 | void noteStreamBufferredBytes(const StoreIOBuffer &); |
88a1614b | 110 | void cacheHit(StoreIOBuffer result); |
111 | void handleIMSReply(StoreIOBuffer result); | |
112 | void sendMoreData(StoreIOBuffer result); | |
122a6e3c AR |
113 | void triggerInitialStoreRead(STCB = SendMoreData); |
114 | void requestMoreBodyFromStore(); | |
88a1614b | 115 | void sendClientOldEntry(); |
60745f24 | 116 | void purgeAllCached(); |
7976fed3 EB |
117 | /// attempts to release the cached entry |
118 | /// \returns whether the entry was released | |
119 | bool purgeEntry(StoreEntry &, const Http::MethodType, const char *descriptionPrefix = ""); | |
120 | /// releases both cached GET and HEAD entries | |
121 | void purgeDoPurge(); | |
7681a3b9 | 122 | void forgetHit(); |
70706149 | 123 | bool blockedHit() const; |
7976fed3 | 124 | const char *storeLookupString(bool found) const { return found ? "match" : "mismatch"; } |
5fdc5490 | 125 | void detailStoreLookup(const char *detail); |
b51aec66 | 126 | |
16611143 | 127 | void sendBodyTooLargeError(); |
79c8035e | 128 | void sendPreconditionFailedError(); |
a2bd457d AJ |
129 | void sendNotModified(); |
130 | void sendNotModifiedOrPreconditionFailedError(); | |
122a6e3c AR |
131 | void sendClientUpstreamResponse(const StoreIOBuffer &upstreamResponse); |
132 | ||
133 | /// Reduces a chance of an accidental direct storeClientCopy() call that | |
134 | /// (should but) forgets to invalidate our lastStreamBufferedBytes. This | |
135 | /// function is not defined; decltype() syntax prohibits "= delete", but | |
136 | /// function usage will trigger deprecation warnings and linking errors. | |
137 | static decltype(::storeClientCopy) storeClientCopy [[deprecated]]; | |
88a1614b | 138 | |
5fdc5490 AJ |
139 | /// Classification of the initial Store lookup. |
140 | /// This very first lookup happens without the Vary-driven key augmentation. | |
141 | /// TODO: Exclude internal Store match bans from the "mismatch" category. | |
142 | const char *firstStoreLookup_ = nullptr; | |
143 | ||
5921355e | 144 | /* (stale) cache hit information preserved during IMS revalidation */ |
88a1614b | 145 | StoreEntry *old_entry; |
e7e0f8a4 EB |
146 | store_client *old_sc; |
147 | time_t old_lastmod; | |
148 | String old_etag; | |
149 | ||
50c09fc4 | 150 | bool deleting; |
1a210de4 EB |
151 | |
152 | typedef enum { | |
153 | crNone = 0, ///< collapsed revalidation is not allowed for this context | |
154 | crInitiator, ///< we initiated collapsed revalidation request | |
155 | crSlave ///< we collapsed on the existing revalidation request | |
156 | } CollapsedRevalidation; | |
157 | ||
158 | CollapsedRevalidation collapsedRevalidation; | |
122a6e3c AR |
159 | |
160 | /// HTTP response body bytes stored in our Client Stream buffer (if any) | |
161 | StoreIOBuffer lastStreamBufferedBytes; | |
162 | ||
163 | // TODO: Remove after moving the meat of this function into a method. | |
164 | friend CSR clientGetMoreData; | |
88a1614b | 165 | }; |
166 | ||
8b082ed9 FC |
167 | // TODO: move to SideAgent parent, when we have one |
168 | void purgeEntriesByUrl(HttpRequest *, const char *); | |
169 | ||
ff9d9458 | 170 | #endif /* SQUID_SRC_CLIENT_SIDE_REPLY_H */ |
f53969cc | 171 |