]> git.ipfire.org Git - thirdparty/squid.git/blame - src/HttpRequest.h
Polish: Http::MethodType upgrade
[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"
f206b652 40#include "RequestFlags.h"
582c2af2
FC
41
42#if USE_AUTH
43#include "auth/UserRequest.h"
44#endif
3ff65596
AR
45#if USE_ADAPTATION
46#include "adaptation/History.h"
47#endif
48#if ICAP_CLIENT
49#include "adaptation/icap/History.h"
50#endif
a98c2da5
AJ
51#if USE_SQUID_EUI
52#include "eui/Eui48.h"
53#include "eui/Eui64.h"
54#endif
582c2af2
FC
55
56class ConnStateData;
a2ac85d9 57
924f73bc 58/* Http Request */
8a648e8d 59void httpRequestPack(void *obj, Packer *p);
5cafad19 60
924f73bc 61class HttpHdrRange;
3ff65596 62class DnsLookupDetails;
924f73bc 63
8596962e 64class HttpRequest: public HttpMsg
a2ac85d9 65{
66
67public:
f3630c67
AR
68 typedef HttpMsgPointerT<HttpRequest> Pointer;
69
b001e822 70 MEMPROXY_CLASS(HttpRequest);
75faaa7a 71 HttpRequest();
0c3d3f65 72 HttpRequest(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *aUrlpath);
5cafad19 73 ~HttpRequest();
8596962e 74 virtual void reset();
4a56ee8d 75
6dd9f4bd 76 // use HTTPMSGLOCK() instead of calling this directly
26ac0430 77 virtual HttpRequest *_lock() {
6dd9f4bd 78 return static_cast<HttpRequest*>(HttpMsg::_lock());
4a56ee8d 79 };
80
0c3d3f65 81 void initHTTP(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *aUrlpath);
75faaa7a 82
fa0e6114
AR
83 virtual HttpRequest *clone() const;
84
c2a7cefd
AJ
85 /// Whether response to this request is potentially cachable
86 /// \retval false Not cacheable.
87 /// \retval true Possibly cacheable. Response factors will determine.
88 bool maybeCacheable();
610ee341 89
79c8035e
AR
90 bool conditional() const; ///< has at least one recognized If-* header
91
655daa06
AR
92 /// whether the client is likely to be able to handle a 1xx reply
93 bool canHandle1xx() const;
94
cc192b50 95 /* Now that we care what host contains it is better off being protected. */
96 /* HACK: These two methods are only inline to get around Makefile dependancies */
97 /* caused by HttpRequest being used in places it really shouldn't. */
98 /* ideally they would be methods of URL instead. */
26ac0430 99 inline void SetHost(const char *src) {
cc192b50 100 host_addr.SetEmpty();
101 host_addr = src;
26ac0430 102 if ( host_addr.IsAnyAddr() ) {
cc192b50 103 xstrncpy(host, src, SQUIDHOSTNAMELEN);
12ef783b 104 host_is_numeric = 0;
26ac0430 105 } else {
cc192b50 106 host_addr.ToHostname(host, SQUIDHOSTNAMELEN);
107 debugs(23, 3, "HttpRequest::SetHost() given IP: " << host_addr);
12ef783b 108 host_is_numeric = 1;
cc192b50 109 }
c9ecfe8a 110 safe_free(canonical); // force its re-build
cc192b50 111 };
112 inline const char* GetHost(void) const { return host; };
1dc746da 113 inline int GetHostIsNumeric(void) const { return host_is_numeric; };
cc192b50 114
3ff65596
AR
115#if USE_ADAPTATION
116 /// Returns possibly nil history, creating it if adapt. logging is enabled
a22e6cd3
AR
117 Adaptation::History::Pointer adaptLogHistory() const;
118 /// Returns possibly nil history, creating it if requested
119 Adaptation::History::Pointer adaptHistory(bool createIfNone = false) const;
aaf0559d
AR
120 /// Makes their history ours, throwing on conflicts
121 void adaptHistoryImport(const HttpRequest &them);
3ff65596
AR
122#endif
123#if ICAP_CLIENT
124 /// Returns possibly nil history, creating it if icap logging is enabled
125 Adaptation::Icap::History::Pointer icapHistory() const;
126#endif
127
128 void recordLookup(const DnsLookupDetails &detail);
129
64b66b76
CT
130 /// sets error detail if no earlier detail was available
131 void detailError(err_type aType, int aDetail);
129fe2a1
CT
132 /// clear error details, useful for retries/repeats
133 void clearError();
64b66b76 134
5cafad19 135protected:
5cafad19 136 void clean();
5cafad19 137
4a56ee8d 138 void init();
a2ac85d9 139
5cafad19 140public:
60745f24 141 HttpRequestMethod method;
4a56ee8d 142
a2ac85d9 143 char login[MAX_LOGIN_SZ];
4a56ee8d 144
cc192b50 145private:
146 char host[SQUIDHOSTNAMELEN];
12ef783b 147 int host_is_numeric;
26ac0430 148
3ff65596
AR
149#if USE_ADAPTATION
150 mutable Adaptation::History::Pointer adaptHistory_; ///< per-HTTP transaction info
151#endif
152#if ICAP_CLIENT
153 mutable Adaptation::Icap::History::Pointer icapHistory_; ///< per-HTTP transaction info
154#endif
155
cc192b50 156public:
b7ac5457 157 Ip::Address host_addr;
2f1431ea 158#if USE_AUTH
c7baff40 159 Auth::UserRequest::Pointer auth_user_request;
2f1431ea 160#endif
f45dd259 161 unsigned short port;
4a56ee8d 162
30abd221 163 String urlpath;
4a56ee8d 164
a2ac85d9 165 char *canonical;
4a56ee8d 166
f206b652 167 RequestFlags flags;
4a56ee8d 168
a2ac85d9 169 HttpHdrRange *range;
4a56ee8d 170
a2ac85d9 171 time_t ims;
4a56ee8d 172
a2ac85d9 173 int imslen;
4a56ee8d 174
b7ac5457 175 Ip::Address client_addr;
4a56ee8d 176
33b24cf0 177#if FOLLOW_X_FORWARDED_FOR
b7ac5457 178 Ip::Address indirect_client_addr;
33b24cf0 179#endif /* FOLLOW_X_FORWARDED_FOR */
3d674977 180
b7ac5457 181 Ip::Address my_addr;
4a56ee8d 182
a2ac85d9 183 HierarchyLogEntry hier;
4a56ee8d 184
3ff65596
AR
185 int dnsWait; ///< sum of DNS lookup delays in milliseconds, for %dt
186
a2ac85d9 187 err_type errType;
64b66b76 188 int errDetail; ///< errType-specific detail about the transaction error
4a56ee8d 189
a2ac85d9 190 char *peer_login; /* Configured peer login:password */
4a56ee8d 191
9ca29d23
AJ
192 char *peer_host; /* Selected peer host*/
193
a2ac85d9 194 time_t lastmod; /* Used on refreshes */
4a56ee8d 195
a2ac85d9 196 const char *vary_headers; /* Used when varying entities are detected. Changes how the store key is calculated */
4a56ee8d 197
a2ac85d9 198 char *peer_domain; /* Configured peer forceddomain */
4a56ee8d 199
35fb56c9
AJ
200 String myportname; // Internal tag name= value from port this requests arrived in.
201
30abd221 202 String tag; /* Internal tag for this request */
4a56ee8d 203
30abd221 204 String extacl_user; /* User name returned by extacl lookup */
4a56ee8d 205
30abd221 206 String extacl_passwd; /* Password returned by extacl lookup */
4a56ee8d 207
30abd221 208 String extacl_log; /* String to be used for access.log purposes */
8596962e 209
8c93a598
HN
210 String extacl_message; /* String to be used for error page purposes */
211
33b24cf0 212#if FOLLOW_X_FORWARDED_FOR
3d674977 213 String x_forwarded_for_iterator; /* XXX a list of IP addresses */
33b24cf0 214#endif /* FOLLOW_X_FORWARDED_FOR */
3d674977 215
8596962e 216public:
5cafad19 217 bool multipartRangeRequest() const;
4a56ee8d 218
429f7150 219 bool parseFirstLine(const char *start, const char *end);
4a56ee8d 220
666f514b 221 int parseHeader(const char *parse_start, int len);
4a56ee8d 222
60745f24 223 virtual bool expectingBody(const HttpRequestMethod& unused, int64_t&) const;
4a56ee8d 224
58217e94 225 bool bodyNibbled() const; // the request has a [partially] consumed body
226
5cafad19 227 int prefixLen();
4a56ee8d 228
5cafad19 229 void swapOut(StoreEntry * e);
4a56ee8d 230
5cafad19 231 void pack(Packer * p);
4a56ee8d 232
5cafad19 233 static void httpRequestPack(void *obj, Packer *p);
8596962e 234
60745f24 235 static HttpRequest * CreateFromUrlAndMethod(char * url, const HttpRequestMethod& method);
c21ad0f5 236
237 static HttpRequest * CreateFromUrl(char * url);
26ac0430 238
582c2af2 239 ConnStateData *pinnedConnection();
d67acb4e 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
11e3fa1c
AJ
248 int64_t getRangeOffsetLimit(); /* the result of this function gets cached in rangeOffsetLimit */
249
8596962e 250private:
251 const char *packableURI(bool full_uri) const;
252
11e3fa1c
AJ
253 mutable int64_t rangeOffsetLimit; /* caches the result of getRangeOffsetLimit */
254
8596962e 255protected:
256 virtual void packFirstLineInto(Packer * p, bool full_uri) const;
4a56ee8d 257
96ee497f 258 virtual bool sanityCheckStartLine(MemBuf *buf, const size_t hdr_len, http_status *error);
4a56ee8d 259
07947ad8 260 virtual void hdrCacheInit();
26ac0430 261
d67acb4e 262 virtual bool inheritProperties(const HttpMsg *aMsg);
a2ac85d9 263};
528b2c61 264
d85b8894 265MEMPROXY_CLASS_INLINE(HttpRequest);
b001e822 266
528b2c61 267#endif /* SQUID_HTTPREQUEST_H */