]> git.ipfire.org Git - thirdparty/squid.git/blob - src/http.h
Fixes and polishing in response to Amos' squid-dev review dated 2014/08/10.
[thirdparty/squid.git] / src / http.h
1
2 /*
3 *
4 * SQUID Web Proxy Cache http://www.squid-cache.org/
5 * ----------------------------------------------------------
6 *
7 * Squid is the result of efforts by numerous individuals from
8 * the Internet community; see the CONTRIBUTORS file for full
9 * details. Many organizations have provided support for Squid's
10 * development; see the SPONSORS file for full details. Squid is
11 * Copyrighted (C) 2001 by the Regents of the University of
12 * California; see the COPYRIGHT file for full details. Squid
13 * incorporates software developed and/or copyrighted by other
14 * sources; see the CREDITS file for full details.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
29 *
30 */
31
32 #ifndef SQUID_HTTP_H
33 #define SQUID_HTTP_H
34
35 #include "comm.h"
36 #include "HttpStateFlags.h"
37 #include "Server.h"
38
39 class ChunkedCodingParser;
40 class FwdState;
41 class HttpHeader;
42
43 class HttpStateData : public ServerStateData
44 {
45
46 public:
47 HttpStateData(FwdState *);
48 ~HttpStateData();
49
50 static void httpBuildRequestHeader(HttpRequest * request,
51 StoreEntry * entry,
52 const AccessLogEntryPointer &al,
53 HttpHeader * hdr_out,
54 const HttpStateFlags &flags);
55
56 virtual const Comm::ConnectionPointer & dataConnection() const;
57 /* should be private */
58 bool sendRequest();
59 void processReplyHeader();
60 void processReplyBody();
61 void readReply(const CommIoCbParams &io);
62 virtual void maybeReadVirginBody(); // read response data from the network
63
64 // Determine whether the response is a cacheable representation
65 int cacheableReply();
66
67 CachePeer *_peer; /* CachePeer request made to */
68 int eof; /* reached end-of-object? */
69 int lastChunk; /* reached last chunk of a chunk-encoded reply */
70 HttpStateFlags flags;
71 size_t read_sz;
72 int header_bytes_read; // to find end of response,
73 int64_t reply_bytes_read; // without relying on StoreEntry
74 int body_bytes_truncated; // positive when we read more than we wanted
75 MemBuf *readBuf;
76 bool ignoreCacheControl;
77 bool surrogateNoStore;
78
79 void processSurrogateControl(HttpReply *);
80
81 protected:
82 void processReply();
83 void proceedAfter1xx();
84 void handle1xx(HttpReply *msg);
85
86 private:
87 /**
88 * The current server connection.
89 * Maybe open, closed, or NULL.
90 * Use doneWithServer() to check if the server is available for use.
91 */
92 Comm::ConnectionPointer serverConnection;
93 AsyncCall::Pointer closeHandler;
94 enum ConnectionStatus {
95 INCOMPLETE_MSG,
96 COMPLETE_PERSISTENT_MSG,
97 COMPLETE_NONPERSISTENT_MSG
98 };
99 ConnectionStatus statusIfComplete() const;
100 ConnectionStatus persistentConnStatus() const;
101 void keepaliveAccounting(HttpReply *);
102 void checkDateSkew(HttpReply *);
103
104 bool continueAfterParsingHeader();
105 void truncateVirginBody();
106
107 virtual void start();
108 virtual void haveParsedReplyHeaders();
109 virtual bool getMoreRequestBody(MemBuf &buf);
110 virtual void closeServer(); // end communication with the server
111 virtual bool doneWithServer() const; // did we end communication?
112 virtual void abortTransaction(const char *reason); // abnormal termination
113 virtual bool mayReadVirginReplyBody() const;
114
115 // consuming request body
116 virtual void handleMoreRequestBodyAvailable();
117 virtual void handleRequestBodyProducerAborted();
118
119 void writeReplyBody();
120 bool decodeAndWriteReplyBody();
121 bool finishingBrokenPost();
122 bool finishingChunkedRequest();
123 void doneSendingRequestBody();
124 void requestBodyHandler(MemBuf &);
125 virtual void sentRequestBody(const CommIoCbParams &io);
126 void wroteLast(const CommIoCbParams &io);
127 void sendComplete();
128 void httpStateConnClosed(const CommCloseCbParams &params);
129 void httpTimeout(const CommTimeoutCbParams &params);
130
131 mb_size_t buildRequestPrefix(MemBuf * mb);
132 static bool decideIfWeDoRanges (HttpRequest * orig_request);
133 bool peerSupportsConnectionPinning() const;
134
135 ChunkedCodingParser *httpChunkDecoder;
136 private:
137 CBDATA_CLASS2(HttpStateData);
138 };
139
140 int httpCachable(const HttpRequestMethod&);
141 void httpStart(FwdState *);
142 const char *httpMakeVaryMark(HttpRequest * request, HttpReply const * reply);
143
144 #endif /* SQUID_HTTP_H */