2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
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.
12 #include "clients/Client.h"
14 #include "http/forward.h"
15 #include "http/StateFlags.h"
16 #include "sbuf/SBuf.h"
22 class HttpStateData
: public Client
24 CBDATA_CHILD(HttpStateData
);
28 /// assists in making and relaying entry caching/sharing decision
32 enum Answers
{ reuseNot
= 0, cachePositively
, cacheNegatively
, doNotCacheButShare
};
34 ReuseDecision(const StoreEntry
*e
, const Http::StatusCode code
);
35 /// stores the corresponding decision
36 Answers
make(const Answers ans
, const char *why
);
38 Answers answer
; ///< the decision id
39 const char *reason
; ///< the decision reason
40 const StoreEntry
*entry
; ///< entry for debugging
41 const Http::StatusCode statusCode
; ///< HTTP status for debugging
44 HttpStateData(FwdState
*);
45 ~HttpStateData() override
;
47 static void httpBuildRequestHeader(HttpRequest
* request
,
49 const AccessLogEntryPointer
&al
,
51 const Http::StateFlags
&flags
);
53 const Comm::ConnectionPointer
& dataConnection() const override
;
54 /* should be private */
56 void processReplyHeader();
57 void processReplyBody() override
;
58 void readReply(const CommIoCbParams
&io
);
59 void maybeReadVirginBody() override
; // read response data from the network
61 // Checks whether the response is cacheable/shareable.
62 ReuseDecision::Answers
reusableReply(ReuseDecision
&decision
);
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 */
67 Http::StateFlags flags
;
68 SBuf inBuf
; ///< I/O buffer for receiving server responses
69 bool ignoreCacheControl
= false;
70 bool surrogateNoStore
= false;
72 /// Upgrade header value sent to the origin server or cache peer.
73 String
*upgradeHeaderOut
= nullptr;
75 void processSurrogateControl(HttpReply
*);
79 void noteDelayAwareReadChance() override
;
82 void proceedAfter1xx();
83 void handle1xx(HttpReply
*msg
);
84 void drop1xx(const char *reason
);
88 * The current server connection.
89 * Maybe open, closed, or NULL.
90 * Use doneWithServer() to check if the server is available for use.
92 Comm::ConnectionPointer serverConnection
;
93 AsyncCall::Pointer closeHandler
;
94 enum ConnectionStatus
{
96 COMPLETE_PERSISTENT_MSG
,
97 COMPLETE_NONPERSISTENT_MSG
99 ConnectionStatus
statusIfComplete() const;
100 ConnectionStatus
persistentConnStatus() const;
101 void keepaliveAccounting(HttpReply
*);
102 void checkDateSkew(HttpReply
*);
104 bool continueAfterParsingHeader();
105 void truncateVirginBody();
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
;
115 void abortTransaction(const char *reason
) { abortAll(reason
); } // abnormal termination
118 * determine if read buffer can have space made available
121 * \param grow whether to actually expand the buffer
123 * \return whether the buffer can be grown to provide space
124 * regardless of whether the grow actually happened.
126 bool maybeMakeSpaceAvailable(bool grow
);
128 // consuming request body
129 virtual void handleMoreRequestBodyAvailable();
130 void handleRequestBodyProducerAborted() override
;
132 void writeReplyBody();
133 bool decodeAndWriteReplyBody();
134 bool finishingBrokenPost();
135 bool finishingChunkedRequest();
136 void doneSendingRequestBody() override
;
137 void requestBodyHandler(MemBuf
&);
138 void sentRequestBody(const CommIoCbParams
&io
) override
;
139 void wroteLast(const CommIoCbParams
&io
);
141 void httpStateConnClosed(const CommCloseCbParams
¶ms
);
142 void httpTimeout(const CommTimeoutCbParams
¶ms
);
144 mb_size_t
buildRequestPrefix(MemBuf
* mb
);
145 void forwardUpgrade(HttpHeader
&);
146 static bool decideIfWeDoRanges (HttpRequest
* orig_request
);
147 bool peerSupportsConnectionPinning() const;
148 const char *blockSwitchingProtocols(const HttpReply
&) const;
150 /// Parser being used at present to parse the HTTP/ICY server response.
151 Http1::ResponseParserPointer hp
;
152 Http1::TeChunkedParser
*httpChunkDecoder
= nullptr;
154 /// amount of message payload/body received so far.
155 int64_t payloadSeen
= 0;
156 /// positive when we read more than we wanted
157 int64_t payloadTruncated
= 0;
159 /// Whether we received a Date header older than that of a matching
161 bool sawDateGoBack
= false;
164 std::ostream
&operator <<(std::ostream
&os
, const HttpStateData::ReuseDecision
&d
);
166 int httpCachable(const HttpRequestMethod
&);
167 void httpStart(FwdState
*);
168 SBuf
httpMakeVaryMark(HttpRequest
* request
, HttpReply
const * reply
);
170 #endif /* SQUID_HTTP_H */