]> git.ipfire.org Git - thirdparty/squid.git/blob - src/http.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / http.h
1 /*
2 * Copyright (C) 1996-2017 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 HttpStateData(FwdState *);
27 ~HttpStateData();
28
29 static void httpBuildRequestHeader(HttpRequest * request,
30 StoreEntry * entry,
31 const AccessLogEntryPointer &al,
32 HttpHeader * hdr_out,
33 const Http::StateFlags &flags);
34
35 virtual const Comm::ConnectionPointer & dataConnection() const;
36 /* should be private */
37 bool sendRequest();
38 void processReplyHeader();
39 void processReplyBody();
40 void readReply(const CommIoCbParams &io);
41 virtual void maybeReadVirginBody(); // read response data from the network
42
43 // Determine whether the response is a cacheable representation
44 int cacheableReply();
45
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;
50 size_t read_sz;
51 SBuf inBuf; ///< I/O buffer for receiving server responses
52 bool ignoreCacheControl;
53 bool surrogateNoStore;
54
55 void processSurrogateControl(HttpReply *);
56
57 protected:
58 void processReply();
59 void proceedAfter1xx();
60 void handle1xx(HttpReply *msg);
61
62 private:
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;
69 AsyncCall::Pointer closeHandler;
70 enum ConnectionStatus {
71 INCOMPLETE_MSG,
72 COMPLETE_PERSISTENT_MSG,
73 COMPLETE_NONPERSISTENT_MSG
74 };
75 ConnectionStatus statusIfComplete() const;
76 ConnectionStatus persistentConnStatus() const;
77 void keepaliveAccounting(HttpReply *);
78 void checkDateSkew(HttpReply *);
79
80 bool continueAfterParsingHeader();
81 void truncateVirginBody();
82
83 virtual void start();
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;
90
91 void abortTransaction(const char *reason) { abortAll(reason); } // abnormal termination
92
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
104 // consuming request body
105 virtual void handleMoreRequestBodyAvailable();
106 virtual void handleRequestBodyProducerAborted();
107
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);
116 void sendComplete();
117 void httpStateConnClosed(const CommCloseCbParams &params);
118 void httpTimeout(const CommTimeoutCbParams &params);
119
120 mb_size_t buildRequestPrefix(MemBuf * mb);
121 static bool decideIfWeDoRanges (HttpRequest * orig_request);
122 bool peerSupportsConnectionPinning() const;
123
124 /// Parser being used at present to parse the HTTP/ICY server response.
125 Http1::ResponseParserPointer hp;
126 Http1::TeChunkedParser *httpChunkDecoder;
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;
132
133 /// Whether we received a Date header older than that of a matching
134 /// cached response.
135 bool sawDateGoBack;
136 };
137
138 int httpCachable(const HttpRequestMethod&);
139 void httpStart(FwdState *);
140 SBuf httpMakeVaryMark(HttpRequest * request, HttpReply const * reply);
141
142 #endif /* SQUID_HTTP_H */
143