http.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_HTTP_H
10 #define SQUID_SRC_HTTP_H
11 
12 #include "clients/Client.h"
13 #include "comm.h"
14 #include "http/forward.h"
15 #include "http/StateFlags.h"
16 #include "sbuf/SBuf.h"
17 
18 #include <optional>
19 
20 class FwdState;
21 class HttpHeader;
22 class String;
23 
24 class HttpStateData : public Client
25 {
27 
28 public:
29 
32  {
33  public:
35 
38  Answers make(const Answers ans, const char *why);
39 
41  const char *reason;
42  const StoreEntry *entry;
44  };
45 
47  ~HttpStateData() override;
48 
50  StoreEntry * entry,
51  const AccessLogEntryPointer &al,
52  HttpHeader * hdr_out,
53  const CachePeer *peer,
54  const Http::StateFlags &flags);
55 
56  const Comm::ConnectionPointer & dataConnection() const override;
57  /* should be private */
58  bool sendRequest();
59  void processReplyHeader();
60  void processReplyBody() override;
61  void readReply(const CommIoCbParams &io);
62  void maybeReadVirginBody() override; // read response data from the network
63 
64  // Checks whether the response is cacheable/shareable.
66 
67  CachePeer *_peer = nullptr; /* CachePeer request made to */
68  int eof = 0; /* reached end-of-object? */
69  int lastChunk = 0; /* reached last chunk of a chunk-encoded reply */
72  bool ignoreCacheControl = false;
73  bool surrogateNoStore = false;
74 
77 
79 
80 protected:
81  /* Client API */
82  void noteDelayAwareReadChance() override;
83 
84  void processReply();
85  void proceedAfter1xx();
86  void handle1xx(const HttpReplyPointer &);
87  void drop1xx(const char *reason);
88 
89 private:
101  };
105  void checkDateSkew(HttpReply *);
106 
108  void truncateVirginBody();
109 
110  void start() override;
111  void haveParsedReplyHeaders() override;
112  bool getMoreRequestBody(MemBuf &buf) override;
113  void closeServer() override; // end communication with the server
114  bool doneWithServer() const override; // did we end communication?
115  void abortAll(const char *reason) override; // abnormal termination
116  bool mayReadVirginReplyBody() const override;
117 
118  void abortTransaction(const char *reason) { abortAll(reason); } // abnormal termination
119 
120  size_t calcReadBufferCapacityLimit() const;
121  std::optional<size_t> canBufferMoreReplyBytes() const;
122  size_t maybeMakeSpaceAvailable(size_t maxReadSize);
123 
124  // consuming request body
125  virtual void handleMoreRequestBodyAvailable();
126  void handleRequestBodyProducerAborted() override;
127 
128  void writeReplyBody();
130  bool finishingBrokenPost();
132  void doneSendingRequestBody() override;
133  void requestBodyHandler(MemBuf &);
134  void sentRequestBody(const CommIoCbParams &io) override;
135  void wroteLast(const CommIoCbParams &io);
136  void sendComplete();
137  void httpStateConnClosed(const CommCloseCbParams &params);
138  void httpTimeout(const CommTimeoutCbParams &params);
140 
142  void forwardUpgrade(HttpHeader&);
143  static bool decideIfWeDoRanges (HttpRequest * orig_request);
144  bool peerSupportsConnectionPinning() const;
145  const char *blockSwitchingProtocols(const HttpReply&) const;
146 
150 
152  int64_t payloadSeen = 0;
154  int64_t payloadTruncated = 0;
155 
157  bool waitingForCommRead = false;
158 
161  bool sawDateGoBack = false;
162 };
163 
164 std::ostream &operator <<(std::ostream &os, const HttpStateData::ReuseDecision &d);
165 
166 int httpCachable(const HttpRequestMethod&);
167 void httpStart(FwdState *);
168 SBuf httpMakeVaryMark(HttpRequest * request, HttpReply const * reply);
169 
170 #endif /* SQUID_SRC_HTTP_H */
171 
~HttpStateData() override
Definition: http.cc:115
void drop1xx(const char *reason)
Definition: http.cc:804
void truncateVirginBody()
Definition: http.cc:1386
StoreEntry * entry
Definition: Client.h:179
void markPrematureReplyBodyEofFailure()
called on a premature EOF discovered when reading response body
Definition: http.cc:1411
void noteDelayAwareReadChance() override
Definition: http.cc:1161
bool ignoreCacheControl
Definition: http.h:72
Definition: Client.h:29
Http::StateFlags flags
Definition: http.h:70
void doneSendingRequestBody() override
Definition: http.cc:2608
Answers make(const Answers ans, const char *why)
stores the corresponding decision
Definition: http.cc:2696
String * upgradeHeaderOut
Upgrade header value sent to the origin server or cache peer.
Definition: http.h:76
void checkDateSkew(HttpReply *)
Definition: http.cc:628
int64_t payloadTruncated
positive when we read more than we wanted
Definition: http.h:154
void sentRequestBody(const CommIoCbParams &io) override
Definition: http.cc:2676
const Http::StatusCode statusCode
HTTP status for debugging.
Definition: http.h:43
bool surrogateNoStore
Definition: http.h:73
int lastChunk
Definition: http.h:69
bool finishingBrokenPost()
if broken posts are enabled for the request, try to fix and return true
Definition: http.cc:2556
CachePeer * _peer
Definition: http.h:67
Definition: SBuf.h:93
mb_size_t buildRequestPrefix(MemBuf *mb)
Definition: http.cc:2365
ConnectionStatus statusIfComplete() const
Definition: http.cc:1061
AsyncCall::Pointer closeHandler
Definition: http.h:96
ConnectionStatus
Definition: http.h:97
HttpStateData(FwdState *)
Definition: http.cc:79
const char * blockSwitchingProtocols(const HttpReply &) const
Definition: http.cc:822
void handle1xx(const HttpReplyPointer &)
ignore or start forwarding the 1xx response (a.k.a., control message)
Definition: http.cc:748
bool getMoreRequestBody(MemBuf &buf) override
either fill buf with available [encoded] request body bytes or return false
Definition: http.cc:2495
bool sendRequest()
Definition: http.cc:2410
size_t calcReadBufferCapacityLimit() const
Definition: http.cc:1645
void handleRequestBodyProducerAborted() override
Definition: http.cc:2656
size_t maybeMakeSpaceAvailable(size_t maxReadSize)
Definition: http.cc:1697
std::optional< size_t > canBufferMoreReplyBytes() const
Definition: http.cc:1671
Comm::ConnectionPointer serverConnection
Definition: http.h:95
StatusCode
Definition: StatusCode.h:20
void keepaliveAccounting(HttpReply *)
Definition: http.cc:608
bool decodeAndWriteReplyBody()
Definition: http.cc:1450
void readReply(const CommIoCbParams &io)
Definition: http.cc:1168
static bool decideIfWeDoRanges(HttpRequest *orig_request)
Definition: http.cc:2335
void processReplyBody() override
Definition: http.cc:1483
@ COMPLETE_NONPERSISTENT_MSG
Definition: http.h:100
void sendComplete()
successfully wrote the entire request (including body, last-chunk, etc.)
Definition: http.cc:1752
void httpStart(FwdState *)
Definition: http.cc:2529
void processReplyHeader()
Definition: http.cc:645
ReuseDecision(const StoreEntry *e, const Http::StatusCode code)
Definition: http.cc:2692
static void httpBuildRequestHeader(HttpRequest *request, StoreEntry *entry, const AccessLogEntryPointer &al, HttpHeader *hdr_out, const CachePeer *peer, const Http::StateFlags &flags)
Definition: http.cc:1908
@ COMPLETE_PERSISTENT_MSG
Definition: http.h:99
SBuf inBuf
I/O buffer for receiving server responses.
Definition: http.h:71
virtual void handleMoreRequestBodyAvailable()
Definition: http.cc:2624
SBuf httpMakeVaryMark(HttpRequest *request, HttpReply const *reply)
Definition: http.cc:589
Definition: MemBuf.h:23
const StoreEntry * entry
entry for debugging
Definition: http.h:42
void proceedAfter1xx()
restores state and resumes processing after 1xx is ignored or forwarded
Definition: http.cc:849
ConnectionStatus persistentConnStatus() const
Definition: http.cc:1111
@ INCOMPLETE_MSG
Definition: http.h:98
void httpTimeout(const CommTimeoutCbParams &params)
Definition: http.cc:146
Answers answer
the decision id
Definition: http.h:40
void haveParsedReplyHeaders() override
called when we have final (possibly adapted) reply headers; kids extend
Definition: http.cc:936
void abortTransaction(const char *reason)
Definition: http.h:118
void writeReplyBody()
Definition: http.cc:1424
void closeServer() override
Definition: http.cc:1771
void httpStateConnClosed(const CommCloseCbParams &params)
Definition: http.cc:138
bool mayReadVirginReplyBody() const override
whether we may receive more virgin response body bytes
Definition: http.cc:1587
std::ostream & operator<<(std::ostream &os, const HttpStateData::ReuseDecision &d)
Definition: http.cc:2703
int code
Definition: smb-errors.c:145
ReuseDecision::Answers reusableReply(ReuseDecision &decision)
Definition: http.cc:296
void start() override
called by AsyncStart; do not call directly
Definition: http.cc:2536
Http1::TeChunkedParser * httpChunkDecoder
Definition: http.h:149
void wroteLast(const CommIoCbParams &io)
called after writing the very last request byte (body, last-chunk, etc)
Definition: http.cc:1715
Http1::ResponseParserPointer hp
Parser being used at present to parse the HTTP/ICY server response.
Definition: http.h:148
const Comm::ConnectionPointer & dataConnection() const override
Definition: http.cc:132
assists in making and relaying entry caching/sharing decision
Definition: http.h:31
const char * reason
the decision reason
Definition: http.h:41
int httpCachable(const HttpRequestMethod &)
int eof
Definition: http.h:68
bool sawDateGoBack
Definition: http.h:161
CBDATA_CHILD(HttpStateData)
bool peerSupportsConnectionPinning() const
Definition: http.cc:878
void processReply()
Definition: http.cc:1287
bool finishingChunkedRequest()
if needed, write last-chunk to end the request body and return true
Definition: http.cc:2591
bool doneWithServer() const override
Definition: http.cc:1784
void abortAll(const char *reason) override
abnormal transaction termination; reason is for debugging only
Definition: http.cc:2685
ssize_t mb_size_t
Definition: MemBuf.h:17
void maybeReadVirginBody() override
read response data from the network
Definition: http.cc:1596
void processSurrogateControl(HttpReply *)
Definition: http.cc:258
int64_t payloadSeen
amount of message payload/body received so far.
Definition: http.h:152
bool continueAfterParsingHeader()
Definition: http.cc:1318
bool waitingForCommRead
whether we are waiting for our Comm::Read() handler to be called
Definition: http.h:157
void requestBodyHandler(MemBuf &)
void forwardUpgrade(HttpHeader &)
Definition: http.cc:2083
HttpRequestPointer request
Definition: Client.h:181

 

Introduction

Documentation

Support

Miscellaneous