]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpRequest.h
SourceFormat Enforcement
[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 "http/RequestMethod.h"
17 #include "HttpMsg.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 MEMPROXY_CLASS(HttpRequest);
47
48 public:
49 typedef RefCount<HttpRequest> Pointer;
50
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 and userinfo only)
120
121 private:
122 char host[SQUIDHOSTNAMELEN];
123 int host_is_numeric;
124
125 #if USE_ADAPTATION
126 mutable Adaptation::History::Pointer adaptHistory_; ///< per-HTTP transaction info
127 #endif
128 #if ICAP_CLIENT
129 mutable Adaptation::Icap::History::Pointer icapHistory_; ///< per-HTTP transaction info
130 #endif
131
132 public:
133 Ip::Address host_addr;
134 #if USE_AUTH
135 Auth::UserRequest::Pointer auth_user_request;
136 #endif
137 unsigned short port;
138
139 String urlpath;
140
141 char *canonical;
142
143 /**
144 * If defined, store_id_program mapped the request URL to this ID.
145 * Store uses this ID (and not the URL) to find and store entries,
146 * avoiding caching duplicate entries when different URLs point to
147 * "essentially the same" cachable resource.
148 */
149 String store_id;
150
151 RequestFlags flags;
152
153 HttpHdrRange *range;
154
155 time_t ims;
156
157 int imslen;
158
159 Ip::Address client_addr;
160
161 #if FOLLOW_X_FORWARDED_FOR
162 Ip::Address indirect_client_addr;
163 #endif /* FOLLOW_X_FORWARDED_FOR */
164
165 Ip::Address my_addr;
166
167 HierarchyLogEntry hier;
168
169 int dnsWait; ///< sum of DNS lookup delays in milliseconds, for %dt
170
171 err_type errType;
172 int errDetail; ///< errType-specific detail about the transaction error
173
174 char *peer_login; /* Configured peer login:password */
175
176 char *peer_host; /* Selected peer host*/
177
178 time_t lastmod; /* Used on refreshes */
179
180 const char *vary_headers; /* Used when varying entities are detected. Changes how the store key is calculated */
181
182 char *peer_domain; /* Configured peer forceddomain */
183
184 String myportname; // Internal tag name= value from port this requests arrived in.
185
186 NotePairs::Pointer notes; ///< annotations added by the note directive and helpers
187
188 String tag; /* Internal tag for this request */
189
190 String extacl_user; /* User name returned by extacl lookup */
191
192 String extacl_passwd; /* Password returned by extacl lookup */
193
194 String extacl_log; /* String to be used for access.log purposes */
195
196 String extacl_message; /* String to be used for error page purposes */
197
198 #if FOLLOW_X_FORWARDED_FOR
199 String x_forwarded_for_iterator; /* XXX a list of IP addresses */
200 #endif /* FOLLOW_X_FORWARDED_FOR */
201
202 /// A strong etag of the cached entry. Used for refreshing that entry.
203 String etag;
204
205 /// whether we have responded with HTTP 100 or FTP 150 already
206 bool forcedBodyContinuation;
207
208 public:
209 bool multipartRangeRequest() const;
210
211 bool parseFirstLine(const char *start, const char *end);
212
213 bool parseHeader(Http1::RequestParser &hp); // TODO move this function to the parser
214
215 virtual bool expectingBody(const HttpRequestMethod& unused, int64_t&) const;
216
217 bool bodyNibbled() const; // the request has a [partially] consumed body
218
219 int prefixLen();
220
221 void swapOut(StoreEntry * e);
222
223 void pack(Packer * p);
224
225 static void httpRequestPack(void *obj, Packer *p);
226
227 static HttpRequest * CreateFromUrlAndMethod(char * url, const HttpRequestMethod& method);
228
229 static HttpRequest * CreateFromUrl(char * url);
230
231 ConnStateData *pinnedConnection();
232
233 /**
234 * Returns the current StoreID for the request as a nul-terminated char*.
235 * Always returns the current id for the request
236 * (either the request canonical url or modified ID by the helper).
237 * Does not return NULL.
238 */
239 const char *storeId();
240
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 */
246 CbcPointer<ConnStateData> clientConnectionManager;
247
248 /// forgets about the cached Range header (for a reason)
249 void ignoreRange(const char *reason);
250 int64_t getRangeOffsetLimit(); /* the result of this function gets cached in rangeOffsetLimit */
251
252 private:
253 const char *packableURI(bool full_uri) const;
254
255 mutable int64_t rangeOffsetLimit; /* caches the result of getRangeOffsetLimit */
256
257 protected:
258 virtual void packFirstLineInto(Packer * p, bool full_uri) const;
259
260 virtual bool sanityCheckStartLine(MemBuf *buf, const size_t hdr_len, Http::StatusCode *error);
261
262 virtual void hdrCacheInit();
263
264 virtual bool inheritProperties(const HttpMsg *aMsg);
265 };
266
267 #endif /* SQUID_HTTPREQUEST_H */
268