]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpReply.h
merge from SslServerCertValidator r12332
[thirdparty/squid.git] / src / HttpReply.h
1 /*
2 *
3 * SQUID Web Proxy Cache http://www.squid-cache.org/
4 * ----------------------------------------------------------
5 *
6 * Squid is the result of efforts by numerous individuals from
7 * the Internet community; see the CONTRIBUTORS file for full
8 * details. Many organizations have provided support for Squid's
9 * development; see the SPONSORS file for full details. Squid is
10 * Copyrighted (C) 2001 by the Regents of the University of
11 * California; see the COPYRIGHT file for full details. Squid
12 * incorporates software developed and/or copyrighted by other
13 * sources; see the CREDITS file for full details.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
28 *
29 */
30 #ifndef SQUID_HTTPREPLY_H
31 #define SQUID_HTTPREPLY_H
32
33 #include "HttpBody.h"
34 #include "HttpMsg.h"
35 #include "HttpRequest.h"
36 #include "HttpStatusLine.h"
37
38 void httpReplyInitModule(void);
39
40 #if DEAD_CODE
41 /** do everything in one call: init, set, pack, clean, return MemBuf */
42 MemBuf *httpPackedReply(HttpVersion ver, http_status status, const char *ctype, int64_t clen, time_t lmt, time_t expires);
43 #endif
44
45 /* Sync changes here with HttpReply.cc */
46
47 class HttpHdrContRange;
48
49 class HttpHdrSc;
50
51 class HttpReply: public HttpMsg
52 {
53
54 public:
55 typedef HttpMsgPointerT<HttpReply> Pointer;
56
57 MEMPROXY_CLASS(HttpReply);
58 HttpReply();
59 ~HttpReply();
60
61 virtual void reset();
62
63 /// \par use HTTPMSGLOCK() instead of calling this directly
64 virtual HttpReply *_lock() {
65 return static_cast<HttpReply*>(HttpMsg::_lock());
66 };
67
68 //virtual void unlock(); // only needed for debugging
69
70 /**
71 \retval true on success
72 \retval false and sets *error to zero when needs more data
73 \retval false and sets *error to a positive http_status code on error
74 */
75 virtual bool sanityCheckStartLine(MemBuf *buf, const size_t hdr_len, http_status *error);
76
77 /** \par public, readable; never update these or their .hdr equivalents directly */
78 time_t date;
79
80 time_t last_modified;
81
82 time_t expires;
83
84 String content_type;
85
86 HttpHdrSc *surrogate_control;
87
88 HttpHdrContRange *content_range;
89
90 short int keep_alive;
91
92 /** \par public, writable, but use httpReply* interfaces when possible */
93 HttpStatusLine sline;
94
95 HttpBody body; /**< for small constant memory-resident text bodies only */
96
97 String protoPrefix; /**< e.g., "HTTP/" */
98
99 bool do_clean;
100
101 public:
102 virtual int httpMsgParseError();
103
104 virtual bool expectingBody(const HttpRequestMethod&, int64_t&) const;
105
106 virtual bool inheritProperties(const HttpMsg *aMsg);
107
108 void updateOnNotModified(HttpReply const *other);
109
110 /** set commonly used info with one call */
111 void setHeaders(http_status status,
112 const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires);
113
114 /** \return a ready to use mem buffer with a packed reply */
115 MemBuf *pack();
116
117 /** construct a 304 reply and return it */
118 HttpReply *make304() const;
119
120 void redirect(http_status, const char *);
121
122 int64_t bodySize(const HttpRequestMethod&) const;
123
124 /** Checks whether received body exceeds known maximum size.
125 * Requires a prior call to calcMaxBodySize().
126 */
127 bool receivedBodyTooLarge(HttpRequest&, int64_t receivedBodySize);
128
129 /** Checks whether expected body exceeds known maximum size.
130 * Requires a prior call to calcMaxBodySize().
131 */
132 bool expectedBodyTooLarge(HttpRequest& request);
133
134 int validatorsMatch (HttpReply const *other) const;
135
136 void packHeadersInto(Packer * p) const;
137
138 /** Clone this reply.
139 * Could be done as a copy-contructor but we do not want to accidently copy a HttpReply..
140 */
141 HttpReply *clone() const;
142
143 /// Remove Warnings with warn-date different from Date value
144 void removeStaleWarnings();
145
146 private:
147 /** initialize */
148 void init();
149
150 void clean();
151
152 void hdrCacheClean();
153
154 void packInto(Packer * p);
155
156 /* ez-routines */
157 /** \return construct 304 reply and pack it into a MemBuf */
158 MemBuf *packed304Reply();
159
160 /* header manipulation */
161 time_t hdrExpirationTime();
162
163 /** Calculates and stores maximum body size if needed.
164 * Used by receivedBodyTooLarge() and expectedBodyTooLarge().
165 */
166 void calcMaxBodySize(HttpRequest& request);
167
168 String removeStaleWarningValues(const String &value);
169
170 mutable int64_t bodySizeMax; /**< cached result of calcMaxBodySize */
171
172 protected:
173 virtual void packFirstLineInto(Packer * p, bool) const;
174
175 virtual bool parseFirstLine(const char *start, const char *end);
176
177 virtual void hdrCacheInit();
178 };
179
180 MEMPROXY_CLASS_INLINE(HttpReply);
181
182 #endif /* SQUID_HTTPREPLY_H */