HttpRequest.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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 
39 class CachePeer;
40 class ConnStateData;
41 class Downloader;
42 
43 /* Http Request */
44 void httpRequestPack(void *obj, Packable *p);
45 
46 class HttpHdrRange;
47 
49 {
51 
52 public:
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 
108 protected:
109  void clean();
110 
111  void init();
112 
113 public:
116 
117 private:
118 #if USE_ADAPTATION
120 #endif
121 #if ICAP_CLIENT
123 #endif
124 
125 public:
126 #if USE_AUTH
128 #endif
129 
131  const SBuf &effectiveRequestUri() const;
132 
140 
142 
144 
145  time_t ims;
146 
147  int imslen;
148 
150 
151 #if FOLLOW_X_FORWARDED_FOR
153 #endif /* FOLLOW_X_FORWARDED_FOR */
154 
156 
158 
159  int dnsWait;
160 
162 
163  char *peer_login; /* Configured peer login:password */
164 
165  char *peer_host; /* Selected peer host*/
166 
167  time_t lastmod; /* Used on refreshes */
168 
171 
172  char *peer_domain; /* Configured peer forceddomain */
173 
174  String myportname; // Internal tag name= value from port this requests arrived in.
175 
176  String tag; /* Internal tag for this request */
177 
178  String extacl_user; /* User name returned by extacl lookup */
179 
180  String extacl_passwd; /* Password returned by extacl lookup */
181 
182  String extacl_log; /* String to be used for access.log purposes */
183 
184  String extacl_message; /* String to be used for error page purposes */
185 
186 #if FOLLOW_X_FORWARDED_FOR
187  String x_forwarded_for_iterator; /* XXX a list of IP addresses */
188 #endif /* FOLLOW_X_FORWARDED_FOR */
189 
192 
195 
196 public:
197  bool multipartRangeRequest() const;
198 
199  bool parseFirstLine(const char *start, const char *end) override;
200 
201  bool expectingBody(const HttpRequestMethod& unused, int64_t&) const override;
202 
203  bool bodyNibbled() const; // the request has a [partially] consumed body
204 
205  int prefixLen() const;
206 
207  void swapOut(StoreEntry * e);
208 
209  void pack(Packable * p) const;
210 
211  static void httpRequestPack(void *obj, Packable *p);
212 
214 
217 
219 
225  const SBuf storeId();
226 
233 
236 
239 
241  void ignoreRange(const char *reason);
242  int64_t getRangeOffsetLimit(); /* the result of this function gets cached in rangeOffsetLimit */
243 
247  bool hasNotes() const { return bool(theNotes) && !theNotes->empty(); }
248 
250 
254 
257  bool parseHeader(Http1::Parser &hp);
260  bool parseHeader(const char *buffer, const size_t size);
261 
262 private:
263  mutable int64_t rangeOffsetLimit; /* caches the result of getRangeOffsetLimit */
264 
268 protected:
269  void packFirstLineInto(Packable * p, bool full_uri) const override;
270 
271  bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error) override;
272 
273  void hdrCacheInit() override;
274 
275  bool inheritProperties(const Http::Message *) override;
276 };
277 
278 class ConnStateData;
282 void UpdateRequestNotes(ConnStateData *csd, HttpRequest &request, NotePairs const &notes);
283 
287 
291 
292 #endif /* SQUID_SRC_HTTPREQUEST_H */
293 
bool bodyNibbled() const
Definition: HttpRequest.cc:440
char * peer_host
Definition: HttpRequest.h:165
static HttpRequest * FromUrl(const SBuf &url, const MasterXaction::Pointer &, const HttpRequestMethod &method=Http::METHOD_GET)
Definition: HttpRequest.cc:517
void ignoreRange(const char *reason)
forgets about the cached Range header (for a reason)
Definition: HttpRequest.cc:621
AnyP::Uri url
the request URI
Definition: HttpRequest.h:115
common parts of HttpRequest and HttpReply
Definition: Message.h:25
MEMPROXY_CLASS(HttpRequest)
char * canonicalCleanUrl() const
Definition: HttpRequest.cc:813
bool parseHeader(Http1::Parser &hp)
Definition: HttpRequest.cc:711
Definition: Uri.h:31
bool hasNotes() const
Definition: HttpRequest.h:247
RequestFlags flags
Definition: HttpRequest.h:141
void clearError()
clear error details, useful for retries/repeats
Definition: HttpRequest.cc:465
String x_forwarded_for_iterator
Definition: HttpRequest.h:187
static void httpRequestPack(void *obj, Packable *p)
AnyP::Port FindListeningPortNumber(const HttpRequest *, const AccessLogEntry *)
Definition: HttpRequest.cc:872
int64_t getRangeOffsetLimit()
Definition: HttpRequest.cc:594
CbcPointer< Downloader > downloader
The Downloader object which initiated the HTTP request if any.
Definition: HttpRequest.h:235
Definition: SBuf.h:93
bool expectingBody(const HttpRequestMethod &unused, int64_t &) const override
Definition: HttpRequest.cc:488
~HttpRequest() override
Definition: HttpRequest.cc:61
bool maybeCacheable()
Definition: HttpRequest.cc:538
Auth::UserRequest::Pointer auth_user_request
Definition: HttpRequest.h:127
int dnsWait
sum of DNS lookup delays in milliseconds, for dt
Definition: HttpRequest.h:159
StatusCode
Definition: StatusCode.h:20
void hdrCacheInit() override
Definition: HttpRequest.cc:379
bool empty() const
Definition: Notes.h:260
err_type
Definition: forward.h:14
bool multipartRangeRequest() const
Definition: HttpRequest.cc:434
void detailError(const err_type c, const ErrorDetail::Pointer &d)
sets error detail if no earlier detail was available
Definition: HttpRequest.h:101
bool conditional() const
has at least one recognized If-* header
Definition: HttpRequest.cc:572
String extacl_user
Definition: HttpRequest.h:178
Adaptation::History::Pointer adaptHistory_
per-HTTP transaction info
Definition: HttpRequest.h:119
Error error
the first transaction problem encountered (or falsy)
Definition: HttpRequest.h:161
const Ip::Address * FindListeningPortAddress(const HttpRequest *, const AccessLogEntry *)
Definition: HttpRequest.cc:863
a transaction problem
Definition: Error.h:27
String myportname
Definition: HttpRequest.h:174
void init()
Definition: HttpRequest.cc:76
void configureContentLengthInterpreter(Http::ContentLengthInterpreter &) override
configures the interpreter as needed
Definition: HttpRequest.h:249
ProtocolType
Definition: ProtocolType.h:23
time_t lastmod
Definition: HttpRequest.h:167
void httpRequestPack(void *obj, Packable *p)
Definition: HttpRequest.cc:361
String etag
A strong etag of the cached entry. Used for refreshing that entry.
Definition: HttpRequest.h:191
void clean()
Definition: HttpRequest.cc:121
int size
Definition: ModDevPoll.cc:69
void recordLookup(const Dns::LookupDetails &detail)
Definition: HttpRequest.cc:580
Ip::Address indirect_client_addr
Definition: HttpRequest.h:152
char * peer_login
Definition: HttpRequest.h:163
ConnStateData * pinnedConnection()
Definition: HttpRequest.cc:725
bool canHandle1xx() const
whether the client is likely to be able to handle a 1xx reply
Definition: HttpRequest.cc:635
char * peer_domain
Definition: HttpRequest.h:172
Adaptation::Icap::History::Pointer icapHistory() const
Returns possibly nil history, creating it if icap logging is enabled.
Definition: HttpRequest.cc:389
RefCount< AccessLogEntry > AccessLogEntryPointer
Definition: HttpRequest.h:37
HttpRequest(const MasterXaction::Pointer &)
Definition: HttpRequest.cc:42
NotePairs::Pointer notes()
MasterXaction::Pointer masterXaction
the master transaction this request belongs to. Never nil.
Definition: HttpRequest.h:238
HierarchyLogEntry hier
Definition: HttpRequest.h:157
encapsulates DNS lookup results
Definition: LookupDetails.h:22
SBuf vary_headers
The variant second-stage cache key. Generated from Vary header pattern for this request.
Definition: HttpRequest.h:170
Ip::Address my_addr
Definition: HttpRequest.h:155
Adaptation::Icap::History::Pointer icapHistory_
per-HTTP transaction info
Definition: HttpRequest.h:122
HttpHdrRange * range
Definition: HttpRequest.h:143
void initHTTP(const HttpRequestMethod &aMethod, AnyP::ProtocolType aProtocol, const char *schemeImage, const char *aUrlpath)
Definition: HttpRequest.cc:68
Http::StatusCode checkEntityFraming() const
Definition: HttpRequest.cc:647
int prefixLen() const
Definition: HttpRequest.cc:369
HttpRequest * clone() const override
Definition: HttpRequest.cc:175
String extacl_log
Definition: HttpRequest.h:182
RefCount< HttpRequest > Pointer
Definition: HttpRequest.h:53
bool parseFirstLine(const char *start, const char *end) override
Definition: HttpRequest.cc:294
Adaptation::History::Pointer adaptHistory(bool createIfNone=false) const
Returns possibly nil history, creating it if requested.
Definition: HttpRequest.cc:404
Adaptation::History::Pointer adaptLogHistory() const
Returns possibly nil history, creating it if adapt. logging is enabled.
Definition: HttpRequest.cc:415
void UpdateRequestNotes(ConnStateData *csd, HttpRequest &request, NotePairs const &notes)
Definition: HttpRequest.cc:760
HttpRequestMethod method
Definition: HttpRequest.h:114
void prepForPeering(const CachePeer &peer)
get ready to be sent to the given cache_peer, including originserver
Definition: HttpRequest.cc:446
bool inheritProperties(const Http::Message *) override
Definition: HttpRequest.cc:214
bool forcedBodyContinuation
whether we have responded with HTTP 100 or FTP 150 already
Definition: HttpRequest.h:194
const SBuf storeId()
Definition: HttpRequest.cc:733
std::optional< KnownPort > Port
validated/supported port number (if any)
Definition: UriScheme.h:26
static HttpRequest * FromUrlXXX(const char *url, const MasterXaction::Pointer &, const HttpRequestMethod &method=Http::METHOD_GET)
Definition: HttpRequest.cc:528
int64_t rangeOffsetLimit
Definition: HttpRequest.h:263
void manager(const CbcPointer< ConnStateData > &aMgr, const AccessLogEntryPointer &al)
associates the request with a from-client connection manager
Definition: HttpRequest.cc:774
void packFirstLineInto(Packable *p, bool full_uri) const override
Definition: HttpRequest.cc:472
time_t ims
Definition: HttpRequest.h:145
String extacl_message
Definition: HttpRequest.h:184
void update(const Error &)
if necessary, stores the given error information (if any)
Definition: Error.cc:51
void prepForDirect()
get ready to be sent directly to an origin server, excluding originserver
Definition: HttpRequest.cc:456
void swapOut(StoreEntry *e)
Definition: HttpRequest.cc:334
@ METHOD_GET
Definition: MethodType.h:25
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
Definition: HttpRequest.cc:744
NotePairs::Pointer notes()
Definition: HttpRequest.cc:752
Ip::Address client_addr
Definition: HttpRequest.h:149
String tag
Definition: HttpRequest.h:176
void reset() override
Definition: HttpRequest.cc:168
void adaptHistoryImport(const HttpRequest &them)
Makes their history ours, throwing on conflicts.
Definition: HttpRequest.cc:421
String extacl_passwd
Definition: HttpRequest.h:180
String store_id
Definition: HttpRequest.h:139
bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error) override
Definition: HttpRequest.cc:268
NotePairs::Pointer theNotes
Definition: HttpRequest.h:267
CbcPointer< ConnStateData > clientConnectionManager
Definition: HttpRequest.h:232
void pack(Packable *p) const
Definition: HttpRequest.cc:344

 

Introduction

Documentation

Support

Miscellaneous