Squid Web Cache master
Loading...
Searching...
No Matches
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
20class FwdState;
21class HttpHeader;
22class String;
23
24class HttpStateData : public Client
25{
27
28public:
29
32 {
33 public:
35
36 ReuseDecision(const StoreEntry *e, const Http::StatusCode code);
38 Answers make(const Answers ans, const char *why);
39
41 const char *reason;
44 };
45
47 ~HttpStateData() override;
48
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
80protected:
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
89private:
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 void handleRequestBodyProducerAborted() override;
125
126 void writeReplyBody();
128 bool finishingBrokenPost();
130 void doneSendingRequestBody() override;
132 void sentRequestBody(const CommIoCbParams &io) override;
133 void wroteLast(const CommIoCbParams &io);
134 void sendComplete();
135 void httpStateConnClosed(const CommCloseCbParams &params);
136 void httpTimeout(const CommTimeoutCbParams &params);
138
141 static bool decideIfWeDoRanges (HttpRequest * orig_request);
143 const char *blockSwitchingProtocols(const HttpReply&) const;
144
148
150 int64_t payloadSeen = 0;
152 int64_t payloadTruncated = 0;
153
155 bool waitingForCommRead = false;
156
159 bool sawDateGoBack = false;
160};
161
162std::ostream &operator <<(std::ostream &os, const HttpStateData::ReuseDecision &d);
163
165void httpStart(FwdState *);
166SBuf httpMakeVaryMark(HttpRequest * request, HttpReply const * reply);
167
168#endif /* SQUID_SRC_HTTP_H */
169
ssize_t mb_size_t
Definition MemBuf.h:17
HttpRequestPointer request
Definition Client.h:179
StoreEntry * entry
Definition Client.h:177
assists in making and relaying entry caching/sharing decision
Definition http.h:32
const Http::StatusCode statusCode
HTTP status for debugging.
Definition http.h:43
Answers answer
the decision id
Definition http.h:40
const StoreEntry * entry
entry for debugging
Definition http.h:42
Answers make(const Answers ans, const char *why)
stores the corresponding decision
Definition http.cc:2666
const char * reason
the decision reason
Definition http.h:41
void httpStateConnClosed(const CommCloseCbParams &params)
Definition http.cc:139
void handleRequestBodyProducerAborted() override
Definition http.cc:2626
AsyncCall::Pointer closeHandler
Definition http.h:96
Http1::ResponseParserPointer hp
Parser being used at present to parse the HTTP/ICY server response.
Definition http.h:146
String * upgradeHeaderOut
Upgrade header value sent to the origin server or cache peer.
Definition http.h:76
void start() override
called by AsyncStart; do not call directly
Definition http.cc:2538
void processReply()
Definition http.cc:1288
CachePeer * _peer
Definition http.h:67
const char * blockSwitchingProtocols(const HttpReply &) const
Definition http.cc:823
std::optional< size_t > canBufferMoreReplyBytes() const
Definition http.cc:1672
static bool decideIfWeDoRanges(HttpRequest *orig_request)
Definition http.cc:2337
void truncateVirginBody()
Definition http.cc:1387
ConnectionStatus persistentConnStatus() const
Definition http.cc:1112
void writeReplyBody()
Definition http.cc:1425
void sendComplete()
successfully wrote the entire request (including body, last-chunk, etc.)
Definition http.cc:1753
void httpTimeout(const CommTimeoutCbParams &params)
Definition http.cc:147
ReuseDecision::Answers reusableReply(ReuseDecision &decision)
Definition http.cc:297
void checkDateSkew(HttpReply *)
Definition http.cc:629
size_t maybeMakeSpaceAvailable(size_t maxReadSize)
Definition http.cc:1698
bool doneWithServer() const override
Definition http.cc:1785
int64_t payloadTruncated
positive when we read more than we wanted
Definition http.h:152
int eof
Definition http.h:68
void haveParsedReplyHeaders() override
called when we have final (possibly adapted) reply headers; kids extend
Definition http.cc:937
static void httpBuildRequestHeader(HttpRequest *request, StoreEntry *entry, const AccessLogEntryPointer &al, HttpHeader *hdr_out, const CachePeer *peer, const Http::StateFlags &flags)
Definition http.cc:1909
void requestBodyHandler(MemBuf &)
void abortTransaction(const char *reason)
Definition http.h:118
mb_size_t buildRequestPrefix(MemBuf *mb)
Definition http.cc:2367
int lastChunk
Definition http.h:69
bool sendRequest()
Definition http.cc:2412
void readReply(const CommIoCbParams &io)
Definition http.cc:1169
void handle1xx(const HttpReplyPointer &)
ignore or start forwarding the 1xx response (a.k.a., control message)
Definition http.cc:749
SBuf inBuf
I/O buffer for receiving server responses.
Definition http.h:71
bool getMoreRequestBody(MemBuf &buf) override
either fill buf with available [encoded] request body bytes or return false
Definition http.cc:2497
bool surrogateNoStore
Definition http.h:73
void abortAll(const char *reason) override
abnormal transaction termination; reason is for debugging only
Definition http.cc:2655
CBDATA_CHILD(HttpStateData)
Http::StateFlags flags
Definition http.h:70
bool ignoreCacheControl
Definition http.h:72
void processSurrogateControl(HttpReply *)
Definition http.cc:259
ConnectionStatus statusIfComplete() const
Definition http.cc:1062
void processReplyBody() override
Definition http.cc:1484
bool decodeAndWriteReplyBody()
Definition http.cc:1451
bool waitingForCommRead
whether we are waiting for our Comm::Read() handler to be called
Definition http.h:155
size_t calcReadBufferCapacityLimit() const
Definition http.cc:1646
void markPrematureReplyBodyEofFailure()
called on a premature EOF discovered when reading response body
Definition http.cc:1412
bool mayReadVirginReplyBody() const override
whether we may receive more virgin response body bytes
Definition http.cc:1588
bool continueAfterParsingHeader()
Definition http.cc:1319
void maybeReadVirginBody() override
read response data from the network
Definition http.cc:1597
int64_t payloadSeen
amount of message payload/body received so far.
Definition http.h:150
ConnectionStatus
Definition http.h:97
@ COMPLETE_PERSISTENT_MSG
Definition http.h:99
@ INCOMPLETE_MSG
Definition http.h:98
@ COMPLETE_NONPERSISTENT_MSG
Definition http.h:100
bool peerSupportsConnectionPinning() const
Definition http.cc:879
bool sawDateGoBack
Definition http.h:159
void closeServer() override
Definition http.cc:1772
void wroteLast(const CommIoCbParams &io)
called after writing the very last request byte (body, last-chunk, etc)
Definition http.cc:1716
void processReplyHeader()
Definition http.cc:646
void noteDelayAwareReadChance() override
Definition http.cc:1162
const Comm::ConnectionPointer & dataConnection() const override
Definition http.cc:133
void sentRequestBody(const CommIoCbParams &io) override
Definition http.cc:2646
Comm::ConnectionPointer serverConnection
Definition http.h:95
~HttpStateData() override
Definition http.cc:116
void proceedAfter1xx()
restores state and resumes processing after 1xx is ignored or forwarded
Definition http.cc:850
bool finishingChunkedRequest()
if needed, write last-chunk to end the request body and return true
Definition http.cc:2593
void forwardUpgrade(HttpHeader &)
Definition http.cc:2085
void keepaliveAccounting(HttpReply *)
Definition http.cc:609
Http1::TeChunkedParser * httpChunkDecoder
Definition http.h:147
bool finishingBrokenPost()
if broken posts are enabled for the request, try to fix and return true
Definition http.cc:2558
void drop1xx(const char *reason)
Definition http.cc:805
void doneSendingRequestBody() override
Definition http.cc:2610
Definition SBuf.h:94
int httpCachable(const HttpRequestMethod &)
SBuf httpMakeVaryMark(HttpRequest *request, HttpReply const *reply)
Definition http.cc:590
void httpStart(FwdState *)
Definition http.cc:2531
std::ostream & operator<<(std::ostream &os, const HttpStateData::ReuseDecision &d)
Definition http.cc:2673
StatusCode
Definition StatusCode.h:20