]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpRequest.h
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / HttpRequest.h
1 /*
2 * Copyright (C) 1996-2018 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/Message.h"
17 #include "http/RequestMethod.h"
18 #include "MasterXaction.h"
19 #include "Notes.h"
20 #include "RequestFlags.h"
21 #include "URL.h"
22
23 #if USE_AUTH
24 #include "auth/UserRequest.h"
25 #endif
26 #if USE_ADAPTATION
27 #include "adaptation/History.h"
28 #endif
29 #if ICAP_CLIENT
30 #include "adaptation/icap/History.h"
31 #endif
32 #if USE_SQUID_EUI
33 #include "eui/Eui48.h"
34 #include "eui/Eui64.h"
35 #endif
36
37 class ConnStateData;
38 class Downloader;
39 class AccessLogEntry;
40 typedef RefCount<AccessLogEntry> AccessLogEntryPointer;
41
42 /* Http Request */
43 void httpRequestPack(void *obj, Packable *p);
44
45 class HttpHdrRange;
46
47 class HttpRequest: public Http::Message
48 {
49 MEMPROXY_CLASS(HttpRequest);
50
51 public:
52 typedef RefCount<HttpRequest> Pointer;
53
54 HttpRequest(const MasterXaction::Pointer &);
55 HttpRequest(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *schemeImage, const char *aUrlpath, const MasterXaction::Pointer &);
56 ~HttpRequest();
57 virtual void reset();
58
59 void initHTTP(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *schemeImage, const char *aUrlpath);
60
61 virtual HttpRequest *clone() const;
62
63 /// Whether response to this request is potentially cachable
64 /// \retval false Not cacheable.
65 /// \retval true Possibly cacheable. Response factors will determine.
66 bool maybeCacheable();
67
68 bool conditional() const; ///< has at least one recognized If-* header
69
70 /// whether the client is likely to be able to handle a 1xx reply
71 bool canHandle1xx() const;
72
73 #if USE_ADAPTATION
74 /// Returns possibly nil history, creating it if adapt. logging is enabled
75 Adaptation::History::Pointer adaptLogHistory() const;
76 /// Returns possibly nil history, creating it if requested
77 Adaptation::History::Pointer adaptHistory(bool createIfNone = false) const;
78 /// Makes their history ours, throwing on conflicts
79 void adaptHistoryImport(const HttpRequest &them);
80 #endif
81 #if ICAP_CLIENT
82 /// Returns possibly nil history, creating it if icap logging is enabled
83 Adaptation::Icap::History::Pointer icapHistory() const;
84 #endif
85
86 void recordLookup(const Dns::LookupDetails &detail);
87
88 /// sets error detail if no earlier detail was available
89 void detailError(err_type aType, int aDetail);
90 /// clear error details, useful for retries/repeats
91 void clearError();
92
93 /// associates the request with a from-client connection manager
94 void manager(const CbcPointer<ConnStateData> &aMgr, const AccessLogEntryPointer &al);
95
96 protected:
97 void clean();
98
99 void init();
100
101 public:
102 HttpRequestMethod method;
103 URL url; ///< the request URI
104
105 private:
106 #if USE_ADAPTATION
107 mutable Adaptation::History::Pointer adaptHistory_; ///< per-HTTP transaction info
108 #endif
109 #if ICAP_CLIENT
110 mutable Adaptation::Icap::History::Pointer icapHistory_; ///< per-HTTP transaction info
111 #endif
112
113 public:
114 #if USE_AUTH
115 Auth::UserRequest::Pointer auth_user_request;
116 #endif
117
118 /// RFC 7230 section 5.5 - Effective Request URI
119 const SBuf &effectiveRequestUri() const;
120
121 /**
122 * If defined, store_id_program mapped the request URL to this ID.
123 * Store uses this ID (and not the URL) to find and store entries,
124 * avoiding caching duplicate entries when different URLs point to
125 * "essentially the same" cachable resource.
126 */
127 String store_id;
128
129 RequestFlags flags;
130
131 HttpHdrRange *range;
132
133 time_t ims;
134
135 int imslen;
136
137 Ip::Address client_addr;
138
139 #if FOLLOW_X_FORWARDED_FOR
140 Ip::Address indirect_client_addr;
141 #endif /* FOLLOW_X_FORWARDED_FOR */
142
143 Ip::Address my_addr;
144
145 HierarchyLogEntry hier;
146
147 int dnsWait; ///< sum of DNS lookup delays in milliseconds, for %dt
148
149 err_type errType;
150 int errDetail; ///< errType-specific detail about the transaction error
151
152 char *peer_login; /* Configured peer login:password */
153
154 char *peer_host; /* Selected peer host*/
155
156 time_t lastmod; /* Used on refreshes */
157
158 /// The variant second-stage cache key. Generated from Vary header pattern for this request.
159 SBuf vary_headers;
160
161 char *peer_domain; /* Configured peer forceddomain */
162
163 String myportname; // Internal tag name= value from port this requests arrived in.
164
165 String tag; /* Internal tag for this request */
166
167 String extacl_user; /* User name returned by extacl lookup */
168
169 String extacl_passwd; /* Password returned by extacl lookup */
170
171 String extacl_log; /* String to be used for access.log purposes */
172
173 String extacl_message; /* String to be used for error page purposes */
174
175 #if FOLLOW_X_FORWARDED_FOR
176 String x_forwarded_for_iterator; /* XXX a list of IP addresses */
177 #endif /* FOLLOW_X_FORWARDED_FOR */
178
179 /// A strong etag of the cached entry. Used for refreshing that entry.
180 String etag;
181
182 /// whether we have responded with HTTP 100 or FTP 150 already
183 bool forcedBodyContinuation;
184
185 public:
186 bool multipartRangeRequest() const;
187
188 bool parseFirstLine(const char *start, const char *end);
189
190 virtual bool expectingBody(const HttpRequestMethod& unused, int64_t&) const;
191
192 bool bodyNibbled() const; // the request has a [partially] consumed body
193
194 int prefixLen() const;
195
196 void swapOut(StoreEntry * e);
197
198 void pack(Packable * p) const;
199
200 static void httpRequestPack(void *obj, Packable *p);
201
202 static HttpRequest * FromUrl(const char * url, const MasterXaction::Pointer &, const HttpRequestMethod &method = Http::METHOD_GET);
203
204 ConnStateData *pinnedConnection();
205
206 /**
207 * Returns the current StoreID for the request as a nul-terminated char*.
208 * Always returns the current id for the request
209 * (either the effective request URI or modified ID by the helper).
210 */
211 const SBuf storeId();
212
213 /**
214 * The client connection manager, if known;
215 * Used for any response actions needed directly to the client.
216 * ie 1xx forwarding or connection pinning state changes
217 */
218 CbcPointer<ConnStateData> clientConnectionManager;
219
220 /// The Downloader object which initiated the HTTP request if any
221 CbcPointer<Downloader> downloader;
222
223 /// the master transaction this request belongs to. Never nil.
224 MasterXaction::Pointer masterXaction;
225
226 /// forgets about the cached Range header (for a reason)
227 void ignoreRange(const char *reason);
228 int64_t getRangeOffsetLimit(); /* the result of this function gets cached in rangeOffsetLimit */
229
230 /// \returns existing non-empty transaction annotations,
231 /// creates and returns empty annotations otherwise
232 NotePairs::Pointer notes();
233 bool hasNotes() const { return bool(theNotes) && !theNotes->empty(); }
234
235 private:
236 mutable int64_t rangeOffsetLimit; /* caches the result of getRangeOffsetLimit */
237
238 /// annotations added by the note directive and helpers
239 /// and(or) by annotate_transaction/annotate_client ACLs.
240 NotePairs::Pointer theNotes;
241 protected:
242 virtual void packFirstLineInto(Packable * p, bool full_uri) const;
243
244 virtual bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error);
245
246 virtual void hdrCacheInit();
247
248 virtual bool inheritProperties(const Http::Message *);
249 };
250
251 class ConnStateData;
252 /**
253 * Updates ConnStateData ids and HttpRequest notes from helpers received notes.
254 */
255 void UpdateRequestNotes(ConnStateData *csd, HttpRequest &request, NotePairs const &notes);
256
257 #endif /* SQUID_HTTPREQUEST_H */
258