]>
Commit | Line | Data |
---|---|---|
88a1614b | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 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 | ||
9 | #ifndef SQUID_CLIENTSIDEREPLY_H | |
10 | #define SQUID_CLIENTSIDEREPLY_H | |
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 *); |
88a1614b | 32 | ~clientReplyContext(); |
33 | ||
34 | void saveState(); | |
35 | void restoreState(); | |
36 | void purgeRequest (); | |
88a1614b | 37 | void sendClientUpstreamResponse(); |
88a1614b | 38 | void doGetMoreData(); |
39 | void identifyStoreObject(); | |
7976fed3 | 40 | void identifyFoundObject(StoreEntry *entry, const char *detail); |
88a1614b | 41 | int storeOKTransferDone() const; |
42 | int storeNotOKTransferDone() const; | |
7a957a93 | 43 | /// replaces current response store entry with the given one |
f0baf149 | 44 | void setReplyToStoreEntry(StoreEntry *e, const char *reason); |
7a957a93 | 45 | /// builds error using clientBuildError() and calls setReplyToError() below |
7976fed3 | 46 | void setReplyToError(err_type, Http::StatusCode, const HttpRequestMethod&, char const *, const ConnStateData *, HttpRequest *, const char *, |
2f1431ea | 47 | #if USE_AUTH |
c7baff40 | 48 | Auth::UserRequest::Pointer); |
2f1431ea | 49 | #else |
9d2b8284 | 50 | void * unused); |
2f1431ea | 51 | #endif |
7a957a93 AR |
52 | /// creates a store entry for the reply and appends err to it |
53 | void setReplyToError(const HttpRequestMethod& method, ErrorState *err); | |
eacfca83 AR |
54 | /// creates a store entry for the reply and appends error reply to it |
55 | void setReplyToReply(HttpReply *reply); | |
f206b652 | 56 | void createStoreEntry(const HttpRequestMethod& m, RequestFlags flags); |
88a1614b | 57 | void removeStoreReference(store_client ** scp, StoreEntry ** ep); |
86a2f789 | 58 | void removeClientStoreReference(store_client **scp, ClientHttpRequest *http); |
88a1614b | 59 | void startError(ErrorState * err); |
88a1614b | 60 | void processExpired(); |
61 | clientStream_status_t replyStatus(); | |
62 | void processMiss(); | |
63 | void traceReply(clientStreamNode * node); | |
a8a0b1c2 | 64 | const char *storeId() const { return (http->store_id.size() > 0 ? http->store_id.termedBuf() : http->uri); } |
88a1614b | 65 | |
955394ce | 66 | Http::StatusCode purgeStatus; |
88a1614b | 67 | |
d2a6dcba | 68 | /* StoreClient API */ |
7976fed3 | 69 | virtual LogTags *loggingTags() const; |
88a1614b | 70 | |
59a1efb2 | 71 | ClientHttpRequest *http; |
66d51f4f AR |
72 | /// Base reply header bytes received from Store. |
73 | /// Compatible with ClientHttpRequest::Out::offset. | |
74 | /// Not to be confused with ClientHttpRequest::Out::headers_sz. | |
88a1614b | 75 | int headers_sz; |
f53969cc SM |
76 | store_client *sc; /* The store_client we're using */ |
77 | StoreIOBuffer tempBuffer; /* For use in validating requests via IMS */ | |
78 | int old_reqsize; /* ... again, for the buffer */ | |
88a1614b | 79 | size_t reqsize; |
57d55dfa | 80 | size_t reqofs; |
cc8c4af2 | 81 | char tempbuf[HTTP_REQBUF_SZ]; ///< a temporary buffer if we need working storage |
88a1614b | 82 | |
cc8c4af2 AJ |
83 | struct Flags { |
84 | Flags() : storelogiccomplete(0), complete(0), headersSent(false) {} | |
88a1614b | 85 | |
26ac0430 | 86 | unsigned storelogiccomplete:1; |
cc8c4af2 | 87 | unsigned complete:1; ///< we have read all we can from upstream |
88a1614b | 88 | bool headersSent; |
2fadd50d | 89 | } flags; |
f53969cc | 90 | clientStreamNode *ourNode; /* This will go away if/when this file gets refactored some more */ |
88a1614b | 91 | |
92 | private: | |
819be284 EB |
93 | /* StoreClient API */ |
94 | virtual void fillChecklist(ACLFilledChecklist &) const; | |
95 | ||
88a1614b | 96 | clientStreamNode *getNextNode() const; |
97 | void makeThisHead(); | |
98 | bool errorInStream(StoreIOBuffer const &result, size_t const &sizeToProcess)const ; | |
99 | void sendStreamError(StoreIOBuffer const &result); | |
100 | void pushStreamData(StoreIOBuffer const &result, char *source); | |
88a1614b | 101 | clientStreamNode * next() const; |
88a1614b | 102 | StoreIOBuffer holdingBuffer; |
7dc5f514 | 103 | HttpReply *reply; |
88a1614b | 104 | void processReplyAccess(); |
2efeb0b7 | 105 | static ACLCB ProcessReplyAccessResult; |
329c128c | 106 | void processReplyAccessResult(const Acl::Answer &accessAllowed); |
b297bcd0 | 107 | void cloneReply(); |
88a1614b | 108 | void buildReplyHeader (); |
955394ce | 109 | bool alwaysAllowResponse(Http::StatusCode sline) const; |
88a1614b | 110 | int checkTransferDone(); |
111 | void processOnlyIfCachedMiss(); | |
acd68301 | 112 | bool processConditional(StoreIOBuffer &result); |
88a1614b | 113 | void cacheHit(StoreIOBuffer result); |
114 | void handleIMSReply(StoreIOBuffer result); | |
115 | void sendMoreData(StoreIOBuffer result); | |
116 | void triggerInitialStoreRead(); | |
88a1614b | 117 | void sendClientOldEntry(); |
60745f24 | 118 | void purgeAllCached(); |
7976fed3 EB |
119 | /// attempts to release the cached entry |
120 | /// \returns whether the entry was released | |
121 | bool purgeEntry(StoreEntry &, const Http::MethodType, const char *descriptionPrefix = ""); | |
122 | /// releases both cached GET and HEAD entries | |
123 | void purgeDoPurge(); | |
7681a3b9 | 124 | void forgetHit(); |
70706149 | 125 | bool blockedHit() const; |
7976fed3 | 126 | const char *storeLookupString(bool found) const { return found ? "match" : "mismatch"; } |
5fdc5490 | 127 | void detailStoreLookup(const char *detail); |
b51aec66 | 128 | |
16611143 | 129 | void sendBodyTooLargeError(); |
79c8035e | 130 | void sendPreconditionFailedError(); |
a2bd457d AJ |
131 | void sendNotModified(); |
132 | void sendNotModifiedOrPreconditionFailedError(); | |
88a1614b | 133 | |
5fdc5490 AJ |
134 | /// Classification of the initial Store lookup. |
135 | /// This very first lookup happens without the Vary-driven key augmentation. | |
136 | /// TODO: Exclude internal Store match bans from the "mismatch" category. | |
137 | const char *firstStoreLookup_ = nullptr; | |
138 | ||
88a1614b | 139 | StoreEntry *old_entry; |
e7e0f8a4 EB |
140 | /* ... for entry to be validated */ |
141 | store_client *old_sc; | |
142 | time_t old_lastmod; | |
143 | String old_etag; | |
144 | ||
50c09fc4 | 145 | bool deleting; |
1a210de4 EB |
146 | |
147 | typedef enum { | |
148 | crNone = 0, ///< collapsed revalidation is not allowed for this context | |
149 | crInitiator, ///< we initiated collapsed revalidation request | |
150 | crSlave ///< we collapsed on the existing revalidation request | |
151 | } CollapsedRevalidation; | |
152 | ||
153 | CollapsedRevalidation collapsedRevalidation; | |
88a1614b | 154 | }; |
155 | ||
156 | #endif /* SQUID_CLIENTSIDEREPLY_H */ | |
f53969cc | 157 |