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