]> git.ipfire.org Git - thirdparty/squid.git/blob - src/http.h
merge from trunk r14590
[thirdparty/squid.git] / src / http.h
1 /*
2 * Copyright (C) 1996-2016 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 "HttpStateFlags.h"
16
17 class FwdState;
18 class HttpHeader;
19
20 class HttpStateData : public Client
21 {
22 CBDATA_CLASS(HttpStateData);
23
24 public:
25 HttpStateData(FwdState *);
26 ~HttpStateData();
27
28 static void httpBuildRequestHeader(HttpRequest * request,
29 StoreEntry * entry,
30 const AccessLogEntryPointer &al,
31 HttpHeader * hdr_out,
32 const HttpStateFlags &flags);
33
34 virtual const Comm::ConnectionPointer & dataConnection() const;
35 /* should be private */
36 bool sendRequest();
37 void processReplyHeader();
38 void processReplyBody();
39 void readReply(const CommIoCbParams &io);
40 virtual void maybeReadVirginBody(); // read response data from the network
41
42 // Determine whether the response is a cacheable representation
43 int cacheableReply();
44
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 */
48 HttpStateFlags flags;
49 size_t read_sz;
50 SBuf inBuf; ///< I/O buffer for receiving server responses
51 bool ignoreCacheControl;
52 bool surrogateNoStore;
53
54 void processSurrogateControl(HttpReply *);
55
56 protected:
57 void processReply();
58 void proceedAfter1xx();
59 void handle1xx(HttpReply *msg);
60
61 private:
62 /**
63 * The current server connection.
64 * Maybe open, closed, or NULL.
65 * Use doneWithServer() to check if the server is available for use.
66 */
67 Comm::ConnectionPointer serverConnection;
68 AsyncCall::Pointer closeHandler;
69 enum ConnectionStatus {
70 INCOMPLETE_MSG,
71 COMPLETE_PERSISTENT_MSG,
72 COMPLETE_NONPERSISTENT_MSG
73 };
74 ConnectionStatus statusIfComplete() const;
75 ConnectionStatus persistentConnStatus() const;
76 void keepaliveAccounting(HttpReply *);
77 void checkDateSkew(HttpReply *);
78
79 bool continueAfterParsingHeader();
80 void truncateVirginBody();
81
82 virtual void start();
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 abortAll(const char *reason); // abnormal termination
88 virtual bool mayReadVirginReplyBody() const;
89
90 void abortTransaction(const char *reason) { abortAll(reason); } // abnormal termination
91
92 /**
93 * determine if read buffer can have space made available
94 * for a read.
95 *
96 * \param grow whether to actually expand the buffer
97 *
98 * \return whether the buffer can be grown to provide space
99 * regardless of whether the grow actually happened.
100 */
101 bool maybeMakeSpaceAvailable(bool grow);
102
103 // consuming request body
104 virtual void handleMoreRequestBodyAvailable();
105 virtual void handleRequestBodyProducerAborted();
106
107 void writeReplyBody();
108 bool decodeAndWriteReplyBody();
109 bool finishingBrokenPost();
110 bool finishingChunkedRequest();
111 void doneSendingRequestBody();
112 void requestBodyHandler(MemBuf &);
113 virtual void sentRequestBody(const CommIoCbParams &io);
114 void wroteLast(const CommIoCbParams &io);
115 void sendComplete();
116 void httpStateConnClosed(const CommCloseCbParams &params);
117 void httpTimeout(const CommTimeoutCbParams &params);
118
119 mb_size_t buildRequestPrefix(MemBuf * mb);
120 static bool decideIfWeDoRanges (HttpRequest * orig_request);
121 bool peerSupportsConnectionPinning() const;
122
123 /// Parser being used at present to parse the HTTP/ICY server response.
124 Http1::ResponseParserPointer hp;
125 Http1::TeChunkedParser *httpChunkDecoder;
126
127 /// amount of message payload/body received so far.
128 int64_t payloadSeen;
129 /// positive when we read more than we wanted
130 int64_t payloadTruncated;
131 };
132
133 int httpCachable(const HttpRequestMethod&);
134 void httpStart(FwdState *);
135 const char *httpMakeVaryMark(HttpRequest * request, HttpReply const * reply);
136
137 #endif /* SQUID_HTTP_H */
138