]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpRequest.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / HttpRequest.h
1 /*
2 * Copyright (C) 1996-2017 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 "dns/forward.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 class Downloader;
38
39 /* Http Request */
40 void httpRequestPack(void *obj, Packable *p);
41
42 class HttpHdrRange;
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 *schemeImage, const char *aUrlpath);
53 ~HttpRequest();
54 virtual void reset();
55
56 void initHTTP(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *schemeImage, 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 #if USE_ADAPTATION
71 /// Returns possibly nil history, creating it if adapt. logging is enabled
72 Adaptation::History::Pointer adaptLogHistory() const;
73 /// Returns possibly nil history, creating it if requested
74 Adaptation::History::Pointer adaptHistory(bool createIfNone = false) const;
75 /// Makes their history ours, throwing on conflicts
76 void adaptHistoryImport(const HttpRequest &them);
77 #endif
78 #if ICAP_CLIENT
79 /// Returns possibly nil history, creating it if icap logging is enabled
80 Adaptation::Icap::History::Pointer icapHistory() const;
81 #endif
82
83 void recordLookup(const Dns::LookupDetails &detail);
84
85 /// sets error detail if no earlier detail was available
86 void detailError(err_type aType, int aDetail);
87 /// clear error details, useful for retries/repeats
88 void clearError();
89
90 protected:
91 void clean();
92
93 void init();
94
95 public:
96 HttpRequestMethod method;
97 URL url; ///< the request URI
98
99 private:
100 #if USE_ADAPTATION
101 mutable Adaptation::History::Pointer adaptHistory_; ///< per-HTTP transaction info
102 #endif
103 #if ICAP_CLIENT
104 mutable Adaptation::Icap::History::Pointer icapHistory_; ///< per-HTTP transaction info
105 #endif
106
107 public:
108 #if USE_AUTH
109 Auth::UserRequest::Pointer auth_user_request;
110 #endif
111
112 /// RFC 7230 section 5.5 - Effective Request URI
113 const SBuf &effectiveRequestUri() const;
114
115 /**
116 * If defined, store_id_program mapped the request URL to this ID.
117 * Store uses this ID (and not the URL) to find and store entries,
118 * avoiding caching duplicate entries when different URLs point to
119 * "essentially the same" cachable resource.
120 */
121 String store_id;
122
123 RequestFlags flags;
124
125 HttpHdrRange *range;
126
127 time_t ims;
128
129 int imslen;
130
131 Ip::Address client_addr;
132
133 #if FOLLOW_X_FORWARDED_FOR
134 Ip::Address indirect_client_addr;
135 #endif /* FOLLOW_X_FORWARDED_FOR */
136
137 Ip::Address my_addr;
138
139 HierarchyLogEntry hier;
140
141 int dnsWait; ///< sum of DNS lookup delays in milliseconds, for %dt
142
143 err_type errType;
144 int errDetail; ///< errType-specific detail about the transaction error
145
146 char *peer_login; /* Configured peer login:password */
147
148 char *peer_host; /* Selected peer host*/
149
150 time_t lastmod; /* Used on refreshes */
151
152 /// The variant second-stage cache key. Generated from Vary header pattern for this request.
153 SBuf vary_headers;
154
155 char *peer_domain; /* Configured peer forceddomain */
156
157 String myportname; // Internal tag name= value from port this requests arrived in.
158
159 NotePairs::Pointer notes; ///< annotations added by the note directive and helpers
160
161 String tag; /* Internal tag for this request */
162
163 String extacl_user; /* User name returned by extacl lookup */
164
165 String extacl_passwd; /* Password returned by extacl lookup */
166
167 String extacl_log; /* String to be used for access.log purposes */
168
169 String extacl_message; /* String to be used for error page purposes */
170
171 #if FOLLOW_X_FORWARDED_FOR
172 String x_forwarded_for_iterator; /* XXX a list of IP addresses */
173 #endif /* FOLLOW_X_FORWARDED_FOR */
174
175 /// A strong etag of the cached entry. Used for refreshing that entry.
176 String etag;
177
178 /// whether we have responded with HTTP 100 or FTP 150 already
179 bool forcedBodyContinuation;
180
181 public:
182 bool multipartRangeRequest() const;
183
184 bool parseFirstLine(const char *start, const char *end);
185
186 virtual bool expectingBody(const HttpRequestMethod& unused, int64_t&) const;
187
188 bool bodyNibbled() const; // the request has a [partially] consumed body
189
190 int prefixLen() const;
191
192 void swapOut(StoreEntry * e);
193
194 void pack(Packable * p) const;
195
196 static void httpRequestPack(void *obj, Packable *p);
197
198 static HttpRequest * CreateFromUrl(char * url, const HttpRequestMethod &method = Http::METHOD_GET);
199
200 ConnStateData *pinnedConnection();
201
202 /**
203 * Returns the current StoreID for the request as a nul-terminated char*.
204 * Always returns the current id for the request
205 * (either the effective request URI or modified ID by the helper).
206 */
207 const SBuf storeId();
208
209 /**
210 * The client connection manager, if known;
211 * Used for any response actions needed directly to the client.
212 * ie 1xx forwarding or connection pinning state changes
213 */
214 CbcPointer<ConnStateData> clientConnectionManager;
215
216 /// The Downloader object which initiated the HTTP request if any
217 CbcPointer<Downloader> downloader;
218
219 /// forgets about the cached Range header (for a reason)
220 void ignoreRange(const char *reason);
221 int64_t getRangeOffsetLimit(); /* the result of this function gets cached in rangeOffsetLimit */
222
223 private:
224 mutable int64_t rangeOffsetLimit; /* caches the result of getRangeOffsetLimit */
225
226 protected:
227 virtual void packFirstLineInto(Packable * p, bool full_uri) const;
228
229 virtual bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error);
230
231 virtual void hdrCacheInit();
232
233 virtual bool inheritProperties(const HttpMsg *aMsg);
234 };
235
236 #endif /* SQUID_HTTPREQUEST_H */
237