]>
Commit | Line | Data |
---|---|---|
528b2c61 | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
528b2c61 | 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. | |
528b2c61 | 7 | */ |
8 | ||
9 | #ifndef SQUID_HTTPREQUEST_H | |
10 | #define SQUID_HTTPREQUEST_H | |
11 | ||
c8ab5ec6 | 12 | #include "anyp/Uri.h" |
582c2af2 | 13 | #include "base/CbcPointer.h" |
4a3b98d7 | 14 | #include "dns/forward.h" |
83b053a0 | 15 | #include "error/Error.h" |
582c2af2 | 16 | #include "HierarchyLogEntry.h" |
63df1d28 | 17 | #include "http/Message.h" |
f35c0145 | 18 | #include "http/RequestMethod.h" |
e16571ed | 19 | #include "MasterXaction.h" |
d06e17ea | 20 | #include "Notes.h" |
f206b652 | 21 | #include "RequestFlags.h" |
582c2af2 FC |
22 | |
23 | #if USE_AUTH | |
24 | #include "auth/UserRequest.h" | |
25 | #endif | |
3ff65596 AR |
26 | #if USE_ADAPTATION |
27 | #include "adaptation/History.h" | |
28 | #endif | |
29 | #if ICAP_CLIENT | |
30 | #include "adaptation/icap/History.h" | |
31 | #endif | |
a98c2da5 AJ |
32 | #if USE_SQUID_EUI |
33 | #include "eui/Eui48.h" | |
34 | #include "eui/Eui64.h" | |
35 | #endif | |
582c2af2 | 36 | |
cd4a5c60 CT |
37 | class AccessLogEntry; |
38 | typedef RefCount<AccessLogEntry> AccessLogEntryPointer; | |
f5e17947 CT |
39 | class CachePeer; |
40 | class ConnStateData; | |
41 | class Downloader; | |
a2ac85d9 | 42 | |
924f73bc | 43 | /* Http Request */ |
17802cf1 | 44 | void httpRequestPack(void *obj, Packable *p); |
5cafad19 | 45 | |
924f73bc | 46 | class HttpHdrRange; |
47 | ||
63df1d28 | 48 | class HttpRequest: public Http::Message |
a2ac85d9 | 49 | { |
741c2986 | 50 | MEMPROXY_CLASS(HttpRequest); |
a2ac85d9 | 51 | |
52 | public: | |
b248c2a3 | 53 | typedef RefCount<HttpRequest> Pointer; |
f3630c67 | 54 | |
e16571ed AJ |
55 | HttpRequest(const MasterXaction::Pointer &); |
56 | HttpRequest(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *schemeImage, const char *aUrlpath, const MasterXaction::Pointer &); | |
5cafad19 | 57 | ~HttpRequest(); |
8596962e | 58 | virtual void reset(); |
4a56ee8d | 59 | |
d31d59d8 | 60 | void initHTTP(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *schemeImage, const char *aUrlpath); |
75faaa7a | 61 | |
fa0e6114 AR |
62 | virtual HttpRequest *clone() const; |
63 | ||
c2a7cefd AJ |
64 | /// Whether response to this request is potentially cachable |
65 | /// \retval false Not cacheable. | |
66 | /// \retval true Possibly cacheable. Response factors will determine. | |
67 | bool maybeCacheable(); | |
610ee341 | 68 | |
79c8035e AR |
69 | bool conditional() const; ///< has at least one recognized If-* header |
70 | ||
655daa06 AR |
71 | /// whether the client is likely to be able to handle a 1xx reply |
72 | bool canHandle1xx() const; | |
73 | ||
bec110e4 EB |
74 | /// \returns a pointer to a local static buffer containing request URI |
75 | /// that honors strip_query_terms and %-encodes unsafe URI characters | |
76 | char *canonicalCleanUrl() const; | |
77 | ||
3ff65596 AR |
78 | #if USE_ADAPTATION |
79 | /// Returns possibly nil history, creating it if adapt. logging is enabled | |
a22e6cd3 AR |
80 | Adaptation::History::Pointer adaptLogHistory() const; |
81 | /// Returns possibly nil history, creating it if requested | |
82 | Adaptation::History::Pointer adaptHistory(bool createIfNone = false) const; | |
aaf0559d AR |
83 | /// Makes their history ours, throwing on conflicts |
84 | void adaptHistoryImport(const HttpRequest &them); | |
3ff65596 AR |
85 | #endif |
86 | #if ICAP_CLIENT | |
87 | /// Returns possibly nil history, creating it if icap logging is enabled | |
88 | Adaptation::Icap::History::Pointer icapHistory() const; | |
89 | #endif | |
90 | ||
f5e17947 CT |
91 | /* If a request goes through several destinations, then the following two |
92 | * methods will be called several times, in destinations-dependent order. */ | |
93 | /// get ready to be sent to the given cache_peer, including originserver | |
94 | void prepForPeering(const CachePeer &peer); | |
95 | /// get ready to be sent directly to an origin server, excluding originserver | |
96 | void prepForDirect(); | |
97 | ||
4a3b98d7 | 98 | void recordLookup(const Dns::LookupDetails &detail); |
3ff65596 | 99 | |
64b66b76 | 100 | /// sets error detail if no earlier detail was available |
83b053a0 | 101 | void detailError(const err_type c, const ErrorDetail::Pointer &d) { error.update(c, d); } |
129fe2a1 CT |
102 | /// clear error details, useful for retries/repeats |
103 | void clearError(); | |
64b66b76 | 104 | |
cd4a5c60 CT |
105 | /// associates the request with a from-client connection manager |
106 | void manager(const CbcPointer<ConnStateData> &aMgr, const AccessLogEntryPointer &al); | |
107 | ||
5cafad19 | 108 | protected: |
5cafad19 | 109 | void clean(); |
5cafad19 | 110 | |
4a56ee8d | 111 | void init(); |
a2ac85d9 | 112 | |
5cafad19 | 113 | public: |
60745f24 | 114 | HttpRequestMethod method; |
c8ab5ec6 | 115 | AnyP::Uri url; ///< the request URI |
4a56ee8d | 116 | |
cc192b50 | 117 | private: |
3ff65596 AR |
118 | #if USE_ADAPTATION |
119 | mutable Adaptation::History::Pointer adaptHistory_; ///< per-HTTP transaction info | |
120 | #endif | |
121 | #if ICAP_CLIENT | |
122 | mutable Adaptation::Icap::History::Pointer icapHistory_; ///< per-HTTP transaction info | |
123 | #endif | |
124 | ||
cc192b50 | 125 | public: |
2f1431ea | 126 | #if USE_AUTH |
c7baff40 | 127 | Auth::UserRequest::Pointer auth_user_request; |
2f1431ea | 128 | #endif |
4a56ee8d | 129 | |
851feda6 AJ |
130 | /// RFC 7230 section 5.5 - Effective Request URI |
131 | const SBuf &effectiveRequestUri() const; | |
4a56ee8d | 132 | |
a8a0b1c2 EC |
133 | /** |
134 | * If defined, store_id_program mapped the request URL to this ID. | |
135 | * Store uses this ID (and not the URL) to find and store entries, | |
136 | * avoiding caching duplicate entries when different URLs point to | |
137 | * "essentially the same" cachable resource. | |
138 | */ | |
139 | String store_id; | |
140 | ||
f206b652 | 141 | RequestFlags flags; |
4a56ee8d | 142 | |
a2ac85d9 | 143 | HttpHdrRange *range; |
4a56ee8d | 144 | |
a2ac85d9 | 145 | time_t ims; |
4a56ee8d | 146 | |
a2ac85d9 | 147 | int imslen; |
4a56ee8d | 148 | |
b7ac5457 | 149 | Ip::Address client_addr; |
4a56ee8d | 150 | |
33b24cf0 | 151 | #if FOLLOW_X_FORWARDED_FOR |
b7ac5457 | 152 | Ip::Address indirect_client_addr; |
33b24cf0 | 153 | #endif /* FOLLOW_X_FORWARDED_FOR */ |
3d674977 | 154 | |
b7ac5457 | 155 | Ip::Address my_addr; |
4a56ee8d | 156 | |
a2ac85d9 | 157 | HierarchyLogEntry hier; |
4a56ee8d | 158 | |
3ff65596 AR |
159 | int dnsWait; ///< sum of DNS lookup delays in milliseconds, for %dt |
160 | ||
83b053a0 | 161 | Error error; ///< the first transaction problem encountered (or falsy) |
4a56ee8d | 162 | |
f53969cc | 163 | char *peer_login; /* Configured peer login:password */ |
4a56ee8d | 164 | |
9ca29d23 AJ |
165 | char *peer_host; /* Selected peer host*/ |
166 | ||
f53969cc | 167 | time_t lastmod; /* Used on refreshes */ |
4a56ee8d | 168 | |
90ab8f20 AJ |
169 | /// The variant second-stage cache key. Generated from Vary header pattern for this request. |
170 | SBuf vary_headers; | |
4a56ee8d | 171 | |
f53969cc | 172 | char *peer_domain; /* Configured peer forceddomain */ |
4a56ee8d | 173 | |
35fb56c9 AJ |
174 | String myportname; // Internal tag name= value from port this requests arrived in. |
175 | ||
f53969cc | 176 | String tag; /* Internal tag for this request */ |
4a56ee8d | 177 | |
f53969cc | 178 | String extacl_user; /* User name returned by extacl lookup */ |
4a56ee8d | 179 | |
f53969cc | 180 | String extacl_passwd; /* Password returned by extacl lookup */ |
4a56ee8d | 181 | |
f53969cc | 182 | String extacl_log; /* String to be used for access.log purposes */ |
8596962e | 183 | |
f53969cc | 184 | String extacl_message; /* String to be used for error page purposes */ |
8c93a598 | 185 | |
33b24cf0 | 186 | #if FOLLOW_X_FORWARDED_FOR |
3d674977 | 187 | String x_forwarded_for_iterator; /* XXX a list of IP addresses */ |
33b24cf0 | 188 | #endif /* FOLLOW_X_FORWARDED_FOR */ |
3d674977 | 189 | |
46017fdd CT |
190 | /// A strong etag of the cached entry. Used for refreshing that entry. |
191 | String etag; | |
192 | ||
ec69bdb2 CT |
193 | /// whether we have responded with HTTP 100 or FTP 150 already |
194 | bool forcedBodyContinuation; | |
195 | ||
8596962e | 196 | public: |
5cafad19 | 197 | bool multipartRangeRequest() const; |
4a56ee8d | 198 | |
429f7150 | 199 | bool parseFirstLine(const char *start, const char *end); |
4a56ee8d | 200 | |
60745f24 | 201 | virtual bool expectingBody(const HttpRequestMethod& unused, int64_t&) const; |
4a56ee8d | 202 | |
58217e94 | 203 | bool bodyNibbled() const; // the request has a [partially] consumed body |
204 | ||
51b5dcf5 | 205 | int prefixLen() const; |
4a56ee8d | 206 | |
5cafad19 | 207 | void swapOut(StoreEntry * e); |
4a56ee8d | 208 | |
1f28a150 | 209 | void pack(Packable * p) const; |
4a56ee8d | 210 | |
17802cf1 | 211 | static void httpRequestPack(void *obj, Packable *p); |
8596962e | 212 | |
6c880a16 AJ |
213 | static HttpRequest * FromUrl(const SBuf &url, const MasterXaction::Pointer &, const HttpRequestMethod &method = Http::METHOD_GET); |
214 | ||
215 | /// \deprecated use SBuf variant instead | |
216 | static HttpRequest * FromUrlXXX(const char * url, const MasterXaction::Pointer &, const HttpRequestMethod &method = Http::METHOD_GET); | |
26ac0430 | 217 | |
582c2af2 | 218 | ConnStateData *pinnedConnection(); |
d67acb4e | 219 | |
a8a0b1c2 EC |
220 | /** |
221 | * Returns the current StoreID for the request as a nul-terminated char*. | |
222 | * Always returns the current id for the request | |
851feda6 | 223 | * (either the effective request URI or modified ID by the helper). |
a8a0b1c2 | 224 | */ |
851feda6 | 225 | const SBuf storeId(); |
a8a0b1c2 | 226 | |
b1cf2350 AJ |
227 | /** |
228 | * The client connection manager, if known; | |
229 | * Used for any response actions needed directly to the client. | |
230 | * ie 1xx forwarding or connection pinning state changes | |
231 | */ | |
40d34a62 | 232 | CbcPointer<ConnStateData> clientConnectionManager; |
655daa06 | 233 | |
4b5ea8a6 | 234 | /// The Downloader object which initiated the HTTP request if any |
cda7024f CT |
235 | CbcPointer<Downloader> downloader; |
236 | ||
5ceaee75 | 237 | /// the master transaction this request belongs to. Never nil. |
e16571ed | 238 | MasterXaction::Pointer masterXaction; |
5ceaee75 | 239 | |
f0baf149 AR |
240 | /// forgets about the cached Range header (for a reason) |
241 | void ignoreRange(const char *reason); | |
11e3fa1c AJ |
242 | int64_t getRangeOffsetLimit(); /* the result of this function gets cached in rangeOffsetLimit */ |
243 | ||
75d47340 CT |
244 | /// \returns existing non-empty transaction annotations, |
245 | /// creates and returns empty annotations otherwise | |
246 | NotePairs::Pointer notes(); | |
247 | bool hasNotes() const { return bool(theNotes) && !theNotes->empty(); } | |
248 | ||
4f1c93a7 EB |
249 | virtual void configureContentLengthInterpreter(Http::ContentLengthInterpreter &) {} |
250 | ||
251 | /// Parses request header using Parser. | |
252 | /// Use it in contexts where the Parser object is available. | |
253 | bool parseHeader(Http1::Parser &hp); | |
254 | /// Parses request header from the buffer. | |
255 | /// Use it in contexts where the Parser object not available. | |
256 | bool parseHeader(const char *buffer, const size_t size); | |
257 | ||
8596962e | 258 | private: |
11e3fa1c AJ |
259 | mutable int64_t rangeOffsetLimit; /* caches the result of getRangeOffsetLimit */ |
260 | ||
75d47340 CT |
261 | /// annotations added by the note directive and helpers |
262 | /// and(or) by annotate_transaction/annotate_client ACLs. | |
263 | NotePairs::Pointer theNotes; | |
8596962e | 264 | protected: |
17802cf1 | 265 | virtual void packFirstLineInto(Packable * p, bool full_uri) const; |
4a56ee8d | 266 | |
84ae6223 | 267 | virtual bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error); |
4a56ee8d | 268 | |
07947ad8 | 269 | virtual void hdrCacheInit(); |
26ac0430 | 270 | |
63df1d28 | 271 | virtual bool inheritProperties(const Http::Message *); |
a2ac85d9 | 272 | }; |
528b2c61 | 273 | |
75d47340 CT |
274 | class ConnStateData; |
275 | /** | |
276 | * Updates ConnStateData ids and HttpRequest notes from helpers received notes. | |
277 | */ | |
278 | void UpdateRequestNotes(ConnStateData *csd, HttpRequest &request, NotePairs const ¬es); | |
279 | ||
ea35939b A |
280 | /// \returns listening/*_port address used by the client connection (or nil) |
281 | /// nil parameter(s) indicate missing caller information and are handled safely | |
282 | const Ip::Address *FindListeningPortAddress(const HttpRequest *, const AccessLogEntry *); | |
283 | ||
528b2c61 | 284 | #endif /* SQUID_HTTPREQUEST_H */ |
f53969cc | 285 |