client_side_request.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_CLIENT_SIDE_REQUEST_H
10 #define SQUID_SRC_CLIENT_SIDE_REQUEST_H
11 
12 #include "AccessLogEntry.h"
13 #include "acl/FilledChecklist.h"
14 #include "client_side.h"
15 #include "http/forward.h"
16 #include "HttpHeaderRange.h"
17 #include "log/forward.h"
18 #include "LogTags.h"
19 #include "Store.h"
20 
21 #if USE_ADAPTATION
22 #include "adaptation/forward.h"
23 #include "adaptation/Initiator.h"
24 #endif
25 
27 class ConnStateData;
28 class MemObject;
29 
31 #if USE_ADAPTATION
32  : public Adaptation::Initiator, // to start adaptation transactions
33  public BodyConsumer // to receive reply bodies in request satisf. mode
34 #endif
35 {
36 #if USE_ADAPTATION
38 #else
40 #endif
41 
42 public:
45 #if USE_ADAPTATION
46  ~ClientHttpRequest() override;
47 #else
49 #endif
50 
51  String rangeBoundaryStr() const;
52  void freeResources();
53  void updateCounters();
54  void logRequest();
55  MemObject * memObject() const {
56  return (storeEntry() ? storeEntry()->mem_obj : nullptr);
57  }
58  bool multipartRangeRequest() const;
59  void processRequest();
60  void httpStart();
61  bool onlyIfCached()const;
62  bool gotEnough() const;
63  StoreEntry *storeEntry() const { return entry_; }
64  void storeEntry(StoreEntry *);
65  StoreEntry *loggingEntry() const { return loggingEntry_; }
66  void loggingEntry(StoreEntry *);
67 
69  return (cbdataReferenceValid(conn_) ? conn_ : nullptr);
70  }
71 
75  void initRequest(HttpRequest *);
76 
80  void resetRequest(HttpRequest *);
81 
82  // XXX: unify the uriChanged condition calculation with resetRequest() callers, removing this method
85  void resetRequestXXX(HttpRequest *, bool uriChanged);
86 
89 
91  void updateLoggingTags(const LogTags_ot code) { al->cache.code.update(code); }
92 
94  const LogTags &loggingTags() const { return al->cache.code; }
95 
96  int64_t mRangeCLen() const;
97 
98  void doCallouts();
99 
100  // The three methods below prepare log_uri and friends for future logging.
101  // Call the best-fit method whenever the current request or its URI changes.
102 
104  void setLogUriToRequestUri();
105 
108  void setLogUriToRawUri(const char *, const HttpRequestMethod &);
109 
112  void setErrorUri(const char *);
113 
118 
120  void calloutsError(const err_type, const ErrorDetail::Pointer &);
121 
123  void updateError(const Error &);
124 
125 public:
130  HttpRequest * const request = nullptr;
131 
135  char *uri = nullptr;
136 
137  // TODO: remove this field and store the URI directly in al->url
141  char * const log_uri = nullptr;
142 
143  String store_id; /* StoreID for transactions where the request member is nil */
144 
145  struct Out {
151  int64_t offset = 0;
153  uint64_t size = 0;
155  size_t headers_sz = 0;
156  } out;
157 
158  HttpHdrRangeIter range_iter; /* data for iterating thru range specs */
159  size_t req_sz = 0;
160 
162 
163  struct Flags {
164  bool accel = false;
165  bool done_copying = false;
166  } flags;
167 
168  struct Redirect {
170  char *location = nullptr;
171  } redirect;
172 
175 
177 
178 private:
180  void absorbLogUri(char *);
182  void clearRequest();
185  void assignRequest(HttpRequest *);
186 
187  int64_t maxReplyBodySize_ = 0;
188  StoreEntry *entry_ = nullptr;
190  ConnStateData * conn_ = nullptr;
191 
192 #if USE_OPENSSL
193 public:
200  void sslBumpStart();
202 
203 private:
206 #endif
207 
208 #if USE_ADAPTATION
209 public:
212 
213  /* AsyncJob API */
214  bool doneAll() const override {
215  return Initiator::doneAll() &&
217  false; // TODO: Refactor into a proper AsyncJob
218  }
219  void callException(const std::exception &) override;
220 
221 private:
224  void handleAdaptationFailure(const ErrorDetail::Pointer &, bool bypassable = false);
225 
228 
229  /* Adaptation::Initiator API */
231  void noteAdaptationAnswer(const Adaptation::Answer &) override;
232 
233  /* BodyConsumer API */
237 
238  void endRequestSatisfaction();
240  void resumeBodyStorage();
241 
242 private:
245 
248 
251 #endif
252 };
253 
254 /* client http based routines */
256 
260 
261 /* ones that should be elsewhere */
263 
264 #endif /* SQUID_SRC_CLIENT_SIDE_REQUEST_H */
@ bumpPeek
Definition: support.h:132
void setLogUriToRawUri(const char *, const HttpRequestMethod &)
void resetRequest(HttpRequest *)
ClientHttpRequest(ConnStateData *)
common parts of HttpRequest and HttpReply
Definition: Message.h:25
void noteAdaptationAnswer(const Adaptation::Answer &) override
void resetRequestXXX(HttpRequest *, bool uriChanged)
@ scNone
Definition: StatusCode.h:21
struct ClientHttpRequest::Redirect redirect
void initRequest(HttpRequest *)
std::unique_ptr< ACLFilledChecklist > MakingPointer
ConnStateData * getConn() const
void tunnelStart(ClientHttpRequest *)
Definition: tunnel.cc:1184
bool sslBumpNeeded() const
returns true if and only if the request needs to be bumped
#define CBDATA_CLASS(type)
Definition: cbdata.h:289
int64_t prepPartialResponseGeneration()
BumpMode
Definition: support.h:132
void startAdaptation(const Adaptation::ServiceGroupPointer &)
Initiate an asynchronous adaptation transaction which will call us back.
void setErrorUri(const char *)
void handleAdaptationFailure(const ErrorDetail::Pointer &, bool bypassable=false)
void updateLoggingTags(const LogTags_ot code)
update the code in the transaction processing tags
struct ClientHttpRequest::Flags flags
@ bumpEnd
Definition: support.h:132
struct ClientHttpRequest::Out out
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:270
bool doneAll() const override
whether positive goal has been reached
StatusCode
Definition: StatusCode.h:20
err_type
Definition: forward.h:14
void assignRequest(HttpRequest *)
void noteBodyProductionEnded(BodyPipe::Pointer) override
void checkForInternalAccess()
Checks whether the current request is internal and adjusts it accordingly.
HttpHdrRangeIter range_iter
size_t headers_sz
Response header bytes written to the client connection.
a transaction problem
Definition: Error.h:27
void callException(const std::exception &) override
called when the job throws during an async call
bool multipartRangeRequest() const
Definition: client_side.cc:696
@ bumpServerFirst
Definition: support.h:132
void clearRequest()
resets the current request and log_uri to nil
virtual bool doneAll() const
whether positive goal has been reached
Definition: AsyncJob.cc:112
bool requestSatisfactionMode() const
CBDATA_CHILD(ClientHttpRequest)
void clientAccessCheck(ClientHttpRequest *)
void noteMoreBodyDataAvailable(BodyPipe::Pointer) override
ACLFilledChecklist::MakingPointer clientAclChecklistCreate(const acl_access *, ClientHttpRequest *)
uint64_t size
Response header and body bytes written to the client connection.
void noteAdaptationAclCheckDone(Adaptation::ServiceGroupPointer) override
@ bumpStare
Definition: support.h:132
int code
Definition: smb-errors.c:145
ConnStateData * conn_
summarizes adaptation service answer for the noteAdaptationAnswer() API
Definition: Answer.h:24
Flag
Definition: Flag.h:15
const LogTags & loggingTags() const
the processing tags associated with this request transaction.
void clientAclChecklistFill(ACLFilledChecklist &, ClientHttpRequest *)
void sslBumpEstablish(Comm::Flag)
Ssl::BumpMode sslBumpNeed_
whether (and how) the request needs to be bumped
void noteBodyProducerAborted(BodyPipe::Pointer) override
void handleAdaptedHeader(Http::Message *)
void resumeBodyStorage()
called by StoreEntry when it has more buffer space available
@ bumpBump
Definition: support.h:132
void handleAdaptationBlock(const Adaptation::Answer &)
size_t req_sz
raw request size on input, not current request size
LogTags_ot
Definition: LogTags.h:40
String rangeBoundaryStr() const
Definition: client_side.cc:780
const AccessLogEntry::Pointer al
access.log entry
CbcPointer< Adaptation::Initiate > virginHeadSource
void setLogUriToRequestUri()
sets log_uri when we know the current request
void calloutsError(const err_type, const ErrorDetail::Pointer &)
Build an error reply. For use with the callouts.
bool receivedWholeAdaptedReply
noteBodyProductionEnded() was called
Ssl::BumpMode sslBumpNeed() const
returns raw sslBump mode value
ClientRequestContext * calloutContext
char * clientConstructTraceEcho(ClientHttpRequest *)
StoreEntry * storeEntry() const
StoreEntry * loggingEntry_
StoreEntry * loggingEntry() const
@ bumpClientFirst
Definition: support.h:132
MemObject * memObject() const
void updateError(const Error &)
if necessary, stores new error information (if any)
void absorbLogUri(char *)
assigns log_uri with aUri without copying the entire C-string
HttpRequest *const request
int64_t mRangeCLen() const
Definition: client_side.cc:740
BodyPipe::Pointer adaptedBodySource

 

Introduction

Documentation

Support

Miscellaneous