2 * Copyright (C) 1996-2025 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_SRC_HTTPREQUEST_H
10 #define SQUID_SRC_HTTPREQUEST_H
13 #include "base/CbcPointer.h"
14 #include "dns/forward.h"
15 #include "error/Error.h"
16 #include "HierarchyLogEntry.h"
17 #include "http/Message.h"
18 #include "http/RequestMethod.h"
19 #include "MasterXaction.h"
21 #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"
38 typedef RefCount
<AccessLogEntry
> AccessLogEntryPointer
;
44 void httpRequestPack(void *obj
, Packable
*p
);
48 class HttpRequest
: public Http::Message
50 MEMPROXY_CLASS(HttpRequest
);
53 typedef RefCount
<HttpRequest
> Pointer
;
55 HttpRequest(const MasterXaction::Pointer
&);
56 HttpRequest(const HttpRequestMethod
& aMethod
, AnyP::ProtocolType aProtocol
, const char *schemeImage
, const char *aUrlpath
, const MasterXaction::Pointer
&);
57 ~HttpRequest() override
;
58 void reset() override
;
60 void initHTTP(const HttpRequestMethod
& aMethod
, AnyP::ProtocolType aProtocol
, const char *schemeImage
, const char *aUrlpath
);
62 HttpRequest
*clone() const override
;
64 /// Whether response to this request is potentially cachable
65 /// \retval false Not cacheable.
66 /// \retval true Possibly cacheable. Response factors will determine.
67 bool maybeCacheable();
69 bool conditional() const; ///< has at least one recognized If-* header
71 /// whether the client is likely to be able to handle a 1xx reply
72 bool canHandle1xx() const;
74 /// \returns a pointer to a local static buffer containing request URI
75 /// that honors strip_query_terms and %-encodes unsafe URI characters
76 char *canonicalCleanUrl() const;
79 /// Returns possibly nil history, creating it if adapt. logging is enabled
80 Adaptation::History::Pointer
adaptLogHistory() const;
81 /// Returns possibly nil history, creating it if requested
82 Adaptation::History::Pointer
adaptHistory(bool createIfNone
= false) const;
83 /// Makes their history ours, throwing on conflicts
84 void adaptHistoryImport(const HttpRequest
&them
);
87 /// Returns possibly nil history, creating it if icap logging is enabled
88 Adaptation::Icap::History::Pointer
icapHistory() const;
91 /* If a request goes through several destinations, then the following two
92 * methods will be called several times, in destinations-dependent order. */
93 /// get ready to be sent to the given cache_peer, including originserver
94 void prepForPeering(const CachePeer
&peer
);
95 /// get ready to be sent directly to an origin server, excluding originserver
98 void recordLookup(const Dns::LookupDetails
&detail
);
100 /// sets error detail if no earlier detail was available
101 void detailError(const err_type c
, const ErrorDetail::Pointer
&d
) { error
.update(c
, d
); }
102 /// clear error details, useful for retries/repeats
105 /// associates the request with a from-client connection manager
106 void manager(const CbcPointer
<ConnStateData
> &aMgr
, const AccessLogEntryPointer
&al
);
114 HttpRequestMethod method
;
115 AnyP::Uri url
; ///< the request URI
119 mutable Adaptation::History::Pointer adaptHistory_
; ///< per-HTTP transaction info
122 mutable Adaptation::Icap::History::Pointer icapHistory_
; ///< per-HTTP transaction info
127 Auth::UserRequest::Pointer auth_user_request
;
130 /// RFC 7230 section 5.5 - Effective Request URI
131 const SBuf
&effectiveRequestUri() const;
134 * If defined, store_id_program mapped the request URL to this ID.
135 * Store uses this ID (and not the URL) to find and store entries,
136 * avoiding caching duplicate entries when different URLs point to
137 * "essentially the same" cachable resource.
149 Ip::Address client_addr
;
151 #if FOLLOW_X_FORWARDED_FOR
152 Ip::Address indirect_client_addr
;
153 #endif /* FOLLOW_X_FORWARDED_FOR */
157 HierarchyLogEntry hier
;
159 int dnsWait
; ///< sum of DNS lookup delays in milliseconds, for %dt
161 Error error
; ///< the first transaction problem encountered (or falsy)
163 char *peer_login
; /* Configured peer login:password */
165 time_t lastmod
; /* Used on refreshes */
167 /// The variant second-stage cache key. Generated from Vary header pattern for this request.
170 char *peer_domain
; /* Configured peer forceddomain */
172 String myportname
; // Internal tag name= value from port this requests arrived in.
174 String tag
; /* Internal tag for this request */
176 String extacl_user
; /* User name returned by extacl lookup */
178 String extacl_passwd
; /* Password returned by extacl lookup */
180 String extacl_log
; /* String to be used for access.log purposes */
182 String extacl_message
; /* String to be used for error page purposes */
184 #if FOLLOW_X_FORWARDED_FOR
185 String x_forwarded_for_iterator
; /* XXX a list of IP addresses */
186 #endif /* FOLLOW_X_FORWARDED_FOR */
188 /// A strong etag of the cached entry. Used for refreshing that entry.
191 /// whether we have responded with HTTP 100 or FTP 150 already
192 bool forcedBodyContinuation
;
195 bool multipartRangeRequest() const;
197 bool parseFirstLine(const char *start
, const char *end
) override
;
199 bool expectingBody(const HttpRequestMethod
& unused
, int64_t&) const override
;
201 bool bodyNibbled() const; // the request has a [partially] consumed body
203 int prefixLen() const;
205 void swapOut(StoreEntry
* e
);
207 void pack(Packable
* p
) const;
209 static void httpRequestPack(void *obj
, Packable
*p
);
211 static HttpRequest
* FromUrl(const SBuf
&url
, const MasterXaction::Pointer
&, const HttpRequestMethod
&method
= Http::METHOD_GET
);
213 /// \deprecated use SBuf variant instead
214 static HttpRequest
* FromUrlXXX(const char * url
, const MasterXaction::Pointer
&, const HttpRequestMethod
&method
= Http::METHOD_GET
);
216 ConnStateData
*pinnedConnection();
219 * Returns the current StoreID for the request as a nul-terminated char*.
220 * Always returns the current id for the request
221 * (either the effective request URI or modified ID by the helper).
223 const SBuf
storeId();
226 * The client connection manager, if known;
227 * Used for any response actions needed directly to the client.
228 * ie 1xx forwarding or connection pinning state changes
230 CbcPointer
<ConnStateData
> clientConnectionManager
;
232 /// The Downloader object which initiated the HTTP request if any
233 CbcPointer
<Downloader
> downloader
;
235 /// the master transaction this request belongs to. Never nil.
236 MasterXaction::Pointer masterXaction
;
238 /// forgets about the cached Range header (for a reason)
239 void ignoreRange(const char *reason
);
240 int64_t getRangeOffsetLimit(); /* the result of this function gets cached in rangeOffsetLimit */
242 /// \returns existing non-empty transaction annotations,
243 /// creates and returns empty annotations otherwise
244 NotePairs::Pointer
notes();
245 bool hasNotes() const { return bool(theNotes
) && !theNotes
->empty(); }
247 void configureContentLengthInterpreter(Http::ContentLengthInterpreter
&) override
{}
249 /// Check whether the message framing headers are valid.
250 /// \returns Http::scNone or an HTTP error status
251 Http::StatusCode
checkEntityFraming() const;
253 /// Parses request header using Parser.
254 /// Use it in contexts where the Parser object is available.
255 bool parseHeader(Http1::Parser
&hp
);
256 /// Parses request header from the buffer.
257 /// Use it in contexts where the Parser object not available.
258 bool parseHeader(const char *buffer
, const size_t size
);
261 mutable int64_t rangeOffsetLimit
; /* caches the result of getRangeOffsetLimit */
263 /// annotations added by the note directive and helpers
264 /// and(or) by annotate_transaction/annotate_client ACLs.
265 NotePairs::Pointer theNotes
;
267 void packFirstLineInto(Packable
* p
, bool full_uri
) const override
;
269 bool sanityCheckStartLine(const char *buf
, const size_t hdr_len
, Http::StatusCode
*error
) override
;
271 void hdrCacheInit() override
;
273 bool inheritProperties(const Http::Message
*) override
;
278 * Updates ConnStateData ids and HttpRequest notes from helpers received notes.
280 void UpdateRequestNotes(ConnStateData
*csd
, HttpRequest
&request
, NotePairs
const ¬es
);
282 /// \returns listening/*_port address used by the client connection (or nil)
283 /// nil parameter(s) indicate missing caller information and are handled safely
284 const Ip::Address
*FindListeningPortAddress(const HttpRequest
*, const AccessLogEntry
*);
286 /// \returns listening/*_port port number used by the client connection (or nothing)
287 /// nil parameter(s) indicate missing caller information and are handled safely
288 AnyP::Port
FindListeningPortNumber(const HttpRequest
*, const AccessLogEntry
*);
290 #endif /* SQUID_SRC_HTTPREQUEST_H */