]> git.ipfire.org Git - thirdparty/squid.git/blame - src/http.h
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / http.h
CommitLineData
e6ccf245 1/*
f70aedc4 2 * Copyright (C) 1996-2021 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 18class FwdState;
c6983ec7 19class HttpHeader;
1c2b4465 20class String;
e6ccf245 21
fccd4a86 22class HttpStateData : public Client
62e76326 23{
5c2f68b7 24 CBDATA_CLASS(HttpStateData);
62e76326 25
26public:
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 *);
2afaba07 45 ~HttpStateData();
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
e83cc785 53 virtual const Comm::ConnectionPointer & dataConnection() const;
4eb368f9 54 /* should be private */
5f8252d2 55 bool sendRequest();
2afaba07 56 void processReplyHeader();
57 void processReplyBody();
dc56a9b1 58 void readReply(const CommIoCbParams &io);
5f8252d2 59 virtual void maybeReadVirginBody(); // 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
f53969cc
SM
64 CachePeer *_peer; /* CachePeer request made to */
65 int eof; /* reached end-of-object? */
66 int lastChunk; /* reached last chunk of a chunk-encoded reply */
bad9c5e4 67 Http::StateFlags flags;
c4b7a5a9 68 size_t read_sz;
395a814a 69 SBuf inBuf; ///< I/O buffer for receiving server responses
43ae1d95 70 bool ignoreCacheControl;
71 bool surrogateNoStore;
5f8252d2 72
1c2b4465
CT
73 /// Upgrade header value sent to the origin server or cache peer.
74 String *upgradeHeaderOut = nullptr;
75
43ae1d95 76 void processSurrogateControl(HttpReply *);
2afaba07 77
7c4e4e7f 78protected:
655daa06
AR
79 void processReply();
80 void proceedAfter1xx();
81 void handle1xx(HttpReply *msg);
1c2b4465 82 void drop1xx(const char *reason);
655daa06 83
528b2c61 84private:
8d71285d
AJ
85 /**
86 * The current server connection.
87 * Maybe open, closed, or NULL.
88 * Use doneWithServer() to check if the server is available for use.
89 */
90 Comm::ConnectionPointer serverConnection;
dc56a9b1 91 AsyncCall::Pointer closeHandler;
528b2c61 92 enum ConnectionStatus {
62e76326 93 INCOMPLETE_MSG,
94 COMPLETE_PERSISTENT_MSG,
95 COMPLETE_NONPERSISTENT_MSG
528b2c61 96 };
97 ConnectionStatus statusIfComplete() const;
98 ConnectionStatus persistentConnStatus() const;
2afaba07 99 void keepaliveAccounting(HttpReply *);
100 void checkDateSkew(HttpReply *);
5f8252d2 101
ba82c452 102 bool continueAfterParsingHeader();
821beb5e 103 void truncateVirginBody();
ba82c452 104
79628299 105 virtual void start();
5f8252d2 106 virtual void haveParsedReplyHeaders();
39cb8c41 107 virtual bool getMoreRequestBody(MemBuf &buf);
5f8252d2 108 virtual void closeServer(); // end communication with the server
109 virtual bool doneWithServer() const; // did we end communication?
92cfc72f 110 virtual void abortAll(const char *reason); // abnormal termination
aea65fec 111 virtual bool mayReadVirginReplyBody() const;
5f8252d2 112
92cfc72f
CT
113 void abortTransaction(const char *reason) { abortAll(reason); } // abnormal termination
114
1ad68518
AJ
115 /**
116 * determine if read buffer can have space made available
117 * for a read.
118 *
119 * \param grow whether to actually expand the buffer
120 *
121 * \return whether the buffer can be grown to provide space
122 * regardless of whether the grow actually happened.
123 */
124 bool maybeMakeSpaceAvailable(bool grow);
125
5f8252d2 126 // consuming request body
127 virtual void handleMoreRequestBodyAvailable();
128 virtual void handleRequestBodyProducerAborted();
129
130 void writeReplyBody();
af0bb8e5 131 bool decodeAndWriteReplyBody();
39cb8c41
AR
132 bool finishingBrokenPost();
133 bool finishingChunkedRequest();
5f8252d2 134 void doneSendingRequestBody();
3b299123 135 void requestBodyHandler(MemBuf &);
dc56a9b1 136 virtual void sentRequestBody(const CommIoCbParams &io);
39cb8c41
AR
137 void wroteLast(const CommIoCbParams &io);
138 void sendComplete();
dc56a9b1 139 void httpStateConnClosed(const CommCloseCbParams &params);
140 void httpTimeout(const CommTimeoutCbParams &params);
141
e24f13cd 142 mb_size_t buildRequestPrefix(MemBuf * mb);
1c2b4465 143 void forwardUpgrade(HttpHeader&);
99d4c5e0 144 static bool decideIfWeDoRanges (HttpRequest * orig_request);
d67acb4e 145 bool peerSupportsConnectionPinning() const;
1c2b4465 146 const char *blockSwitchingProtocols(const HttpReply&) const;
2afaba07 147
f542211b
AJ
148 /// Parser being used at present to parse the HTTP/ICY server response.
149 Http1::ResponseParserPointer hp;
db1720f8 150 Http1::TeChunkedParser *httpChunkDecoder;
8e100780
AJ
151
152 /// amount of message payload/body received so far.
153 int64_t payloadSeen;
154 /// positive when we read more than we wanted
155 int64_t payloadTruncated;
eace013e
EB
156
157 /// Whether we received a Date header older than that of a matching
158 /// cached response.
159 bool sawDateGoBack;
e6ccf245 160};
161
39fe14b2
EB
162std::ostream &operator <<(std::ostream &os, const HttpStateData::ReuseDecision &d);
163
8a648e8d
FC
164int httpCachable(const HttpRequestMethod&);
165void httpStart(FwdState *);
90ab8f20 166SBuf httpMakeVaryMark(HttpRequest * request, HttpReply const * reply);
fc54b8d2 167
e6ccf245 168#endif /* SQUID_HTTP_H */
f53969cc 169