Squid Web Cache master
Loading...
Searching...
No Matches
HttpRequest.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9#ifndef SQUID_SRC_HTTPREQUEST_H
10#define SQUID_SRC_HTTPREQUEST_H
11
12#include "anyp/Uri.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"
20#include "Notes.h"
21#include "RequestFlags.h"
22
23#if USE_AUTH
24#include "auth/UserRequest.h"
25#endif
26#if USE_ADAPTATION
27#include "adaptation/History.h"
28#endif
29#if ICAP_CLIENT
31#endif
32#if USE_SQUID_EUI
33#include "eui/Eui48.h"
34#include "eui/Eui64.h"
35#endif
36
37class AccessLogEntry;
39class CachePeer;
40class ConnStateData;
41class Downloader;
42
43/* Http Request */
44void httpRequestPack(void *obj, Packable *p);
45
46class HttpHdrRange;
47
49{
51
52public:
54
56 HttpRequest(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *schemeImage, const char *aUrlpath, const MasterXaction::Pointer &);
57 ~HttpRequest() override;
58 void reset() override;
59
60 void initHTTP(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *schemeImage, const char *aUrlpath);
61
62 HttpRequest *clone() const override;
63
67 bool maybeCacheable();
68
69 bool conditional() const;
70
72 bool canHandle1xx() const;
73
76 char *canonicalCleanUrl() const;
77
78#if USE_ADAPTATION
82 Adaptation::History::Pointer adaptHistory(bool createIfNone = false) const;
84 void adaptHistoryImport(const HttpRequest &them);
85#endif
86#if ICAP_CLIENT
89#endif
90
91 /* If a request goes through several destinations, then the following two
92 * methods will be called several times, in destinations-dependent order. */
94 void prepForPeering(const CachePeer &peer);
96 void prepForDirect();
97
98 void recordLookup(const Dns::LookupDetails &detail);
99
101 void detailError(const err_type c, const ErrorDetail::Pointer &d) { error.update(c, d); }
103 void clearError();
104
106 void manager(const CbcPointer<ConnStateData> &aMgr, const AccessLogEntryPointer &al);
107
108protected:
109 void clean();
110
111 void init();
112
113public:
116
117private:
118#if USE_ADAPTATION
120#endif
121#if ICAP_CLIENT
123#endif
124
125public:
126#if USE_AUTH
128#endif
129
131 const SBuf &effectiveRequestUri() const;
132
140
142
144
145 time_t ims;
146
148
150
151#if FOLLOW_X_FORWARDED_FOR
153#endif /* FOLLOW_X_FORWARDED_FOR */
154
156
158
160
162
163 char *peer_login; /* Configured peer login:password */
164
165 time_t lastmod; /* Used on refreshes */
166
169
170 char *peer_domain; /* Configured peer forceddomain */
171
172 String myportname; // Internal tag name= value from port this requests arrived in.
173
174 String tag; /* Internal tag for this request */
175
176 String extacl_user; /* User name returned by extacl lookup */
177
178 String extacl_passwd; /* Password returned by extacl lookup */
179
180 String extacl_log; /* String to be used for access.log purposes */
181
182 String extacl_message; /* String to be used for error page purposes */
183
184#if FOLLOW_X_FORWARDED_FOR
185 String x_forwarded_for_iterator; /* XXX a list of IP addresses */
186#endif /* FOLLOW_X_FORWARDED_FOR */
187
190
193
194public:
195 bool multipartRangeRequest() const;
196
197 bool parseFirstLine(const char *start, const char *end) override;
198
199 bool expectingBody(const HttpRequestMethod& unused, int64_t&) const override;
200
201 bool bodyNibbled() const; // the request has a [partially] consumed body
202
203 int prefixLen() const;
204
205 void swapOut(StoreEntry * e);
206
207 void pack(Packable * p, bool maskSensitiveInfo = false) const;
208
209 static void httpRequestPack(void *obj, Packable *p);
210
212
215
217
223 const SBuf storeId();
224
231
234
237
239 void ignoreRange(const char *reason);
240 int64_t getRangeOffsetLimit(); /* the result of this function gets cached in rangeOffsetLimit */
241
245 bool hasNotes() const { return bool(theNotes) && !theNotes->empty(); }
246
248
252
255 bool parseHeader(Http1::Parser &hp);
258 bool parseHeader(const char *buffer, const size_t size);
259
260private:
261 mutable int64_t rangeOffsetLimit; /* caches the result of getRangeOffsetLimit */
262
266protected:
267 void packFirstLineInto(Packable * p, bool full_uri) const override;
268
269 bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error) override;
270
271 void hdrCacheInit() override;
272
273 bool inheritProperties(const Http::Message *) override;
274};
275
276class ConnStateData;
280void UpdateRequestNotes(ConnStateData *csd, HttpRequest &request, NotePairs const &notes);
281
285
289
290#endif /* SQUID_SRC_HTTPREQUEST_H */
291
const Ip::Address * FindListeningPortAddress(const HttpRequest *, const AccessLogEntry *)
void httpRequestPack(void *obj, Packable *p)
void UpdateRequestNotes(ConnStateData *csd, HttpRequest &request, NotePairs const &notes)
RefCount< AccessLogEntry > AccessLogEntryPointer
Definition HttpRequest.h:38
AnyP::Port FindListeningPortNumber(const HttpRequest *, const AccessLogEntry *)
int size
Definition ModDevPoll.cc:70
NotePairs::Pointer notes()
encapsulates DNS lookup results
a transaction problem
Definition Error.h:27
void update(const Error &)
if necessary, stores the given error information (if any)
Definition Error.cc:51
String extacl_log
void recordLookup(const Dns::LookupDetails &detail)
bool conditional() const
has at least one recognized If-* header
HttpHdrRange * range
CbcPointer< ConnStateData > clientConnectionManager
Adaptation::History::Pointer adaptHistory(bool createIfNone=false) const
Returns possibly nil history, creating it if requested.
MasterXaction::Pointer masterXaction
the master transaction this request belongs to. Never nil.
void clearError()
clear error details, useful for retries/repeats
void prepForDirect()
get ready to be sent directly to an origin server, excluding originserver
void prepForPeering(const CachePeer &peer)
get ready to be sent to the given cache_peer, including originserver
HttpRequestMethod method
void initHTTP(const HttpRequestMethod &aMethod, AnyP::ProtocolType aProtocol, const char *schemeImage, const char *aUrlpath)
int64_t getRangeOffsetLimit()
String myportname
HttpRequest * clone() const override
bool inheritProperties(const Http::Message *) override
int prefixLen() const
static void httpRequestPack(void *obj, Packable *p)
Ip::Address indirect_client_addr
static HttpRequest * FromUrlXXX(const char *url, const MasterXaction::Pointer &, const HttpRequestMethod &method=Http::METHOD_GET)
bool parseHeader(Http1::Parser &hp)
String extacl_user
void packFirstLineInto(Packable *p, bool full_uri) const override
bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error) override
bool multipartRangeRequest() const
void pack(Packable *p, bool maskSensitiveInfo=false) const
HierarchyLogEntry hier
time_t lastmod
String extacl_message
Adaptation::Icap::History::Pointer icapHistory_
per-HTTP transaction info
void configureContentLengthInterpreter(Http::ContentLengthInterpreter &) override
configures the interpreter as needed
String store_id
RequestFlags flags
String extacl_passwd
int64_t rangeOffsetLimit
String x_forwarded_for_iterator
bool forcedBodyContinuation
whether we have responded with HTTP 100 or FTP 150 already
bool parseFirstLine(const char *start, const char *end) override
char * peer_domain
void detailError(const err_type c, const ErrorDetail::Pointer &d)
sets error detail if no earlier detail was available
NotePairs::Pointer notes()
bool bodyNibbled() const
bool hasNotes() const
SBuf vary_headers
The variant second-stage cache key. Generated from Vary header pattern for this request.
String etag
A strong etag of the cached entry. Used for refreshing that entry.
Adaptation::History::Pointer adaptHistory_
per-HTTP transaction info
~HttpRequest() override
CbcPointer< Downloader > downloader
The Downloader object which initiated the HTTP request if any.
ConnStateData * pinnedConnection()
int dnsWait
sum of DNS lookup delays in milliseconds, for dt
void ignoreRange(const char *reason)
forgets about the cached Range header (for a reason)
NotePairs::Pointer theNotes
char * peer_login
const SBuf storeId()
bool maybeCacheable()
void adaptHistoryImport(const HttpRequest &them)
Makes their history ours, throwing on conflicts.
MEMPROXY_CLASS(HttpRequest)
RefCount< HttpRequest > Pointer
Definition HttpRequest.h:53
void swapOut(StoreEntry *e)
void hdrCacheInit() override
char * canonicalCleanUrl() const
Ip::Address my_addr
void reset() override
Adaptation::History::Pointer adaptLogHistory() const
Returns possibly nil history, creating it if adapt. logging is enabled.
Auth::UserRequest::Pointer auth_user_request
bool expectingBody(const HttpRequestMethod &unused, int64_t &) const override
bool canHandle1xx() const
whether the client is likely to be able to handle a 1xx reply
static HttpRequest * FromUrl(const SBuf &url, const MasterXaction::Pointer &, const HttpRequestMethod &method=Http::METHOD_GET)
Http::StatusCode checkEntityFraming() const
Error error
the first transaction problem encountered (or falsy)
Adaptation::Icap::History::Pointer icapHistory() const
Returns possibly nil history, creating it if icap logging is enabled.
AnyP::Uri url
the request URI
Ip::Address client_addr
void manager(const CbcPointer< ConnStateData > &aMgr, const AccessLogEntryPointer &al)
associates the request with a from-client connection manager
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
common parts of HttpRequest and HttpReply
Definition Message.h:26
bool empty() const
Definition Notes.h:260
Definition SBuf.h:94
err_type
Definition forward.h:14
std::optional< KnownPort > Port
validated/supported port number (if any)
Definition UriScheme.h:26
StatusCode
Definition StatusCode.h:20
@ METHOD_GET
Definition MethodType.h:25