2 * Copyright (C) 1996-2015 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"
14 #include "dns/forward.h"
16 #include "HierarchyLogEntry.h"
17 #include "http/RequestMethod.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 void httpRequestPack(void *obj
, Packer
*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;
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
) {
77 if (host_addr
.isAnyAddr()) {
78 xstrncpy(host
, src
, SQUIDHOSTNAMELEN
);
81 host_addr
.toHostStr(host
, SQUIDHOSTNAMELEN
);
82 debugs(23, 3, "HttpRequest::SetHost() given IP: " << host_addr
);
85 safe_free(canonical
); // force its re-build
87 inline const char* GetHost(void) const { return host
; };
88 inline int GetHostIsNumeric(void) const { return host_is_numeric
; };
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
);
99 /// Returns possibly nil history, creating it if icap logging is enabled
100 Adaptation::Icap::History::Pointer
icapHistory() const;
103 void recordLookup(const Dns::LookupDetails
&detail
);
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
116 HttpRequestMethod method
;
118 // TODO expand to include all URI parts
119 URL url
; ///< the request URI (scheme and userinfo only)
122 char host
[SQUIDHOSTNAMELEN
];
126 mutable Adaptation::History::Pointer adaptHistory_
; ///< per-HTTP transaction info
129 mutable Adaptation::Icap::History::Pointer icapHistory_
; ///< per-HTTP transaction info
133 Ip::Address host_addr
;
135 Auth::UserRequest::Pointer auth_user_request
;
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.
159 Ip::Address client_addr
;
161 #if FOLLOW_X_FORWARDED_FOR
162 Ip::Address indirect_client_addr
;
163 #endif /* FOLLOW_X_FORWARDED_FOR */
167 HierarchyLogEntry hier
;
169 int dnsWait
; ///< sum of DNS lookup delays in milliseconds, for %dt
172 int errDetail
; ///< errType-specific detail about the transaction error
174 char *peer_login
; /* Configured peer login:password */
176 char *peer_host
; /* Selected peer host*/
178 time_t lastmod
; /* Used on refreshes */
180 const char *vary_headers
; /* Used when varying entities are detected. Changes how the store key is calculated */
182 char *peer_domain
; /* Configured peer forceddomain */
184 String myportname
; // Internal tag name= value from port this requests arrived in.
186 NotePairs::Pointer notes
; ///< annotations added by the note directive and helpers
188 String tag
; /* Internal tag for this request */
190 String extacl_user
; /* User name returned by extacl lookup */
192 String extacl_passwd
; /* Password returned by extacl lookup */
194 String extacl_log
; /* String to be used for access.log purposes */
196 String extacl_message
; /* String to be used for error page purposes */
198 #if FOLLOW_X_FORWARDED_FOR
199 String x_forwarded_for_iterator
; /* XXX a list of IP addresses */
200 #endif /* FOLLOW_X_FORWARDED_FOR */
202 /// A strong etag of the cached entry. Used for refreshing that entry.
205 /// whether we have responded with HTTP 100 or FTP 150 already
206 bool forcedBodyContinuation
;
209 bool multipartRangeRequest() const;
211 bool parseFirstLine(const char *start
, const char *end
);
213 bool parseHeader(Http1::RequestParser
&hp
); // TODO move this function to the parser
215 virtual bool expectingBody(const HttpRequestMethod
& unused
, int64_t&) const;
217 bool bodyNibbled() const; // the request has a [partially] consumed body
221 void swapOut(StoreEntry
* e
);
223 void pack(Packer
* p
);
225 static void httpRequestPack(void *obj
, Packer
*p
);
227 static HttpRequest
* CreateFromUrlAndMethod(char * url
, const HttpRequestMethod
& method
);
229 static HttpRequest
* CreateFromUrl(char * url
);
231 ConnStateData
*pinnedConnection();
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.
239 const char *storeId();
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
246 CbcPointer
<ConnStateData
> clientConnectionManager
;
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 */
253 const char *packableURI(bool full_uri
) const;
255 mutable int64_t rangeOffsetLimit
; /* caches the result of getRangeOffsetLimit */
258 virtual void packFirstLineInto(Packer
* p
, bool full_uri
) const;
260 virtual bool sanityCheckStartLine(MemBuf
*buf
, const size_t hdr_len
, Http::StatusCode
*error
);
262 virtual void hdrCacheInit();
264 virtual bool inheritProperties(const HttpMsg
*aMsg
);
267 #endif /* SQUID_HTTPREQUEST_H */