]> git.ipfire.org Git - thirdparty/squid.git/blob - src/http.h
Merged from trunk
[thirdparty/squid.git] / src / http.h
1 /*
2 * Copyright (C) 1996-2015 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 abortTransaction(const char *reason); // abnormal termination
88 virtual bool mayReadVirginReplyBody() const;
89
90 /**
91 * determine if read buffer can have space made available
92 * for a read.
93 *
94 * \param grow whether to actually expand the buffer
95 *
96 * \return whether the buffer can be grown to provide space
97 * regardless of whether the grow actually happened.
98 */
99 bool maybeMakeSpaceAvailable(bool grow);
100
101 // consuming request body
102 virtual void handleMoreRequestBodyAvailable();
103 virtual void handleRequestBodyProducerAborted();
104
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);
113 void sendComplete();
114 void httpStateConnClosed(const CommCloseCbParams &params);
115 void httpTimeout(const CommTimeoutCbParams &params);
116
117 mb_size_t buildRequestPrefix(MemBuf * mb);
118 static bool decideIfWeDoRanges (HttpRequest * orig_request);
119 bool peerSupportsConnectionPinning() const;
120
121 /// Parser being used at present to parse the HTTP/ICY server response.
122 Http1::ResponseParserPointer hp;
123 Http1::TeChunkedParser *httpChunkDecoder;
124
125 /// amount of message payload/body received so far.
126 int64_t payloadSeen;
127 /// positive when we read more than we wanted
128 int64_t payloadTruncated;
129 };
130
131 int httpCachable(const HttpRequestMethod&);
132 void httpStart(FwdState *);
133 const char *httpMakeVaryMark(HttpRequest * request, HttpReply const * reply);
134
135 #endif /* SQUID_HTTP_H */
136