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