2 * Copyright (C) 1996-2015 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 "HttpStateFlags.h"
16 class ChunkedCodingParser
;
20 class HttpStateData
: public Client
22 CBDATA_CLASS(HttpStateData
);
25 HttpStateData(FwdState
*);
28 static void httpBuildRequestHeader(HttpRequest
* request
,
30 const AccessLogEntryPointer
&al
,
32 const HttpStateFlags
&flags
);
34 virtual const Comm::ConnectionPointer
& dataConnection() const;
35 /* should be private */
37 void processReplyHeader();
38 void processReplyBody();
39 void readReply(const CommIoCbParams
&io
);
40 virtual void maybeReadVirginBody(); // read response data from the network
42 // Determine whether the response is a cacheable representation
45 CachePeer
*_peer
; /* CachePeer request made to */
46 int eof
; /* reached end-of-object? */
47 int lastChunk
; /* reached last chunk of a chunk-encoded reply */
50 SBuf inBuf
; ///< I/O buffer for receiving server responses
51 bool ignoreCacheControl
;
52 bool surrogateNoStore
;
54 void processSurrogateControl(HttpReply
*);
58 void proceedAfter1xx();
59 void handle1xx(HttpReply
*msg
);
63 * The current server connection.
64 * Maybe open, closed, or NULL.
65 * Use doneWithServer() to check if the server is available for use.
67 Comm::ConnectionPointer serverConnection
;
68 AsyncCall::Pointer closeHandler
;
69 enum ConnectionStatus
{
71 COMPLETE_PERSISTENT_MSG
,
72 COMPLETE_NONPERSISTENT_MSG
74 ConnectionStatus
statusIfComplete() const;
75 ConnectionStatus
persistentConnStatus() const;
76 void keepaliveAccounting(HttpReply
*);
77 void checkDateSkew(HttpReply
*);
79 bool continueAfterParsingHeader();
80 void truncateVirginBody();
83 virtual void haveParsedReplyHeaders();
84 virtual bool getMoreRequestBody(MemBuf
&buf
);
85 virtual void closeServer(); // end communication with the server
86 virtual bool doneWithServer() const; // did we end communication?
87 virtual void abortTransaction(const char *reason
); // abnormal termination
88 virtual bool mayReadVirginReplyBody() const;
91 * determine if read buffer can have space made available
94 * \param grow whether to actually expand the buffer
96 * \return whether the buffer can be grown to provide space
97 * regardless of whether the grow actually happened.
99 bool maybeMakeSpaceAvailable(bool grow
);
101 // consuming request body
102 virtual void handleMoreRequestBodyAvailable();
103 virtual void handleRequestBodyProducerAborted();
105 void writeReplyBody();
106 bool decodeAndWriteReplyBody();
107 bool finishingBrokenPost();
108 bool finishingChunkedRequest();
109 void doneSendingRequestBody();
110 void requestBodyHandler(MemBuf
&);
111 virtual void sentRequestBody(const CommIoCbParams
&io
);
112 void wroteLast(const CommIoCbParams
&io
);
114 void httpStateConnClosed(const CommCloseCbParams
¶ms
);
115 void httpTimeout(const CommTimeoutCbParams
¶ms
);
117 mb_size_t
buildRequestPrefix(MemBuf
* mb
);
118 static bool decideIfWeDoRanges (HttpRequest
* orig_request
);
119 bool peerSupportsConnectionPinning() const;
121 /// Parser being used at present to parse the HTTP/ICY server response.
122 Http1::ResponseParserPointer hp
;
123 ChunkedCodingParser
*httpChunkDecoder
;
125 /// amount of message payload/body received so far.
127 /// positive when we read more than we wanted
128 int64_t payloadTruncated
;
131 int httpCachable(const HttpRequestMethod
&);
132 void httpStart(FwdState
*);
133 const char *httpMakeVaryMark(HttpRequest
* request
, HttpReply
const * reply
);
135 #endif /* SQUID_HTTP_H */