3 * SQUID Web Proxy Cache http://www.squid-cache.org/
4 * ----------------------------------------------------------
6 * Squid is the result of efforts by numerous individuals from
7 * the Internet community; see the CONTRIBUTORS file for full
8 * details. Many organizations have provided support for Squid's
9 * development; see the SPONSORS file for full details. Squid is
10 * Copyrighted (C) 2001 by the Regents of the University of
11 * California; see the COPYRIGHT file for full details. Squid
12 * incorporates software developed and/or copyrighted by other
13 * sources; see the CREDITS file for full details.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 #ifndef SQUID_HTTPREQUEST_H
32 #define SQUID_HTTPREQUEST_H
34 #include "base/CbcPointer.h"
37 #include "HierarchyLogEntry.h"
39 #include "HttpRequestMethod.h"
41 #include "RequestFlags.h"
44 #include "auth/UserRequest.h"
47 #include "adaptation/History.h"
50 #include "adaptation/icap/History.h"
53 #include "eui/Eui48.h"
54 #include "eui/Eui64.h"
60 void httpRequestPack(void *obj
, Packer
*p
);
63 class DnsLookupDetails
;
65 class HttpRequest
: public HttpMsg
69 typedef RefCount
<HttpRequest
> Pointer
;
71 MEMPROXY_CLASS(HttpRequest
);
73 HttpRequest(const HttpRequestMethod
& aMethod
, AnyP::ProtocolType aProtocol
, const char *aUrlpath
);
77 void initHTTP(const HttpRequestMethod
& aMethod
, AnyP::ProtocolType aProtocol
, const char *aUrlpath
);
79 virtual HttpRequest
*clone() const;
81 /// Whether response to this request is potentially cachable
82 /// \retval false Not cacheable.
83 /// \retval true Possibly cacheable. Response factors will determine.
84 bool maybeCacheable();
86 bool conditional() const; ///< has at least one recognized If-* header
88 /// whether the client is likely to be able to handle a 1xx reply
89 bool canHandle1xx() const;
91 /* Now that we care what host contains it is better off being protected. */
92 /* HACK: These two methods are only inline to get around Makefile dependancies */
93 /* caused by HttpRequest being used in places it really shouldn't. */
94 /* ideally they would be methods of URL instead. */
95 inline void SetHost(const char *src
) {
98 if (host_addr
.isAnyAddr()) {
99 xstrncpy(host
, src
, SQUIDHOSTNAMELEN
);
102 host_addr
.toHostStr(host
, SQUIDHOSTNAMELEN
);
103 debugs(23, 3, "HttpRequest::SetHost() given IP: " << host_addr
);
106 safe_free(canonical
); // force its re-build
108 inline const char* GetHost(void) const { return host
; };
109 inline int GetHostIsNumeric(void) const { return host_is_numeric
; };
112 /// Returns possibly nil history, creating it if adapt. logging is enabled
113 Adaptation::History::Pointer
adaptLogHistory() const;
114 /// Returns possibly nil history, creating it if requested
115 Adaptation::History::Pointer
adaptHistory(bool createIfNone
= false) const;
116 /// Makes their history ours, throwing on conflicts
117 void adaptHistoryImport(const HttpRequest
&them
);
120 /// Returns possibly nil history, creating it if icap logging is enabled
121 Adaptation::Icap::History::Pointer
icapHistory() const;
124 void recordLookup(const DnsLookupDetails
&detail
);
126 /// sets error detail if no earlier detail was available
127 void detailError(err_type aType
, int aDetail
);
128 /// clear error details, useful for retries/repeats
137 HttpRequestMethod method
;
139 char login
[MAX_LOGIN_SZ
];
142 char host
[SQUIDHOSTNAMELEN
];
146 mutable Adaptation::History::Pointer adaptHistory_
; ///< per-HTTP transaction info
149 mutable Adaptation::Icap::History::Pointer icapHistory_
; ///< per-HTTP transaction info
153 Ip::Address host_addr
;
155 Auth::UserRequest::Pointer auth_user_request
;
164 * If defined, store_id_program mapped the request URL to this ID.
165 * Store uses this ID (and not the URL) to find and store entries,
166 * avoiding caching duplicate entries when different URLs point to
167 * "essentially the same" cachable resource.
179 Ip::Address client_addr
;
181 #if FOLLOW_X_FORWARDED_FOR
182 Ip::Address indirect_client_addr
;
183 #endif /* FOLLOW_X_FORWARDED_FOR */
187 HierarchyLogEntry hier
;
189 int dnsWait
; ///< sum of DNS lookup delays in milliseconds, for %dt
192 int errDetail
; ///< errType-specific detail about the transaction error
194 char *peer_login
; /* Configured peer login:password */
196 char *peer_host
; /* Selected peer host*/
198 time_t lastmod
; /* Used on refreshes */
200 const char *vary_headers
; /* Used when varying entities are detected. Changes how the store key is calculated */
202 char *peer_domain
; /* Configured peer forceddomain */
204 String myportname
; // Internal tag name= value from port this requests arrived in.
206 NotePairs::Pointer notes
; ///< annotations added by the note directive and helpers
208 String tag
; /* Internal tag for this request */
210 String extacl_user
; /* User name returned by extacl lookup */
212 String extacl_passwd
; /* Password returned by extacl lookup */
214 String extacl_log
; /* String to be used for access.log purposes */
216 String extacl_message
; /* String to be used for error page purposes */
218 #if FOLLOW_X_FORWARDED_FOR
219 String x_forwarded_for_iterator
; /* XXX a list of IP addresses */
220 #endif /* FOLLOW_X_FORWARDED_FOR */
222 /// A strong etag of the cached entry. Used for refreshing that entry.
226 bool multipartRangeRequest() const;
228 bool parseFirstLine(const char *start
, const char *end
);
230 int parseHeader(const char *parse_start
, int len
);
232 virtual bool expectingBody(const HttpRequestMethod
& unused
, int64_t&) const;
234 bool bodyNibbled() const; // the request has a [partially] consumed body
238 void swapOut(StoreEntry
* e
);
240 void pack(Packer
* p
);
242 static void httpRequestPack(void *obj
, Packer
*p
);
244 static HttpRequest
* CreateFromUrlAndMethod(char * url
, const HttpRequestMethod
& method
);
246 static HttpRequest
* CreateFromUrl(char * url
);
248 ConnStateData
*pinnedConnection();
251 * Returns the current StoreID for the request as a nul-terminated char*.
252 * Always returns the current id for the request
253 * (either the request canonical url or modified ID by the helper).
254 * Does not return NULL.
256 const char *storeId();
259 * The client connection manager, if known;
260 * Used for any response actions needed directly to the client.
261 * ie 1xx forwarding or connection pinning state changes
263 CbcPointer
<ConnStateData
> clientConnectionManager
;
265 /// forgets about the cached Range header (for a reason)
266 void ignoreRange(const char *reason
);
267 int64_t getRangeOffsetLimit(); /* the result of this function gets cached in rangeOffsetLimit */
270 const char *packableURI(bool full_uri
) const;
272 mutable int64_t rangeOffsetLimit
; /* caches the result of getRangeOffsetLimit */
275 virtual void packFirstLineInto(Packer
* p
, bool full_uri
) const;
277 virtual bool sanityCheckStartLine(MemBuf
*buf
, const size_t hdr_len
, Http::StatusCode
*error
);
279 virtual void hdrCacheInit();
281 virtual bool inheritProperties(const HttpMsg
*aMsg
);
284 MEMPROXY_CLASS_INLINE(HttpRequest
);
286 #endif /* SQUID_HTTPREQUEST_H */