]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpRequest.h
Sync with trunk rev.13312
[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 "Notes.h"
41 #include "RequestFlags.h"
42
43 #if USE_AUTH
44 #include "auth/UserRequest.h"
45 #endif
46 #if USE_ADAPTATION
47 #include "adaptation/History.h"
48 #endif
49 #if ICAP_CLIENT
50 #include "adaptation/icap/History.h"
51 #endif
52 #if USE_SQUID_EUI
53 #include "eui/Eui48.h"
54 #include "eui/Eui64.h"
55 #endif
56
57 class ConnStateData;
58
59 /* Http Request */
60 void httpRequestPack(void *obj, Packer *p);
61
62 class HttpHdrRange;
63 class DnsLookupDetails;
64
65 class HttpRequest: public HttpMsg
66 {
67
68 public:
69 typedef RefCount<HttpRequest> Pointer;
70
71 MEMPROXY_CLASS(HttpRequest);
72 HttpRequest();
73 HttpRequest(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *aUrlpath);
74 ~HttpRequest();
75 virtual void reset();
76
77 void initHTTP(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *aUrlpath);
78
79 virtual HttpRequest *clone() const;
80
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();
85
86 bool conditional() const; ///< has at least one recognized If-* header
87
88 /// whether the client is likely to be able to handle a 1xx reply
89 bool canHandle1xx() const;
90
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. */
95 inline void SetHost(const char *src) {
96 host_addr.setEmpty();
97 host_addr = src;
98 if (host_addr.isAnyAddr()) {
99 xstrncpy(host, src, SQUIDHOSTNAMELEN);
100 host_is_numeric = 0;
101 } else {
102 host_addr.toHostStr(host, SQUIDHOSTNAMELEN);
103 debugs(23, 3, "HttpRequest::SetHost() given IP: " << host_addr);
104 host_is_numeric = 1;
105 }
106 safe_free(canonical); // force its re-build
107 };
108 inline const char* GetHost(void) const { return host; };
109 inline int GetHostIsNumeric(void) const { return host_is_numeric; };
110
111 #if USE_ADAPTATION
112 /// Returns possibly nil history, creating it if adapt. logging is enabled
113 Adaptation::History::Pointer adaptLogHistory() const;
114 /// Returns possibly nil history, creating it if requested
115 Adaptation::History::Pointer adaptHistory(bool createIfNone = false) const;
116 /// Makes their history ours, throwing on conflicts
117 void adaptHistoryImport(const HttpRequest &them);
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
126 /// sets error detail if no earlier detail was available
127 void detailError(err_type aType, int aDetail);
128 /// clear error details, useful for retries/repeats
129 void clearError();
130
131 protected:
132 void clean();
133
134 void init();
135
136 public:
137 HttpRequestMethod method;
138
139 char login[MAX_LOGIN_SZ];
140
141 private:
142 char host[SQUIDHOSTNAMELEN];
143 int host_is_numeric;
144
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
152 public:
153 Ip::Address host_addr;
154 #if USE_AUTH
155 Auth::UserRequest::Pointer auth_user_request;
156 #endif
157 unsigned short port;
158
159 String urlpath;
160
161 char *canonical;
162
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
171 RequestFlags flags;
172
173 HttpHdrRange *range;
174
175 time_t ims;
176
177 int imslen;
178
179 Ip::Address client_addr;
180
181 #if FOLLOW_X_FORWARDED_FOR
182 Ip::Address indirect_client_addr;
183 #endif /* FOLLOW_X_FORWARDED_FOR */
184
185 Ip::Address my_addr;
186
187 HierarchyLogEntry hier;
188
189 int dnsWait; ///< sum of DNS lookup delays in milliseconds, for %dt
190
191 err_type errType;
192 int errDetail; ///< errType-specific detail about the transaction error
193
194 char *peer_login; /* Configured peer login:password */
195
196 char *peer_host; /* Selected peer host*/
197
198 time_t lastmod; /* Used on refreshes */
199
200 const char *vary_headers; /* Used when varying entities are detected. Changes how the store key is calculated */
201
202 char *peer_domain; /* Configured peer forceddomain */
203
204 String myportname; // Internal tag name= value from port this requests arrived in.
205
206 NotePairs::Pointer notes; ///< annotations added by the note directive and helpers
207
208 String tag; /* Internal tag for this request */
209
210 String extacl_user; /* User name returned by extacl lookup */
211
212 String extacl_passwd; /* Password returned by extacl lookup */
213
214 String extacl_log; /* String to be used for access.log purposes */
215
216 String extacl_message; /* String to be used for error page purposes */
217
218 #if FOLLOW_X_FORWARDED_FOR
219 String x_forwarded_for_iterator; /* XXX a list of IP addresses */
220 #endif /* FOLLOW_X_FORWARDED_FOR */
221
222 /// A strong etag of the cached entry. Used for refreshing that entry.
223 String etag;
224
225 public:
226 bool multipartRangeRequest() const;
227
228 bool parseFirstLine(const char *start, const char *end);
229
230 int parseHeader(const char *parse_start, int len);
231
232 virtual bool expectingBody(const HttpRequestMethod& unused, int64_t&) const;
233
234 bool bodyNibbled() const; // the request has a [partially] consumed body
235
236 int prefixLen();
237
238 void swapOut(StoreEntry * e);
239
240 void pack(Packer * p);
241
242 static void httpRequestPack(void *obj, Packer *p);
243
244 static HttpRequest * CreateFromUrlAndMethod(char * url, const HttpRequestMethod& method);
245
246 static HttpRequest * CreateFromUrl(char * url);
247
248 ConnStateData *pinnedConnection();
249
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
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 */
263 CbcPointer<ConnStateData> clientConnectionManager;
264
265 /// forgets about the cached Range header (for a reason)
266 void ignoreRange(const char *reason);
267 int64_t getRangeOffsetLimit(); /* the result of this function gets cached in rangeOffsetLimit */
268
269 private:
270 const char *packableURI(bool full_uri) const;
271
272 mutable int64_t rangeOffsetLimit; /* caches the result of getRangeOffsetLimit */
273
274 protected:
275 virtual void packFirstLineInto(Packer * p, bool full_uri) const;
276
277 virtual bool sanityCheckStartLine(MemBuf *buf, const size_t hdr_len, Http::StatusCode *error);
278
279 virtual void hdrCacheInit();
280
281 virtual bool inheritProperties(const HttpMsg *aMsg);
282 };
283
284 MEMPROXY_CLASS_INLINE(HttpRequest);
285
286 #endif /* SQUID_HTTPREQUEST_H */