2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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.
12 #include "clients/Client.h"
14 #include "http/forward.h"
15 #include "http/StateFlags.h"
16 #include "sbuf/SBuf.h"
21 class HttpStateData
: public Client
23 CBDATA_CLASS(HttpStateData
);
26 HttpStateData(FwdState
*);
29 static void httpBuildRequestHeader(HttpRequest
* request
,
31 const AccessLogEntryPointer
&al
,
33 const Http::StateFlags
&flags
);
35 virtual const Comm::ConnectionPointer
& dataConnection() const;
36 /* should be private */
38 void processReplyHeader();
39 void processReplyBody();
40 void readReply(const CommIoCbParams
&io
);
41 virtual void maybeReadVirginBody(); // read response data from the network
43 // Determine whether the response is a cacheable representation
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 */
49 Http::StateFlags flags
;
51 SBuf inBuf
; ///< I/O buffer for receiving server responses
52 bool ignoreCacheControl
;
53 bool surrogateNoStore
;
55 void processSurrogateControl(HttpReply
*);
59 void proceedAfter1xx();
60 void handle1xx(HttpReply
*msg
);
64 * The current server connection.
65 * Maybe open, closed, or NULL.
66 * Use doneWithServer() to check if the server is available for use.
68 Comm::ConnectionPointer serverConnection
;
69 AsyncCall::Pointer closeHandler
;
70 enum ConnectionStatus
{
72 COMPLETE_PERSISTENT_MSG
,
73 COMPLETE_NONPERSISTENT_MSG
75 ConnectionStatus
statusIfComplete() const;
76 ConnectionStatus
persistentConnStatus() const;
77 void keepaliveAccounting(HttpReply
*);
78 void checkDateSkew(HttpReply
*);
80 bool continueAfterParsingHeader();
81 void truncateVirginBody();
84 virtual void haveParsedReplyHeaders();
85 virtual bool getMoreRequestBody(MemBuf
&buf
);
86 virtual void closeServer(); // end communication with the server
87 virtual bool doneWithServer() const; // did we end communication?
88 virtual void abortAll(const char *reason
); // abnormal termination
89 virtual bool mayReadVirginReplyBody() const;
91 void abortTransaction(const char *reason
) { abortAll(reason
); } // abnormal termination
94 * determine if read buffer can have space made available
97 * \param grow whether to actually expand the buffer
99 * \return whether the buffer can be grown to provide space
100 * regardless of whether the grow actually happened.
102 bool maybeMakeSpaceAvailable(bool grow
);
104 // consuming request body
105 virtual void handleMoreRequestBodyAvailable();
106 virtual void handleRequestBodyProducerAborted();
108 void writeReplyBody();
109 bool decodeAndWriteReplyBody();
110 bool finishingBrokenPost();
111 bool finishingChunkedRequest();
112 void doneSendingRequestBody();
113 void requestBodyHandler(MemBuf
&);
114 virtual void sentRequestBody(const CommIoCbParams
&io
);
115 void wroteLast(const CommIoCbParams
&io
);
117 void httpStateConnClosed(const CommCloseCbParams
¶ms
);
118 void httpTimeout(const CommTimeoutCbParams
¶ms
);
120 mb_size_t
buildRequestPrefix(MemBuf
* mb
);
121 static bool decideIfWeDoRanges (HttpRequest
* orig_request
);
122 bool peerSupportsConnectionPinning() const;
124 /// Parser being used at present to parse the HTTP/ICY server response.
125 Http1::ResponseParserPointer hp
;
126 Http1::TeChunkedParser
*httpChunkDecoder
;
128 /// amount of message payload/body received so far.
130 /// positive when we read more than we wanted
131 int64_t payloadTruncated
;
133 /// Whether we received a Date header older than that of a matching
138 int httpCachable(const HttpRequestMethod
&);
139 void httpStart(FwdState
*);
140 SBuf
httpMakeVaryMark(HttpRequest
* request
, HttpReply
const * reply
);
142 #endif /* SQUID_HTTP_H */