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