2 * Copyright (C) 1996-2018 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
);
27 /// assists in making and relaying entry caching/sharing decision
31 enum Answers
{ reuseNot
= 0, cachePositively
, cacheNegatively
, doNotCacheButShare
};
33 ReuseDecision(const StoreEntry
*e
, const Http::StatusCode code
);
34 /// stores the corresponding decision
35 Answers
make(const Answers ans
, const char *why
);
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
43 HttpStateData(FwdState
*);
46 static void httpBuildRequestHeader(HttpRequest
* request
,
48 const AccessLogEntryPointer
&al
,
50 const Http::StateFlags
&flags
);
52 virtual const Comm::ConnectionPointer
& dataConnection() const;
53 /* should be private */
55 void processReplyHeader();
56 void processReplyBody();
57 void readReply(const CommIoCbParams
&io
);
58 virtual void maybeReadVirginBody(); // read response data from the network
60 // Checks whether the response is cacheable/shareable.
61 ReuseDecision::Answers
reusableReply(ReuseDecision
&decision
);
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 */
66 Http::StateFlags flags
;
68 SBuf inBuf
; ///< I/O buffer for receiving server responses
69 bool ignoreCacheControl
;
70 bool surrogateNoStore
;
72 void processSurrogateControl(HttpReply
*);
76 void proceedAfter1xx();
77 void handle1xx(HttpReply
*msg
);
81 * The current server connection.
82 * Maybe open, closed, or NULL.
83 * Use doneWithServer() to check if the server is available for use.
85 Comm::ConnectionPointer serverConnection
;
86 AsyncCall::Pointer closeHandler
;
87 enum ConnectionStatus
{
89 COMPLETE_PERSISTENT_MSG
,
90 COMPLETE_NONPERSISTENT_MSG
92 ConnectionStatus
statusIfComplete() const;
93 ConnectionStatus
persistentConnStatus() const;
94 void keepaliveAccounting(HttpReply
*);
95 void checkDateSkew(HttpReply
*);
97 bool continueAfterParsingHeader();
98 void truncateVirginBody();
100 virtual void start();
101 virtual void haveParsedReplyHeaders();
102 virtual bool getMoreRequestBody(MemBuf
&buf
);
103 virtual void closeServer(); // end communication with the server
104 virtual bool doneWithServer() const; // did we end communication?
105 virtual void abortAll(const char *reason
); // abnormal termination
106 virtual bool mayReadVirginReplyBody() const;
108 void abortTransaction(const char *reason
) { abortAll(reason
); } // abnormal termination
111 * determine if read buffer can have space made available
114 * \param grow whether to actually expand the buffer
116 * \return whether the buffer can be grown to provide space
117 * regardless of whether the grow actually happened.
119 bool maybeMakeSpaceAvailable(bool grow
);
121 // consuming request body
122 virtual void handleMoreRequestBodyAvailable();
123 virtual void handleRequestBodyProducerAborted();
125 void writeReplyBody();
126 bool decodeAndWriteReplyBody();
127 bool finishingBrokenPost();
128 bool finishingChunkedRequest();
129 void doneSendingRequestBody();
130 void requestBodyHandler(MemBuf
&);
131 virtual void sentRequestBody(const CommIoCbParams
&io
);
132 void wroteLast(const CommIoCbParams
&io
);
134 void httpStateConnClosed(const CommCloseCbParams
¶ms
);
135 void httpTimeout(const CommTimeoutCbParams
¶ms
);
137 mb_size_t
buildRequestPrefix(MemBuf
* mb
);
138 static bool decideIfWeDoRanges (HttpRequest
* orig_request
);
139 bool peerSupportsConnectionPinning() const;
141 /// Parser being used at present to parse the HTTP/ICY server response.
142 Http1::ResponseParserPointer hp
;
143 Http1::TeChunkedParser
*httpChunkDecoder
;
145 /// amount of message payload/body received so far.
147 /// positive when we read more than we wanted
148 int64_t payloadTruncated
;
150 /// Whether we received a Date header older than that of a matching
155 std::ostream
&operator <<(std::ostream
&os
, const HttpStateData::ReuseDecision
&d
);
157 int httpCachable(const HttpRequestMethod
&);
158 void httpStart(FwdState
*);
159 SBuf
httpMakeVaryMark(HttpRequest
* request
, HttpReply
const * reply
);
161 #endif /* SQUID_HTTP_H */