http.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_HTTP_H
10#define SQUID_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
18class FwdState;
19class HttpHeader;
20class String;
21
22class HttpStateData : public Client
23{
25
26public:
27
30 {
31 public:
33
36 Answers make(const Answers ans, const char *why);
37
39 const char *reason;
42 };
43
45 ~HttpStateData() override;
46
49 const AccessLogEntryPointer &al,
50 HttpHeader * hdr_out,
51 const Http::StateFlags &flags);
52
53 const Comm::ConnectionPointer & dataConnection() const override;
54 /* should be private */
55 bool sendRequest();
56 void processReplyHeader();
57 void processReplyBody() override;
58 void readReply(const CommIoCbParams &io);
59 void maybeReadVirginBody() override; // read response data from the network
60
61 // Checks whether the response is cacheable/shareable.
63
64 CachePeer *_peer = nullptr; /* CachePeer request made to */
65 int eof = 0; /* reached end-of-object? */
66 int lastChunk = 0; /* reached last chunk of a chunk-encoded reply */
69 bool ignoreCacheControl = false;
70 bool surrogateNoStore = false;
71
74
76
77protected:
78 /* Client API */
79 void noteDelayAwareReadChance() override;
80
81 void processReply();
82 void proceedAfter1xx();
83 void handle1xx(HttpReply *msg);
84 void drop1xx(const char *reason);
85
86private:
98 };
102 void checkDateSkew(HttpReply *);
103
105 void truncateVirginBody();
106
107 void start() override;
108 void haveParsedReplyHeaders() override;
109 bool getMoreRequestBody(MemBuf &buf) override;
110 void closeServer() override; // end communication with the server
111 bool doneWithServer() const override; // did we end communication?
112 void abortAll(const char *reason) override; // abnormal termination
113 bool mayReadVirginReplyBody() const override;
114
115 void abortTransaction(const char *reason) { abortAll(reason); } // abnormal termination
116
126 bool maybeMakeSpaceAvailable(bool grow);
127
128 // consuming request body
129 virtual void handleMoreRequestBodyAvailable();
130 void handleRequestBodyProducerAborted() override;
131
132 void writeReplyBody();
134 bool finishingBrokenPost();
136 void doneSendingRequestBody() override;
138 void sentRequestBody(const CommIoCbParams &io) override;
139 void wroteLast(const CommIoCbParams &io);
140 void sendComplete();
141 void httpStateConnClosed(const CommCloseCbParams &params);
142 void httpTimeout(const CommTimeoutCbParams &params);
144
147 static bool decideIfWeDoRanges (HttpRequest * orig_request);
149 const char *blockSwitchingProtocols(const HttpReply&) const;
150
154
156 int64_t payloadSeen = 0;
158 int64_t payloadTruncated = 0;
159
162 bool sawDateGoBack = false;
163};
164
165std::ostream &operator <<(std::ostream &os, const HttpStateData::ReuseDecision &d);
166
168void httpStart(FwdState *);
169SBuf httpMakeVaryMark(HttpRequest * request, HttpReply const * reply);
170
171#endif /* SQUID_HTTP_H */
172
ssize_t mb_size_t
Definition: MemBuf.h:17
Definition: Client.h:35
HttpRequestPointer request
Definition: Client.h:178
StoreEntry * entry
Definition: Client.h:176
assists in making and relaying entry caching/sharing decision
Definition: http.h:30
const Http::StatusCode statusCode
HTTP status for debugging.
Definition: http.h:41
Answers answer
the decision id
Definition: http.h:38
ReuseDecision(const StoreEntry *e, const Http::StatusCode code)
Definition: http.cc:2622
const StoreEntry * entry
entry for debugging
Definition: http.h:40
Answers make(const Answers ans, const char *why)
stores the corresponding decision
Definition: http.cc:2626
const char * reason
the decision reason
Definition: http.h:39
void httpStateConnClosed(const CommCloseCbParams &params)
Definition: http.cc:137
void handleRequestBodyProducerAborted() override
Definition: http.cc:2586
AsyncCall::Pointer closeHandler
Definition: http.h:93
Http1::ResponseParserPointer hp
Parser being used at present to parse the HTTP/ICY server response.
Definition: http.h:152
String * upgradeHeaderOut
Upgrade header value sent to the origin server or cache peer.
Definition: http.h:73
void handle1xx(HttpReply *msg)
ignore or start forwarding the 1xx response (a.k.a., control message)
Definition: http.cc:747
void start() override
called by AsyncStart; do not call directly
Definition: http.cc:2466
void processReply()
Definition: http.cc:1266
CachePeer * _peer
Definition: http.h:64
const char * blockSwitchingProtocols(const HttpReply &) const
Definition: http.cc:824
static void httpBuildRequestHeader(HttpRequest *request, StoreEntry *entry, const AccessLogEntryPointer &al, HttpHeader *hdr_out, const Http::StateFlags &flags)
Definition: http.cc:1835
static bool decideIfWeDoRanges(HttpRequest *orig_request)
Definition: http.cc:2264
void truncateVirginBody()
Definition: http.cc:1367
ConnectionStatus persistentConnStatus() const
Definition: http.cc:1113
void writeReplyBody()
Definition: http.cc:1405
void sendComplete()
successfully wrote the entire request (including body, last-chunk, etc.)
Definition: http.cc:1683
void httpTimeout(const CommTimeoutCbParams &params)
Definition: http.cc:145
ReuseDecision::Answers reusableReply(ReuseDecision &decision)
Definition: http.cc:295
void checkDateSkew(HttpReply *)
Definition: http.cc:627
bool doneWithServer() const override
Definition: http.cc:1715
int64_t payloadTruncated
positive when we read more than we wanted
Definition: http.h:158
int eof
Definition: http.h:65
void haveParsedReplyHeaders() override
called when we have final (possibly adapted) reply headers; kids extend
Definition: http.cc:938
void requestBodyHandler(MemBuf &)
void abortTransaction(const char *reason)
Definition: http.h:115
mb_size_t buildRequestPrefix(MemBuf *mb)
Definition: http.cc:2294
int lastChunk
Definition: http.h:66
bool sendRequest()
Definition: http.cc:2338
void readReply(const CommIoCbParams &io)
Definition: http.cc:1170
SBuf inBuf
I/O buffer for receiving server responses.
Definition: http.h:68
bool getMoreRequestBody(MemBuf &buf) override
either fill buf with available [encoded] request body bytes or return false
Definition: http.cc:2425
bool surrogateNoStore
Definition: http.h:70
HttpStateData(FwdState *)
Definition: http.cc:78
void abortAll(const char *reason) override
abnormal transaction termination; reason is for debugging only
Definition: http.cc:2615
CBDATA_CHILD(HttpStateData)
Http::StateFlags flags
Definition: http.h:67
bool ignoreCacheControl
Definition: http.h:69
void processSurrogateControl(HttpReply *)
Definition: http.cc:257
ConnectionStatus statusIfComplete() const
Definition: http.cc:1063
void processReplyBody() override
Definition: http.cc:1465
bool decodeAndWriteReplyBody()
Definition: http.cc:1431
void markPrematureReplyBodyEofFailure()
called on a premature EOF discovered when reading response body
Definition: http.cc:1392
bool mayReadVirginReplyBody() const override
whether we may receive more virgin response body bytes
Definition: http.cc:1574
bool continueAfterParsingHeader()
Definition: http.cc:1297
void maybeReadVirginBody() override
read response data from the network
Definition: http.cc:1583
int64_t payloadSeen
amount of message payload/body received so far.
Definition: http.h:156
bool maybeMakeSpaceAvailable(bool grow)
Definition: http.cc:1609
ConnectionStatus
Definition: http.h:94
@ COMPLETE_PERSISTENT_MSG
Definition: http.h:96
@ INCOMPLETE_MSG
Definition: http.h:95
@ COMPLETE_NONPERSISTENT_MSG
Definition: http.h:97
bool peerSupportsConnectionPinning() const
Definition: http.cc:880
virtual void handleMoreRequestBodyAvailable()
Definition: http.cc:2554
bool sawDateGoBack
Definition: http.h:162
void closeServer() override
Definition: http.cc:1702
void wroteLast(const CommIoCbParams &io)
called after writing the very last request byte (body, last-chunk, etc)
Definition: http.cc:1646
void processReplyHeader()
Definition: http.cc:644
void noteDelayAwareReadChance() override
Definition: http.cc:1163
const Comm::ConnectionPointer & dataConnection() const override
Definition: http.cc:131
void sentRequestBody(const CommIoCbParams &io) override
Definition: http.cc:2606
Comm::ConnectionPointer serverConnection
Definition: http.h:92
~HttpStateData() override
Definition: http.cc:114
void proceedAfter1xx()
restores state and resumes processing after 1xx is ignored or forwarded
Definition: http.cc:851
bool finishingChunkedRequest()
if needed, write last-chunk to end the request body and return true
Definition: http.cc:2521
void forwardUpgrade(HttpHeader &)
Definition: http.cc:2012
void keepaliveAccounting(HttpReply *)
Definition: http.cc:607
Http1::TeChunkedParser * httpChunkDecoder
Definition: http.h:153
bool finishingBrokenPost()
if broken posts are enabled for the request, try to fix and return true
Definition: http.cc:2486
void drop1xx(const char *reason)
Definition: http.cc:806
void doneSendingRequestBody() override
Definition: http.cc:2538
Definition: MemBuf.h:24
Definition: SBuf.h:94
int httpCachable(const HttpRequestMethod &)
SBuf httpMakeVaryMark(HttpRequest *request, HttpReply const *reply)
Definition: http.cc:588
void httpStart(FwdState *)
Definition: http.cc:2459
std::ostream & operator<<(std::ostream &os, const HttpStateData::ReuseDecision &d)
Definition: http.cc:2633
StatusCode
Definition: StatusCode.h:20
int code
Definition: smb-errors.c:145

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors