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