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