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"
40 #include "RequestFlags.h"
43 #include "auth/UserRequest.h"
46 #include "adaptation/History.h"
49 #include "adaptation/icap/History.h"
52 #include "eui/Eui48.h"
53 #include "eui/Eui64.h"
59 void httpRequestPack(void *obj
, Packer
*p
);
62 class DnsLookupDetails
;
64 class HttpRequest
: public HttpMsg
68 typedef HttpMsgPointerT
<HttpRequest
> Pointer
;
70 MEMPROXY_CLASS(HttpRequest
);
72 HttpRequest(const HttpRequestMethod
& aMethod
, AnyP::ProtocolType aProtocol
, const char *aUrlpath
);
76 // use HTTPMSGLOCK() instead of calling this directly
77 virtual HttpRequest
*_lock() {
78 return static_cast<HttpRequest
*>(HttpMsg::_lock());
81 void initHTTP(const HttpRequestMethod
& aMethod
, AnyP::ProtocolType aProtocol
, const char *aUrlpath
);
83 virtual HttpRequest
*clone() const;
85 /* are responses to this request potentially cachable */
86 bool cacheable() const;
88 bool conditional() const; ///< has at least one recognized If-* header
90 /// whether the client is likely to be able to handle a 1xx reply
91 bool canHandle1xx() const;
93 /* Now that we care what host contains it is better off being protected. */
94 /* HACK: These two methods are only inline to get around Makefile dependancies */
95 /* caused by HttpRequest being used in places it really shouldn't. */
96 /* ideally they would be methods of URL instead. */
97 inline void SetHost(const char *src
) {
100 if ( host_addr
.IsAnyAddr() ) {
101 xstrncpy(host
, src
, SQUIDHOSTNAMELEN
);
104 host_addr
.ToHostname(host
, SQUIDHOSTNAMELEN
);
105 debugs(23, 3, "HttpRequest::SetHost() given IP: " << host_addr
);
108 safe_free(canonical
); // force its re-build
110 inline const char* GetHost(void) const { return host
; };
111 inline int GetHostIsNumeric(void) const { return host_is_numeric
; };
114 /// Returns possibly nil history, creating it if adapt. logging is enabled
115 Adaptation::History::Pointer
adaptLogHistory() const;
116 /// Returns possibly nil history, creating it if requested
117 Adaptation::History::Pointer
adaptHistory(bool createIfNone
= false) const;
118 /// Makes their history ours, throwing on conflicts
119 void adaptHistoryImport(const HttpRequest
&them
);
122 /// Returns possibly nil history, creating it if icap logging is enabled
123 Adaptation::Icap::History::Pointer
icapHistory() const;
126 void recordLookup(const DnsLookupDetails
&detail
);
128 /// sets error detail if no earlier detail was available
129 void detailError(err_type aType
, int aDetail
);
130 /// clear error details, useful for retries/repeats
139 HttpRequestMethod method
;
141 char login
[MAX_LOGIN_SZ
];
144 char host
[SQUIDHOSTNAMELEN
];
148 mutable Adaptation::History::Pointer adaptHistory_
; ///< per-HTTP transaction info
151 mutable Adaptation::Icap::History::Pointer icapHistory_
; ///< per-HTTP transaction info
155 Ip::Address host_addr
;
157 Auth::UserRequest::Pointer auth_user_request
;
173 Ip::Address client_addr
;
175 #if FOLLOW_X_FORWARDED_FOR
176 Ip::Address indirect_client_addr
;
177 #endif /* FOLLOW_X_FORWARDED_FOR */
181 HierarchyLogEntry hier
;
183 int dnsWait
; ///< sum of DNS lookup delays in milliseconds, for %dt
186 int errDetail
; ///< errType-specific detail about the transaction error
188 char *peer_login
; /* Configured peer login:password */
190 char *peer_host
; /* Selected peer host*/
192 time_t lastmod
; /* Used on refreshes */
194 const char *vary_headers
; /* Used when varying entities are detected. Changes how the store key is calculated */
196 char *peer_domain
; /* Configured peer forceddomain */
198 String myportname
; // Internal tag name= value from port this requests arrived in.
200 String tag
; /* Internal tag for this request */
202 String extacl_user
; /* User name returned by extacl lookup */
204 String extacl_passwd
; /* Password returned by extacl lookup */
206 String extacl_log
; /* String to be used for access.log purposes */
208 String extacl_message
; /* String to be used for error page purposes */
210 #if FOLLOW_X_FORWARDED_FOR
211 String x_forwarded_for_iterator
; /* XXX a list of IP addresses */
212 #endif /* FOLLOW_X_FORWARDED_FOR */
214 /// A strong etag of the cached entry. Used for refreshing that entry.
218 bool multipartRangeRequest() const;
220 bool parseFirstLine(const char *start
, const char *end
);
222 int parseHeader(const char *parse_start
, int len
);
224 virtual bool expectingBody(const HttpRequestMethod
& unused
, int64_t&) const;
226 bool bodyNibbled() const; // the request has a [partially] consumed body
230 void swapOut(StoreEntry
* e
);
232 void pack(Packer
* p
);
234 static void httpRequestPack(void *obj
, Packer
*p
);
236 static HttpRequest
* CreateFromUrlAndMethod(char * url
, const HttpRequestMethod
& method
);
238 static HttpRequest
* CreateFromUrl(char * url
);
240 ConnStateData
*pinnedConnection();
243 * The client connection manager, if known;
244 * Used for any response actions needed directly to the client.
245 * ie 1xx forwarding or connection pinning state changes
247 CbcPointer
<ConnStateData
> clientConnectionManager
;
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_status
*error
);
261 virtual void hdrCacheInit();
263 virtual bool inheritProperties(const HttpMsg
*aMsg
);
266 MEMPROXY_CLASS_INLINE(HttpRequest
);
268 #endif /* SQUID_HTTPREQUEST_H */