]> git.ipfire.org Git - thirdparty/squid.git/blob - src/http.h
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / http.h
1 /*
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 #ifndef SQUID_HTTP_H
10 #define SQUID_HTTP_H
11
12 #include "clients/Client.h"
13 #include "comm.h"
14 #include "http/forward.h"
15 #include "http/StateFlags.h"
16 #include "sbuf/SBuf.h"
17
18 class FwdState;
19 class HttpHeader;
20
21 class HttpStateData : public Client
22 {
23 CBDATA_CLASS(HttpStateData);
24
25 public:
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
43 HttpStateData(FwdState *);
44 ~HttpStateData();
45
46 static void httpBuildRequestHeader(HttpRequest * request,
47 StoreEntry * entry,
48 const AccessLogEntryPointer &al,
49 HttpHeader * hdr_out,
50 const Http::StateFlags &flags);
51
52 virtual const Comm::ConnectionPointer & dataConnection() const;
53 /* should be private */
54 bool sendRequest();
55 void processReplyHeader();
56 void processReplyBody();
57 void readReply(const CommIoCbParams &io);
58 virtual void maybeReadVirginBody(); // read response data from the network
59
60 // Checks whether the response is cacheable/shareable.
61 ReuseDecision::Answers reusableReply(ReuseDecision &decision);
62
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;
67 size_t read_sz;
68 SBuf inBuf; ///< I/O buffer for receiving server responses
69 bool ignoreCacheControl;
70 bool surrogateNoStore;
71
72 void processSurrogateControl(HttpReply *);
73
74 protected:
75 void processReply();
76 void proceedAfter1xx();
77 void handle1xx(HttpReply *msg);
78
79 private:
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;
86 AsyncCall::Pointer closeHandler;
87 enum ConnectionStatus {
88 INCOMPLETE_MSG,
89 COMPLETE_PERSISTENT_MSG,
90 COMPLETE_NONPERSISTENT_MSG
91 };
92 ConnectionStatus statusIfComplete() const;
93 ConnectionStatus persistentConnStatus() const;
94 void keepaliveAccounting(HttpReply *);
95 void checkDateSkew(HttpReply *);
96
97 bool continueAfterParsingHeader();
98 void truncateVirginBody();
99
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;
107
108 void abortTransaction(const char *reason) { abortAll(reason); } // abnormal termination
109
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
121 // consuming request body
122 virtual void handleMoreRequestBodyAvailable();
123 virtual void handleRequestBodyProducerAborted();
124
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);
133 void sendComplete();
134 void httpStateConnClosed(const CommCloseCbParams &params);
135 void httpTimeout(const CommTimeoutCbParams &params);
136
137 mb_size_t buildRequestPrefix(MemBuf * mb);
138 static bool decideIfWeDoRanges (HttpRequest * orig_request);
139 bool peerSupportsConnectionPinning() const;
140
141 /// Parser being used at present to parse the HTTP/ICY server response.
142 Http1::ResponseParserPointer hp;
143 Http1::TeChunkedParser *httpChunkDecoder;
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;
149
150 /// Whether we received a Date header older than that of a matching
151 /// cached response.
152 bool sawDateGoBack;
153 };
154
155 std::ostream &operator <<(std::ostream &os, const HttpStateData::ReuseDecision &d);
156
157 int httpCachable(const HttpRequestMethod&);
158 void httpStart(FwdState *);
159 SBuf httpMakeVaryMark(HttpRequest * request, HttpReply const * reply);
160
161 #endif /* SQUID_HTTP_H */
162