2 * Copyright (C) 1996-2014 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"
15 #include "HierarchyLogEntry.h"
17 #include "HttpRequestMethod.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"
39 void httpRequestPack(void *obj
, Packer
*p
);
42 class DnsLookupDetails
;
44 class HttpRequest
: public HttpMsg
48 typedef RefCount
<HttpRequest
> Pointer
;
50 MEMPROXY_CLASS(HttpRequest
);
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 DnsLookupDetails
&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 only)
121 char login
[MAX_LOGIN_SZ
];
124 char host
[SQUIDHOSTNAMELEN
];
128 mutable Adaptation::History::Pointer adaptHistory_
; ///< per-HTTP transaction info
131 mutable Adaptation::Icap::History::Pointer icapHistory_
; ///< per-HTTP transaction info
135 Ip::Address host_addr
;
137 Auth::UserRequest::Pointer auth_user_request
;
146 * If defined, store_id_program mapped the request URL to this ID.
147 * Store uses this ID (and not the URL) to find and store entries,
148 * avoiding caching duplicate entries when different URLs point to
149 * "essentially the same" cachable resource.
161 Ip::Address client_addr
;
163 #if FOLLOW_X_FORWARDED_FOR
164 Ip::Address indirect_client_addr
;
165 #endif /* FOLLOW_X_FORWARDED_FOR */
169 HierarchyLogEntry hier
;
171 int dnsWait
; ///< sum of DNS lookup delays in milliseconds, for %dt
174 int errDetail
; ///< errType-specific detail about the transaction error
176 char *peer_login
; /* Configured peer login:password */
178 char *peer_host
; /* Selected peer host*/
180 time_t lastmod
; /* Used on refreshes */
182 const char *vary_headers
; /* Used when varying entities are detected. Changes how the store key is calculated */
184 char *peer_domain
; /* Configured peer forceddomain */
186 String myportname
; // Internal tag name= value from port this requests arrived in.
188 NotePairs::Pointer notes
; ///< annotations added by the note directive and helpers
190 String tag
; /* Internal tag for this request */
192 String extacl_user
; /* User name returned by extacl lookup */
194 String extacl_passwd
; /* Password returned by extacl lookup */
196 String extacl_log
; /* String to be used for access.log purposes */
198 String extacl_message
; /* String to be used for error page purposes */
200 #if FOLLOW_X_FORWARDED_FOR
201 String x_forwarded_for_iterator
; /* XXX a list of IP addresses */
202 #endif /* FOLLOW_X_FORWARDED_FOR */
204 /// A strong etag of the cached entry. Used for refreshing that entry.
208 bool multipartRangeRequest() const;
210 bool parseFirstLine(const char *start
, const char *end
);
212 int parseHeader(const char *parse_start
, int len
);
214 virtual bool expectingBody(const HttpRequestMethod
& unused
, int64_t&) const;
216 bool bodyNibbled() const; // the request has a [partially] consumed body
220 void swapOut(StoreEntry
* e
);
222 void pack(Packer
* p
);
224 static void httpRequestPack(void *obj
, Packer
*p
);
226 static HttpRequest
* CreateFromUrlAndMethod(char * url
, const HttpRequestMethod
& method
);
228 static HttpRequest
* CreateFromUrl(char * url
);
230 ConnStateData
*pinnedConnection();
233 * Returns the current StoreID for the request as a nul-terminated char*.
234 * Always returns the current id for the request
235 * (either the request canonical url or modified ID by the helper).
236 * Does not return NULL.
238 const char *storeId();
241 * The client connection manager, if known;
242 * Used for any response actions needed directly to the client.
243 * ie 1xx forwarding or connection pinning state changes
245 CbcPointer
<ConnStateData
> clientConnectionManager
;
247 /// forgets about the cached Range header (for a reason)
248 void ignoreRange(const char *reason
);
249 int64_t getRangeOffsetLimit(); /* the result of this function gets cached in rangeOffsetLimit */
252 const char *packableURI(bool full_uri
) const;
254 mutable int64_t rangeOffsetLimit
; /* caches the result of getRangeOffsetLimit */
257 virtual void packFirstLineInto(Packer
* p
, bool full_uri
) const;
259 virtual bool sanityCheckStartLine(MemBuf
*buf
, const size_t hdr_len
, Http::StatusCode
*error
);
261 virtual void hdrCacheInit();
263 virtual bool inheritProperties(const HttpMsg
*aMsg
);
266 MEMPROXY_CLASS_INLINE(HttpRequest
);
268 #endif /* SQUID_HTTPREQUEST_H */