]> git.ipfire.org Git - thirdparty/squid.git/blame - src/http.h
Collapse internal revalidation requests (SMP-unaware caches), again.
[thirdparty/squid.git] / src / http.h
CommitLineData
e6ccf245 1/*
4ac4a490 2 * Copyright (C) 1996-2017 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;
e6ccf245 20
fccd4a86 21class HttpStateData : public Client
62e76326 22{
5c2f68b7 23 CBDATA_CLASS(HttpStateData);
62e76326 24
25public:
39fe14b2
EB
26
27 /// assists in making and relaying entry caching/sharing decision
28 class ReuseDecision
29 {
30 public:
31 enum Answers { reuseNot = 0, cachePositively, cacheNegatively, doNotCacheButShare };
32
33 ReuseDecision(const StoreEntry *e, const Http::StatusCode code);
34 /// stores the corresponding decision
35 Answers make(const Answers ans, const char *why);
36
37 Answers answer; ///< the decision id
38 const char *reason; ///< the decision reason
39 const StoreEntry *entry; ///< entry for debugging
40 const Http::StatusCode statusCode; ///< HTTP status for debugging
41 };
42
11913361 43 HttpStateData(FwdState *);
2afaba07 44 ~HttpStateData();
45
99d4c5e0 46 static void httpBuildRequestHeader(HttpRequest * request,
99d4c5e0 47 StoreEntry * entry,
4bf68cfa 48 const AccessLogEntryPointer &al,
99d4c5e0 49 HttpHeader * hdr_out,
bad9c5e4 50 const Http::StateFlags &flags);
5f8252d2 51
e83cc785 52 virtual const Comm::ConnectionPointer & dataConnection() const;
4eb368f9 53 /* should be private */
5f8252d2 54 bool sendRequest();
2afaba07 55 void processReplyHeader();
56 void processReplyBody();
dc56a9b1 57 void readReply(const CommIoCbParams &io);
5f8252d2 58 virtual void maybeReadVirginBody(); // read response data from the network
2b59002c 59
39fe14b2
EB
60 // Checks whether the response is cacheable/shareable.
61 ReuseDecision::Answers reusableReply(ReuseDecision &decision);
2afaba07 62
f53969cc
SM
63 CachePeer *_peer; /* CachePeer request made to */
64 int eof; /* reached end-of-object? */
65 int lastChunk; /* reached last chunk of a chunk-encoded reply */
bad9c5e4 66 Http::StateFlags flags;
c4b7a5a9 67 size_t read_sz;
395a814a 68 SBuf inBuf; ///< I/O buffer for receiving server responses
43ae1d95 69 bool ignoreCacheControl;
70 bool surrogateNoStore;
5f8252d2 71
43ae1d95 72 void processSurrogateControl(HttpReply *);
2afaba07 73
7c4e4e7f 74protected:
655daa06
AR
75 void processReply();
76 void proceedAfter1xx();
77 void handle1xx(HttpReply *msg);
78
528b2c61 79private:
8d71285d
AJ
80 /**
81 * The current server connection.
82 * Maybe open, closed, or NULL.
83 * Use doneWithServer() to check if the server is available for use.
84 */
85 Comm::ConnectionPointer serverConnection;
dc56a9b1 86 AsyncCall::Pointer closeHandler;
528b2c61 87 enum ConnectionStatus {
62e76326 88 INCOMPLETE_MSG,
89 COMPLETE_PERSISTENT_MSG,
90 COMPLETE_NONPERSISTENT_MSG
528b2c61 91 };
92 ConnectionStatus statusIfComplete() const;
93 ConnectionStatus persistentConnStatus() const;
2afaba07 94 void keepaliveAccounting(HttpReply *);
95 void checkDateSkew(HttpReply *);
5f8252d2 96
ba82c452 97 bool continueAfterParsingHeader();
821beb5e 98 void truncateVirginBody();
ba82c452 99
79628299 100 virtual void start();
5f8252d2 101 virtual void haveParsedReplyHeaders();
39cb8c41 102 virtual bool getMoreRequestBody(MemBuf &buf);
5f8252d2 103 virtual void closeServer(); // end communication with the server
104 virtual bool doneWithServer() const; // did we end communication?
92cfc72f 105 virtual void abortAll(const char *reason); // abnormal termination
aea65fec 106 virtual bool mayReadVirginReplyBody() const;
5f8252d2 107
92cfc72f
CT
108 void abortTransaction(const char *reason) { abortAll(reason); } // abnormal termination
109
1ad68518
AJ
110 /**
111 * determine if read buffer can have space made available
112 * for a read.
113 *
114 * \param grow whether to actually expand the buffer
115 *
116 * \return whether the buffer can be grown to provide space
117 * regardless of whether the grow actually happened.
118 */
119 bool maybeMakeSpaceAvailable(bool grow);
120
5f8252d2 121 // consuming request body
122 virtual void handleMoreRequestBodyAvailable();
123 virtual void handleRequestBodyProducerAborted();
124
125 void writeReplyBody();
af0bb8e5 126 bool decodeAndWriteReplyBody();
39cb8c41
AR
127 bool finishingBrokenPost();
128 bool finishingChunkedRequest();
5f8252d2 129 void doneSendingRequestBody();
3b299123 130 void requestBodyHandler(MemBuf &);
dc56a9b1 131 virtual void sentRequestBody(const CommIoCbParams &io);
39cb8c41
AR
132 void wroteLast(const CommIoCbParams &io);
133 void sendComplete();
dc56a9b1 134 void httpStateConnClosed(const CommCloseCbParams &params);
135 void httpTimeout(const CommTimeoutCbParams &params);
136
e24f13cd 137 mb_size_t buildRequestPrefix(MemBuf * mb);
99d4c5e0 138 static bool decideIfWeDoRanges (HttpRequest * orig_request);
d67acb4e 139 bool peerSupportsConnectionPinning() const;
2afaba07 140
f542211b
AJ
141 /// Parser being used at present to parse the HTTP/ICY server response.
142 Http1::ResponseParserPointer hp;
db1720f8 143 Http1::TeChunkedParser *httpChunkDecoder;
8e100780
AJ
144
145 /// amount of message payload/body received so far.
146 int64_t payloadSeen;
147 /// positive when we read more than we wanted
148 int64_t payloadTruncated;
eace013e
EB
149
150 /// Whether we received a Date header older than that of a matching
151 /// cached response.
152 bool sawDateGoBack;
e6ccf245 153};
154
39fe14b2
EB
155std::ostream &operator <<(std::ostream &os, const HttpStateData::ReuseDecision &d);
156
8a648e8d
FC
157int httpCachable(const HttpRequestMethod&);
158void httpStart(FwdState *);
90ab8f20 159SBuf httpMakeVaryMark(HttpRequest * request, HttpReply const * reply);
fc54b8d2 160
e6ccf245 161#endif /* SQUID_HTTP_H */
f53969cc 162