2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_HTTPREQUEST_H
10 #define SQUID_HTTPREQUEST_H
12 #include "base/CbcPointer.h"
13 #include "dns/forward.h"
15 #include "HierarchyLogEntry.h"
16 #include "http/Message.h"
17 #include "http/RequestMethod.h"
18 #include "MasterXaction.h"
20 #include "RequestFlags.h"
24 #include "auth/UserRequest.h"
27 #include "adaptation/History.h"
30 #include "adaptation/icap/History.h"
33 #include "eui/Eui48.h"
34 #include "eui/Eui64.h"
40 typedef RefCount
<AccessLogEntry
> AccessLogEntryPointer
;
43 void httpRequestPack(void *obj
, Packable
*p
);
47 class HttpRequest
: public Http::Message
49 MEMPROXY_CLASS(HttpRequest
);
52 typedef RefCount
<HttpRequest
> Pointer
;
54 HttpRequest(const MasterXaction::Pointer
&);
55 HttpRequest(const HttpRequestMethod
& aMethod
, AnyP::ProtocolType aProtocol
, const char *schemeImage
, const char *aUrlpath
, const MasterXaction::Pointer
&);
59 void initHTTP(const HttpRequestMethod
& aMethod
, AnyP::ProtocolType aProtocol
, const char *schemeImage
, const char *aUrlpath
);
61 virtual HttpRequest
*clone() const;
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();
68 bool conditional() const; ///< has at least one recognized If-* header
70 /// whether the client is likely to be able to handle a 1xx reply
71 bool canHandle1xx() const;
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
);
82 /// Returns possibly nil history, creating it if icap logging is enabled
83 Adaptation::Icap::History::Pointer
icapHistory() const;
86 void recordLookup(const Dns::LookupDetails
&detail
);
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
93 /// associates the request with a from-client connection manager
94 void manager(const CbcPointer
<ConnStateData
> &aMgr
, const AccessLogEntryPointer
&al
);
102 HttpRequestMethod method
;
103 URL url
; ///< the request URI
107 mutable Adaptation::History::Pointer adaptHistory_
; ///< per-HTTP transaction info
110 mutable Adaptation::Icap::History::Pointer icapHistory_
; ///< per-HTTP transaction info
115 Auth::UserRequest::Pointer auth_user_request
;
118 /// RFC 7230 section 5.5 - Effective Request URI
119 const SBuf
&effectiveRequestUri() const;
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.
137 Ip::Address client_addr
;
139 #if FOLLOW_X_FORWARDED_FOR
140 Ip::Address indirect_client_addr
;
141 #endif /* FOLLOW_X_FORWARDED_FOR */
145 HierarchyLogEntry hier
;
147 int dnsWait
; ///< sum of DNS lookup delays in milliseconds, for %dt
150 int errDetail
; ///< errType-specific detail about the transaction error
152 char *peer_login
; /* Configured peer login:password */
154 char *peer_host
; /* Selected peer host*/
156 time_t lastmod
; /* Used on refreshes */
158 /// The variant second-stage cache key. Generated from Vary header pattern for this request.
161 char *peer_domain
; /* Configured peer forceddomain */
163 String myportname
; // Internal tag name= value from port this requests arrived in.
165 String tag
; /* Internal tag for this request */
167 String extacl_user
; /* User name returned by extacl lookup */
169 String extacl_passwd
; /* Password returned by extacl lookup */
171 String extacl_log
; /* String to be used for access.log purposes */
173 String extacl_message
; /* String to be used for error page purposes */
175 #if FOLLOW_X_FORWARDED_FOR
176 String x_forwarded_for_iterator
; /* XXX a list of IP addresses */
177 #endif /* FOLLOW_X_FORWARDED_FOR */
179 /// A strong etag of the cached entry. Used for refreshing that entry.
182 /// whether we have responded with HTTP 100 or FTP 150 already
183 bool forcedBodyContinuation
;
186 bool multipartRangeRequest() const;
188 bool parseFirstLine(const char *start
, const char *end
);
190 virtual bool expectingBody(const HttpRequestMethod
& unused
, int64_t&) const;
192 bool bodyNibbled() const; // the request has a [partially] consumed body
194 int prefixLen() const;
196 void swapOut(StoreEntry
* e
);
198 void pack(Packable
* p
) const;
200 static void httpRequestPack(void *obj
, Packable
*p
);
202 static HttpRequest
* FromUrl(const char * url
, const MasterXaction::Pointer
&, const HttpRequestMethod
&method
= Http::METHOD_GET
);
204 ConnStateData
*pinnedConnection();
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).
211 const SBuf
storeId();
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
218 CbcPointer
<ConnStateData
> clientConnectionManager
;
220 /// The Downloader object which initiated the HTTP request if any
221 CbcPointer
<Downloader
> downloader
;
223 /// the master transaction this request belongs to. Never nil.
224 MasterXaction::Pointer masterXaction
;
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 */
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(); }
236 mutable int64_t rangeOffsetLimit
; /* caches the result of getRangeOffsetLimit */
238 /// annotations added by the note directive and helpers
239 /// and(or) by annotate_transaction/annotate_client ACLs.
240 NotePairs::Pointer theNotes
;
242 virtual void packFirstLineInto(Packable
* p
, bool full_uri
) const;
244 virtual bool sanityCheckStartLine(const char *buf
, const size_t hdr_len
, Http::StatusCode
*error
);
246 virtual void hdrCacheInit();
248 virtual bool inheritProperties(const Http::Message
*);
253 * Updates ConnStateData ids and HttpRequest notes from helpers received notes.
255 void UpdateRequestNotes(ConnStateData
*csd
, HttpRequest
&request
, NotePairs
const ¬es
);
257 #endif /* SQUID_HTTPREQUEST_H */