]>
Commit | Line | Data |
---|---|---|
e6ccf245 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
e6ccf245 | 3 | * |
bbc27441 AJ |
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. | |
e6ccf245 | 7 | */ |
8 | ||
ff9d9458 FC |
9 | #ifndef SQUID_SRC_HTTP_H |
10 | #define SQUID_SRC_HTTP_H | |
e6ccf245 | 11 | |
fccd4a86 | 12 | #include "clients/Client.h" |
c4b7a5a9 | 13 | #include "comm.h" |
51c3e7f0 | 14 | #include "http/forward.h" |
bad9c5e4 | 15 | #include "http/StateFlags.h" |
90ab8f20 | 16 | #include "sbuf/SBuf.h" |
314782d4 | 17 | |
50c5af88 AR |
18 | #include <optional> |
19 | ||
314782d4 | 20 | class FwdState; |
c6983ec7 | 21 | class HttpHeader; |
1c2b4465 | 22 | class String; |
e6ccf245 | 23 | |
fccd4a86 | 24 | class HttpStateData : public Client |
62e76326 | 25 | { |
337b9aa4 | 26 | CBDATA_CHILD(HttpStateData); |
62e76326 | 27 | |
28 | public: | |
39fe14b2 EB |
29 | |
30 | /// assists in making and relaying entry caching/sharing decision | |
31 | class ReuseDecision | |
32 | { | |
33 | public: | |
34 | enum Answers { reuseNot = 0, cachePositively, cacheNegatively, doNotCacheButShare }; | |
35 | ||
36 | ReuseDecision(const StoreEntry *e, const Http::StatusCode code); | |
37 | /// stores the corresponding decision | |
38 | Answers make(const Answers ans, const char *why); | |
39 | ||
40 | Answers answer; ///< the decision id | |
41 | const char *reason; ///< the decision reason | |
42 | const StoreEntry *entry; ///< entry for debugging | |
43 | const Http::StatusCode statusCode; ///< HTTP status for debugging | |
44 | }; | |
45 | ||
11913361 | 46 | HttpStateData(FwdState *); |
337b9aa4 | 47 | ~HttpStateData() override; |
2afaba07 | 48 | |
99d4c5e0 | 49 | static void httpBuildRequestHeader(HttpRequest * request, |
99d4c5e0 | 50 | StoreEntry * entry, |
4bf68cfa | 51 | const AccessLogEntryPointer &al, |
99d4c5e0 | 52 | HttpHeader * hdr_out, |
bad9c5e4 | 53 | const Http::StateFlags &flags); |
5f8252d2 | 54 | |
337b9aa4 | 55 | const Comm::ConnectionPointer & dataConnection() const override; |
4eb368f9 | 56 | /* should be private */ |
5f8252d2 | 57 | bool sendRequest(); |
2afaba07 | 58 | void processReplyHeader(); |
337b9aa4 | 59 | void processReplyBody() override; |
dc56a9b1 | 60 | void readReply(const CommIoCbParams &io); |
337b9aa4 | 61 | void maybeReadVirginBody() override; // read response data from the network |
2b59002c | 62 | |
39fe14b2 EB |
63 | // Checks whether the response is cacheable/shareable. |
64 | ReuseDecision::Answers reusableReply(ReuseDecision &decision); | |
2afaba07 | 65 | |
c31f43b9 FC |
66 | CachePeer *_peer = nullptr; /* CachePeer request made to */ |
67 | int eof = 0; /* reached end-of-object? */ | |
68 | int lastChunk = 0; /* reached last chunk of a chunk-encoded reply */ | |
bad9c5e4 | 69 | Http::StateFlags flags; |
395a814a | 70 | SBuf inBuf; ///< I/O buffer for receiving server responses |
c31f43b9 FC |
71 | bool ignoreCacheControl = false; |
72 | bool surrogateNoStore = false; | |
5f8252d2 | 73 | |
1c2b4465 CT |
74 | /// Upgrade header value sent to the origin server or cache peer. |
75 | String *upgradeHeaderOut = nullptr; | |
76 | ||
43ae1d95 | 77 | void processSurrogateControl(HttpReply *); |
2afaba07 | 78 | |
7c4e4e7f | 79 | protected: |
a928fdfd | 80 | /* Client API */ |
337b9aa4 | 81 | void noteDelayAwareReadChance() override; |
a928fdfd | 82 | |
655daa06 AR |
83 | void processReply(); |
84 | void proceedAfter1xx(); | |
80a6a08a | 85 | void handle1xx(const HttpReplyPointer &); |
1c2b4465 | 86 | void drop1xx(const char *reason); |
655daa06 | 87 | |
528b2c61 | 88 | private: |
8d71285d AJ |
89 | /** |
90 | * The current server connection. | |
91 | * Maybe open, closed, or NULL. | |
92 | * Use doneWithServer() to check if the server is available for use. | |
93 | */ | |
94 | Comm::ConnectionPointer serverConnection; | |
dc56a9b1 | 95 | AsyncCall::Pointer closeHandler; |
528b2c61 | 96 | enum ConnectionStatus { |
62e76326 | 97 | INCOMPLETE_MSG, |
98 | COMPLETE_PERSISTENT_MSG, | |
99 | COMPLETE_NONPERSISTENT_MSG | |
528b2c61 | 100 | }; |
101 | ConnectionStatus statusIfComplete() const; | |
102 | ConnectionStatus persistentConnStatus() const; | |
2afaba07 | 103 | void keepaliveAccounting(HttpReply *); |
104 | void checkDateSkew(HttpReply *); | |
5f8252d2 | 105 | |
ba82c452 | 106 | bool continueAfterParsingHeader(); |
821beb5e | 107 | void truncateVirginBody(); |
ba82c452 | 108 | |
337b9aa4 AR |
109 | void start() override; |
110 | void haveParsedReplyHeaders() override; | |
111 | bool getMoreRequestBody(MemBuf &buf) override; | |
112 | void closeServer() override; // end communication with the server | |
113 | bool doneWithServer() const override; // did we end communication? | |
114 | void abortAll(const char *reason) override; // abnormal termination | |
115 | bool mayReadVirginReplyBody() const override; | |
5f8252d2 | 116 | |
92cfc72f CT |
117 | void abortTransaction(const char *reason) { abortAll(reason); } // abnormal termination |
118 | ||
50c5af88 AR |
119 | size_t calcReadBufferCapacityLimit() const; |
120 | std::optional<size_t> canBufferMoreReplyBytes() const; | |
121 | size_t maybeMakeSpaceAvailable(size_t maxReadSize); | |
1ad68518 | 122 | |
5f8252d2 | 123 | // consuming request body |
124 | virtual void handleMoreRequestBodyAvailable(); | |
337b9aa4 | 125 | void handleRequestBodyProducerAborted() override; |
5f8252d2 | 126 | |
127 | void writeReplyBody(); | |
af0bb8e5 | 128 | bool decodeAndWriteReplyBody(); |
39cb8c41 AR |
129 | bool finishingBrokenPost(); |
130 | bool finishingChunkedRequest(); | |
337b9aa4 | 131 | void doneSendingRequestBody() override; |
3b299123 | 132 | void requestBodyHandler(MemBuf &); |
337b9aa4 | 133 | void sentRequestBody(const CommIoCbParams &io) override; |
39cb8c41 AR |
134 | void wroteLast(const CommIoCbParams &io); |
135 | void sendComplete(); | |
dc56a9b1 | 136 | void httpStateConnClosed(const CommCloseCbParams ¶ms); |
137 | void httpTimeout(const CommTimeoutCbParams ¶ms); | |
21f90159 | 138 | void markPrematureReplyBodyEofFailure(); |
dc56a9b1 | 139 | |
e24f13cd | 140 | mb_size_t buildRequestPrefix(MemBuf * mb); |
1c2b4465 | 141 | void forwardUpgrade(HttpHeader&); |
99d4c5e0 | 142 | static bool decideIfWeDoRanges (HttpRequest * orig_request); |
d67acb4e | 143 | bool peerSupportsConnectionPinning() const; |
1c2b4465 | 144 | const char *blockSwitchingProtocols(const HttpReply&) const; |
2afaba07 | 145 | |
f542211b AJ |
146 | /// Parser being used at present to parse the HTTP/ICY server response. |
147 | Http1::ResponseParserPointer hp; | |
c31f43b9 | 148 | Http1::TeChunkedParser *httpChunkDecoder = nullptr; |
8e100780 AJ |
149 | |
150 | /// amount of message payload/body received so far. | |
c31f43b9 | 151 | int64_t payloadSeen = 0; |
8e100780 | 152 | /// positive when we read more than we wanted |
c31f43b9 | 153 | int64_t payloadTruncated = 0; |
eace013e EB |
154 | |
155 | /// Whether we received a Date header older than that of a matching | |
156 | /// cached response. | |
c31f43b9 | 157 | bool sawDateGoBack = false; |
e6ccf245 | 158 | }; |
159 | ||
39fe14b2 EB |
160 | std::ostream &operator <<(std::ostream &os, const HttpStateData::ReuseDecision &d); |
161 | ||
8a648e8d FC |
162 | int httpCachable(const HttpRequestMethod&); |
163 | void httpStart(FwdState *); | |
90ab8f20 | 164 | SBuf httpMakeVaryMark(HttpRequest * request, HttpReply const * reply); |
fc54b8d2 | 165 | |
ff9d9458 | 166 | #endif /* SQUID_SRC_HTTP_H */ |
f53969cc | 167 |