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