2 * Copyright (C) 1996-2016 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/RequestMethod.h"
19 #include "RequestFlags.h"
23 #include "auth/UserRequest.h"
26 #include "adaptation/History.h"
29 #include "adaptation/icap/History.h"
32 #include "eui/Eui48.h"
33 #include "eui/Eui64.h"
40 void httpRequestPack(void *obj
, Packable
*p
);
44 class HttpRequest
: public HttpMsg
46 MEMPROXY_CLASS(HttpRequest
);
49 typedef RefCount
<HttpRequest
> Pointer
;
52 HttpRequest(const HttpRequestMethod
& aMethod
, AnyP::ProtocolType aProtocol
, const char *aUrlpath
);
56 void initHTTP(const HttpRequestMethod
& aMethod
, AnyP::ProtocolType aProtocol
, const char *aUrlpath
);
58 virtual HttpRequest
*clone() const;
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();
65 bool conditional() const; ///< has at least one recognized If-* header
67 /// whether the client is likely to be able to handle a 1xx reply
68 bool canHandle1xx() const;
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
);
79 /// Returns possibly nil history, creating it if icap logging is enabled
80 Adaptation::Icap::History::Pointer
icapHistory() const;
83 void recordLookup(const Dns::LookupDetails
&detail
);
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
96 HttpRequestMethod method
;
97 URL url
; ///< the request URI
101 mutable Adaptation::History::Pointer adaptHistory_
; ///< per-HTTP transaction info
104 mutable Adaptation::Icap::History::Pointer icapHistory_
; ///< per-HTTP transaction info
109 Auth::UserRequest::Pointer auth_user_request
;
112 /// RFC 7230 section 5.5 - Effective Request URI
113 const SBuf
&effectiveRequestUri() const;
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.
131 Ip::Address client_addr
;
133 #if FOLLOW_X_FORWARDED_FOR
134 Ip::Address indirect_client_addr
;
135 #endif /* FOLLOW_X_FORWARDED_FOR */
139 HierarchyLogEntry hier
;
141 int dnsWait
; ///< sum of DNS lookup delays in milliseconds, for %dt
144 int errDetail
; ///< errType-specific detail about the transaction error
146 char *peer_login
; /* Configured peer login:password */
148 char *peer_host
; /* Selected peer host*/
150 time_t lastmod
; /* Used on refreshes */
152 /// The variant second-stage cache key. Generated from Vary header pattern for this request.
155 char *peer_domain
; /* Configured peer forceddomain */
157 String myportname
; // Internal tag name= value from port this requests arrived in.
159 NotePairs::Pointer notes
; ///< annotations added by the note directive and helpers
161 String tag
; /* Internal tag for this request */
163 String extacl_user
; /* User name returned by extacl lookup */
165 String extacl_passwd
; /* Password returned by extacl lookup */
167 String extacl_log
; /* String to be used for access.log purposes */
169 String extacl_message
; /* String to be used for error page purposes */
171 #if FOLLOW_X_FORWARDED_FOR
172 String x_forwarded_for_iterator
; /* XXX a list of IP addresses */
173 #endif /* FOLLOW_X_FORWARDED_FOR */
175 /// A strong etag of the cached entry. Used for refreshing that entry.
178 /// whether we have responded with HTTP 100 or FTP 150 already
179 bool forcedBodyContinuation
;
182 bool multipartRangeRequest() const;
184 bool parseFirstLine(const char *start
, const char *end
);
186 virtual bool expectingBody(const HttpRequestMethod
& unused
, int64_t&) const;
188 bool bodyNibbled() const; // the request has a [partially] consumed body
190 int prefixLen() const;
192 void swapOut(StoreEntry
* e
);
194 void pack(Packable
* p
) const;
196 static void httpRequestPack(void *obj
, Packable
*p
);
198 static HttpRequest
* CreateFromUrl(char * url
, const HttpRequestMethod
&method
= Http::METHOD_GET
);
200 ConnStateData
*pinnedConnection();
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).
207 const SBuf
storeId();
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
214 CbcPointer
<ConnStateData
> clientConnectionManager
;
216 /// The Downloader object which initiated the HTTP request if any
217 CbcPointer
<Downloader
> downloader
;
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 */
224 mutable int64_t rangeOffsetLimit
; /* caches the result of getRangeOffsetLimit */
227 virtual void packFirstLineInto(Packable
* p
, bool full_uri
) const;
229 virtual bool sanityCheckStartLine(const char *buf
, const size_t hdr_len
, Http::StatusCode
*error
);
231 virtual void hdrCacheInit();
233 virtual bool inheritProperties(const HttpMsg
*aMsg
);
236 #endif /* SQUID_HTTPREQUEST_H */