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