]>
Commit | Line | Data |
---|---|---|
528b2c61 | 1 | /* |
bbc27441 | 2 | * Copyright (C) 1996-2014 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 | ||
582c2af2 FC |
12 | #include "base/CbcPointer.h" |
13 | #include "Debug.h" | |
c8f1812b | 14 | #include "err_type.h" |
582c2af2 | 15 | #include "HierarchyLogEntry.h" |
f35c0145 | 16 | #include "http/RequestMethod.h" |
e74be5fd | 17 | #include "HttpMsg.h" |
d06e17ea | 18 | #include "Notes.h" |
f206b652 | 19 | #include "RequestFlags.h" |
4e3f4dc7 | 20 | #include "URL.h" |
582c2af2 FC |
21 | |
22 | #if USE_AUTH | |
23 | #include "auth/UserRequest.h" | |
24 | #endif | |
3ff65596 AR |
25 | #if USE_ADAPTATION |
26 | #include "adaptation/History.h" | |
27 | #endif | |
28 | #if ICAP_CLIENT | |
29 | #include "adaptation/icap/History.h" | |
30 | #endif | |
a98c2da5 AJ |
31 | #if USE_SQUID_EUI |
32 | #include "eui/Eui48.h" | |
33 | #include "eui/Eui64.h" | |
34 | #endif | |
582c2af2 FC |
35 | |
36 | class ConnStateData; | |
a2ac85d9 | 37 | |
924f73bc | 38 | /* Http Request */ |
8a648e8d | 39 | void httpRequestPack(void *obj, Packer *p); |
5cafad19 | 40 | |
924f73bc | 41 | class HttpHdrRange; |
3ff65596 | 42 | class DnsLookupDetails; |
924f73bc | 43 | |
8596962e | 44 | class HttpRequest: public HttpMsg |
a2ac85d9 | 45 | { |
741c2986 | 46 | MEMPROXY_CLASS(HttpRequest); |
a2ac85d9 | 47 | |
48 | public: | |
b248c2a3 | 49 | typedef RefCount<HttpRequest> Pointer; |
f3630c67 | 50 | |
75faaa7a | 51 | HttpRequest(); |
0c3d3f65 | 52 | HttpRequest(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *aUrlpath); |
5cafad19 | 53 | ~HttpRequest(); |
8596962e | 54 | virtual void reset(); |
4a56ee8d | 55 | |
0c3d3f65 | 56 | void initHTTP(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *aUrlpath); |
75faaa7a | 57 | |
fa0e6114 AR |
58 | virtual HttpRequest *clone() const; |
59 | ||
c2a7cefd AJ |
60 | /// Whether response to this request is potentially cachable |
61 | /// \retval false Not cacheable. | |
62 | /// \retval true Possibly cacheable. Response factors will determine. | |
63 | bool maybeCacheable(); | |
610ee341 | 64 | |
79c8035e AR |
65 | bool conditional() const; ///< has at least one recognized If-* header |
66 | ||
655daa06 AR |
67 | /// whether the client is likely to be able to handle a 1xx reply |
68 | bool canHandle1xx() const; | |
69 | ||
cc192b50 | 70 | /* Now that we care what host contains it is better off being protected. */ |
71 | /* HACK: These two methods are only inline to get around Makefile dependancies */ | |
72 | /* caused by HttpRequest being used in places it really shouldn't. */ | |
73 | /* ideally they would be methods of URL instead. */ | |
26ac0430 | 74 | inline void SetHost(const char *src) { |
4dd643d5 | 75 | host_addr.setEmpty(); |
cc192b50 | 76 | host_addr = src; |
4dd643d5 | 77 | if (host_addr.isAnyAddr()) { |
cc192b50 | 78 | xstrncpy(host, src, SQUIDHOSTNAMELEN); |
12ef783b | 79 | host_is_numeric = 0; |
26ac0430 | 80 | } else { |
4dd643d5 | 81 | host_addr.toHostStr(host, SQUIDHOSTNAMELEN); |
cc192b50 | 82 | debugs(23, 3, "HttpRequest::SetHost() given IP: " << host_addr); |
12ef783b | 83 | host_is_numeric = 1; |
cc192b50 | 84 | } |
c9ecfe8a | 85 | safe_free(canonical); // force its re-build |
cc192b50 | 86 | }; |
87 | inline const char* GetHost(void) const { return host; }; | |
1dc746da | 88 | inline int GetHostIsNumeric(void) const { return host_is_numeric; }; |
cc192b50 | 89 | |
3ff65596 AR |
90 | #if USE_ADAPTATION |
91 | /// Returns possibly nil history, creating it if adapt. logging is enabled | |
a22e6cd3 AR |
92 | Adaptation::History::Pointer adaptLogHistory() const; |
93 | /// Returns possibly nil history, creating it if requested | |
94 | Adaptation::History::Pointer adaptHistory(bool createIfNone = false) const; | |
aaf0559d AR |
95 | /// Makes their history ours, throwing on conflicts |
96 | void adaptHistoryImport(const HttpRequest &them); | |
3ff65596 AR |
97 | #endif |
98 | #if ICAP_CLIENT | |
99 | /// Returns possibly nil history, creating it if icap logging is enabled | |
100 | Adaptation::Icap::History::Pointer icapHistory() const; | |
101 | #endif | |
102 | ||
103 | void recordLookup(const DnsLookupDetails &detail); | |
104 | ||
64b66b76 CT |
105 | /// sets error detail if no earlier detail was available |
106 | void detailError(err_type aType, int aDetail); | |
129fe2a1 CT |
107 | /// clear error details, useful for retries/repeats |
108 | void clearError(); | |
64b66b76 | 109 | |
5cafad19 | 110 | protected: |
5cafad19 | 111 | void clean(); |
5cafad19 | 112 | |
4a56ee8d | 113 | void init(); |
a2ac85d9 | 114 | |
5cafad19 | 115 | public: |
60745f24 | 116 | HttpRequestMethod method; |
4a56ee8d | 117 | |
4e3f4dc7 | 118 | // TODO expand to include all URI parts |
92d6986d | 119 | URL url; ///< the request URI (scheme and userinfo only) |
4a56ee8d | 120 | |
cc192b50 | 121 | private: |
122 | char host[SQUIDHOSTNAMELEN]; | |
12ef783b | 123 | int host_is_numeric; |
26ac0430 | 124 | |
3ff65596 AR |
125 | #if USE_ADAPTATION |
126 | mutable Adaptation::History::Pointer adaptHistory_; ///< per-HTTP transaction info | |
127 | #endif | |
128 | #if ICAP_CLIENT | |
129 | mutable Adaptation::Icap::History::Pointer icapHistory_; ///< per-HTTP transaction info | |
130 | #endif | |
131 | ||
cc192b50 | 132 | public: |
b7ac5457 | 133 | Ip::Address host_addr; |
2f1431ea | 134 | #if USE_AUTH |
c7baff40 | 135 | Auth::UserRequest::Pointer auth_user_request; |
2f1431ea | 136 | #endif |
f45dd259 | 137 | unsigned short port; |
4a56ee8d | 138 | |
30abd221 | 139 | String urlpath; |
4a56ee8d | 140 | |
a2ac85d9 | 141 | char *canonical; |
4a56ee8d | 142 | |
a8a0b1c2 EC |
143 | /** |
144 | * If defined, store_id_program mapped the request URL to this ID. | |
145 | * Store uses this ID (and not the URL) to find and store entries, | |
146 | * avoiding caching duplicate entries when different URLs point to | |
147 | * "essentially the same" cachable resource. | |
148 | */ | |
149 | String store_id; | |
150 | ||
f206b652 | 151 | RequestFlags flags; |
4a56ee8d | 152 | |
a2ac85d9 | 153 | HttpHdrRange *range; |
4a56ee8d | 154 | |
a2ac85d9 | 155 | time_t ims; |
4a56ee8d | 156 | |
a2ac85d9 | 157 | int imslen; |
4a56ee8d | 158 | |
b7ac5457 | 159 | Ip::Address client_addr; |
4a56ee8d | 160 | |
33b24cf0 | 161 | #if FOLLOW_X_FORWARDED_FOR |
b7ac5457 | 162 | Ip::Address indirect_client_addr; |
33b24cf0 | 163 | #endif /* FOLLOW_X_FORWARDED_FOR */ |
3d674977 | 164 | |
b7ac5457 | 165 | Ip::Address my_addr; |
4a56ee8d | 166 | |
a2ac85d9 | 167 | HierarchyLogEntry hier; |
4a56ee8d | 168 | |
3ff65596 AR |
169 | int dnsWait; ///< sum of DNS lookup delays in milliseconds, for %dt |
170 | ||
a2ac85d9 | 171 | err_type errType; |
64b66b76 | 172 | int errDetail; ///< errType-specific detail about the transaction error |
4a56ee8d | 173 | |
f53969cc | 174 | char *peer_login; /* Configured peer login:password */ |
4a56ee8d | 175 | |
9ca29d23 AJ |
176 | char *peer_host; /* Selected peer host*/ |
177 | ||
f53969cc | 178 | time_t lastmod; /* Used on refreshes */ |
4a56ee8d | 179 | |
f53969cc | 180 | const char *vary_headers; /* Used when varying entities are detected. Changes how the store key is calculated */ |
4a56ee8d | 181 | |
f53969cc | 182 | char *peer_domain; /* Configured peer forceddomain */ |
4a56ee8d | 183 | |
35fb56c9 AJ |
184 | String myportname; // Internal tag name= value from port this requests arrived in. |
185 | ||
f4f55a21 | 186 | NotePairs::Pointer notes; ///< annotations added by the note directive and helpers |
d06e17ea | 187 | |
f53969cc | 188 | String tag; /* Internal tag for this request */ |
4a56ee8d | 189 | |
f53969cc | 190 | String extacl_user; /* User name returned by extacl lookup */ |
4a56ee8d | 191 | |
f53969cc | 192 | String extacl_passwd; /* Password returned by extacl lookup */ |
4a56ee8d | 193 | |
f53969cc | 194 | String extacl_log; /* String to be used for access.log purposes */ |
8596962e | 195 | |
f53969cc | 196 | String extacl_message; /* String to be used for error page purposes */ |
8c93a598 | 197 | |
33b24cf0 | 198 | #if FOLLOW_X_FORWARDED_FOR |
3d674977 | 199 | String x_forwarded_for_iterator; /* XXX a list of IP addresses */ |
33b24cf0 | 200 | #endif /* FOLLOW_X_FORWARDED_FOR */ |
3d674977 | 201 | |
46017fdd CT |
202 | /// A strong etag of the cached entry. Used for refreshing that entry. |
203 | String etag; | |
204 | ||
ec69bdb2 CT |
205 | /// whether we have responded with HTTP 100 or FTP 150 already |
206 | bool forcedBodyContinuation; | |
207 | ||
8596962e | 208 | public: |
5cafad19 | 209 | bool multipartRangeRequest() const; |
4a56ee8d | 210 | |
429f7150 | 211 | bool parseFirstLine(const char *start, const char *end); |
4a56ee8d | 212 | |
784619e6 | 213 | bool parseHeader(Http1::RequestParser &hp); // TODO move this function to the parser |
4a56ee8d | 214 | |
60745f24 | 215 | virtual bool expectingBody(const HttpRequestMethod& unused, int64_t&) const; |
4a56ee8d | 216 | |
58217e94 | 217 | bool bodyNibbled() const; // the request has a [partially] consumed body |
218 | ||
5cafad19 | 219 | int prefixLen(); |
4a56ee8d | 220 | |
5cafad19 | 221 | void swapOut(StoreEntry * e); |
4a56ee8d | 222 | |
5cafad19 | 223 | void pack(Packer * p); |
4a56ee8d | 224 | |
5cafad19 | 225 | static void httpRequestPack(void *obj, Packer *p); |
8596962e | 226 | |
60745f24 | 227 | static HttpRequest * CreateFromUrlAndMethod(char * url, const HttpRequestMethod& method); |
c21ad0f5 | 228 | |
229 | static HttpRequest * CreateFromUrl(char * url); | |
26ac0430 | 230 | |
582c2af2 | 231 | ConnStateData *pinnedConnection(); |
d67acb4e | 232 | |
a8a0b1c2 EC |
233 | /** |
234 | * Returns the current StoreID for the request as a nul-terminated char*. | |
235 | * Always returns the current id for the request | |
236 | * (either the request canonical url or modified ID by the helper). | |
237 | * Does not return NULL. | |
238 | */ | |
239 | const char *storeId(); | |
240 | ||
b1cf2350 AJ |
241 | /** |
242 | * The client connection manager, if known; | |
243 | * Used for any response actions needed directly to the client. | |
244 | * ie 1xx forwarding or connection pinning state changes | |
245 | */ | |
40d34a62 | 246 | CbcPointer<ConnStateData> clientConnectionManager; |
655daa06 | 247 | |
f0baf149 AR |
248 | /// forgets about the cached Range header (for a reason) |
249 | void ignoreRange(const char *reason); | |
11e3fa1c AJ |
250 | int64_t getRangeOffsetLimit(); /* the result of this function gets cached in rangeOffsetLimit */ |
251 | ||
8596962e | 252 | private: |
253 | const char *packableURI(bool full_uri) const; | |
254 | ||
11e3fa1c AJ |
255 | mutable int64_t rangeOffsetLimit; /* caches the result of getRangeOffsetLimit */ |
256 | ||
8596962e | 257 | protected: |
258 | virtual void packFirstLineInto(Packer * p, bool full_uri) const; | |
4a56ee8d | 259 | |
955394ce | 260 | virtual bool sanityCheckStartLine(MemBuf *buf, const size_t hdr_len, Http::StatusCode *error); |
4a56ee8d | 261 | |
07947ad8 | 262 | virtual void hdrCacheInit(); |
26ac0430 | 263 | |
d67acb4e | 264 | virtual bool inheritProperties(const HttpMsg *aMsg); |
a2ac85d9 | 265 | }; |
528b2c61 | 266 | |
528b2c61 | 267 | #endif /* SQUID_HTTPREQUEST_H */ |
f53969cc | 268 |