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 "http/RequestMethod.h"
41 #include "RequestFlags.h"
45 #include "auth/UserRequest.h"
48 #include "adaptation/History.h"
51 #include "adaptation/icap/History.h"
54 #include "eui/Eui48.h"
55 #include "eui/Eui64.h"
61 void httpRequestPack(void *obj
, Packer
*p
);
64 class DnsLookupDetails
;
66 class HttpRequest
: public HttpMsg
70 typedef RefCount
<HttpRequest
> Pointer
;
72 MEMPROXY_CLASS(HttpRequest
);
74 HttpRequest(const HttpRequestMethod
& aMethod
, AnyP::ProtocolType aProtocol
, const char *aUrlpath
);
78 void initHTTP(const HttpRequestMethod
& aMethod
, AnyP::ProtocolType aProtocol
, const char *aUrlpath
);
80 virtual HttpRequest
*clone() const;
82 /// Whether response to this request is potentially cachable
83 /// \retval false Not cacheable.
84 /// \retval true Possibly cacheable. Response factors will determine.
85 bool maybeCacheable();
87 bool conditional() const; ///< has at least one recognized If-* header
89 /// whether the client is likely to be able to handle a 1xx reply
90 bool canHandle1xx() const;
92 /* Now that we care what host contains it is better off being protected. */
93 /* HACK: These two methods are only inline to get around Makefile dependancies */
94 /* caused by HttpRequest being used in places it really shouldn't. */
95 /* ideally they would be methods of URL instead. */
96 inline void SetHost(const char *src
) {
99 if (host_addr
.isAnyAddr()) {
100 xstrncpy(host
, src
, SQUIDHOSTNAMELEN
);
103 host_addr
.toHostStr(host
, SQUIDHOSTNAMELEN
);
104 debugs(23, 3, "HttpRequest::SetHost() given IP: " << host_addr
);
107 safe_free(canonical
); // force its re-build
109 inline const char* GetHost(void) const { return host
; };
110 inline int GetHostIsNumeric(void) const { return host_is_numeric
; };
113 /// Returns possibly nil history, creating it if adapt. logging is enabled
114 Adaptation::History::Pointer
adaptLogHistory() const;
115 /// Returns possibly nil history, creating it if requested
116 Adaptation::History::Pointer
adaptHistory(bool createIfNone
= false) const;
117 /// Makes their history ours, throwing on conflicts
118 void adaptHistoryImport(const HttpRequest
&them
);
121 /// Returns possibly nil history, creating it if icap logging is enabled
122 Adaptation::Icap::History::Pointer
icapHistory() const;
125 void recordLookup(const DnsLookupDetails
&detail
);
127 /// sets error detail if no earlier detail was available
128 void detailError(err_type aType
, int aDetail
);
129 /// clear error details, useful for retries/repeats
138 HttpRequestMethod method
;
140 // TODO expand to include all URI parts
141 URL url
; ///< the request URI (scheme only)
143 char login
[MAX_LOGIN_SZ
];
146 char host
[SQUIDHOSTNAMELEN
];
150 mutable Adaptation::History::Pointer adaptHistory_
; ///< per-HTTP transaction info
153 mutable Adaptation::Icap::History::Pointer icapHistory_
; ///< per-HTTP transaction info
157 Ip::Address host_addr
;
159 Auth::UserRequest::Pointer auth_user_request
;
168 * If defined, store_id_program mapped the request URL to this ID.
169 * Store uses this ID (and not the URL) to find and store entries,
170 * avoiding caching duplicate entries when different URLs point to
171 * "essentially the same" cachable resource.
183 Ip::Address client_addr
;
185 #if FOLLOW_X_FORWARDED_FOR
186 Ip::Address indirect_client_addr
;
187 #endif /* FOLLOW_X_FORWARDED_FOR */
191 HierarchyLogEntry hier
;
193 int dnsWait
; ///< sum of DNS lookup delays in milliseconds, for %dt
196 int errDetail
; ///< errType-specific detail about the transaction error
198 char *peer_login
; /* Configured peer login:password */
200 char *peer_host
; /* Selected peer host*/
202 time_t lastmod
; /* Used on refreshes */
204 const char *vary_headers
; /* Used when varying entities are detected. Changes how the store key is calculated */
206 char *peer_domain
; /* Configured peer forceddomain */
208 String myportname
; // Internal tag name= value from port this requests arrived in.
210 NotePairs::Pointer notes
; ///< annotations added by the note directive and helpers
212 String tag
; /* Internal tag for this request */
214 String extacl_user
; /* User name returned by extacl lookup */
216 String extacl_passwd
; /* Password returned by extacl lookup */
218 String extacl_log
; /* String to be used for access.log purposes */
220 String extacl_message
; /* String to be used for error page purposes */
222 #if FOLLOW_X_FORWARDED_FOR
223 String x_forwarded_for_iterator
; /* XXX a list of IP addresses */
224 #endif /* FOLLOW_X_FORWARDED_FOR */
226 /// A strong etag of the cached entry. Used for refreshing that entry.
230 bool multipartRangeRequest() const;
232 bool parseFirstLine(const char *start
, const char *end
);
234 bool parseHeader(Http1::RequestParser
&hp
); // TODO move this function to the parser
236 virtual bool expectingBody(const HttpRequestMethod
& unused
, int64_t&) const;
238 bool bodyNibbled() const; // the request has a [partially] consumed body
242 void swapOut(StoreEntry
* e
);
244 void pack(Packer
* p
);
246 static void httpRequestPack(void *obj
, Packer
*p
);
248 static HttpRequest
* CreateFromUrlAndMethod(char * url
, const HttpRequestMethod
& method
);
250 static HttpRequest
* CreateFromUrl(char * url
);
252 ConnStateData
*pinnedConnection();
255 * Returns the current StoreID for the request as a nul-terminated char*.
256 * Always returns the current id for the request
257 * (either the request canonical url or modified ID by the helper).
258 * Does not return NULL.
260 const char *storeId();
263 * The client connection manager, if known;
264 * Used for any response actions needed directly to the client.
265 * ie 1xx forwarding or connection pinning state changes
267 CbcPointer
<ConnStateData
> clientConnectionManager
;
269 /// forgets about the cached Range header (for a reason)
270 void ignoreRange(const char *reason
);
271 int64_t getRangeOffsetLimit(); /* the result of this function gets cached in rangeOffsetLimit */
274 const char *packableURI(bool full_uri
) const;
276 mutable int64_t rangeOffsetLimit
; /* caches the result of getRangeOffsetLimit */
279 virtual void packFirstLineInto(Packer
* p
, bool full_uri
) const;
281 virtual bool sanityCheckStartLine(MemBuf
*buf
, const size_t hdr_len
, Http::StatusCode
*error
);
283 virtual void hdrCacheInit();
285 virtual bool inheritProperties(const HttpMsg
*aMsg
);
288 MEMPROXY_CLASS_INLINE(HttpRequest
);
290 #endif /* SQUID_HTTPREQUEST_H */