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