19
18
* it under the terms of the GNU General Public License as published by
20
19
* the Free Software Foundation; either version 2 of the License, or
21
20
* (at your option) any later version.
23
22
* This program is distributed in the hope that it will be useful,
24
23
* but WITHOUT ANY WARRANTY; without even the implied warranty of
25
24
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
25
* GNU General Public License for more details.
28
27
* You should have received a copy of the GNU General Public License
29
28
* along with this program; if not, write to the Free Software
30
29
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
34
32
#ifndef SQUID_HTTPREPLY_H
35
33
#define SQUID_HTTPREPLY_H
38
36
#include "HttpStatusLine.h"
40
38
extern void httpReplyInitModule(void);
41
/* do everything in one call: init, set, pack, clean, return MemBuf */
41
/** do everything in one call: init, set, pack, clean, return MemBuf */
42
42
extern MemBuf *httpPackedReply(HttpVersion ver, http_status status, const char *ctype, int64_t clen, time_t lmt, time_t expires);
44
45
/* Sync changes here with HttpReply.cc */
58
59
virtual void reset();
60
// use HTTPMSGLOCK() instead of calling this directly
61
virtual HttpReply *_lock()
61
/// \par use HTTPMSGLOCK() instead of calling this directly
62
virtual HttpReply *_lock() {
63
63
return static_cast<HttpReply*>(HttpMsg::_lock());
66
66
//virtual void unlock(); // only needed for debugging
68
// returns true on success
69
// returns false and leaves *error unchanged when needs more data
70
// returns false and sets *error to a positive http_status code on error
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
71
73
virtual bool sanityCheckStartLine(MemBuf *buf, const size_t hdr_len, http_status *error);
73
/* public, readable; never update these or their .hdr equivalents directly */
75
/** \par public, readable; never update these or their .hdr equivalents directly */
76
78
time_t last_modified;
86
88
short int keep_alive;
88
/* public, writable, but use httpReply* interfaces when possible */
90
/** \par public, writable, but use httpReply* interfaces when possible */
89
91
HttpStatusLine sline;
91
HttpBody body; /* for small constant memory-resident text bodies only */
93
HttpBody body; /**< for small constant memory-resident text bodies only */
93
String protoPrefix; // e.g., "HTTP/"
95
String protoPrefix; /**< e.g., "HTTP/" */
98
100
virtual int httpMsgParseError();
100
virtual bool expectingBody(method_t, int64_t&) const;
102
virtual bool expectingBody(const HttpRequestMethod&, int64_t&) const;
104
virtual bool inheritProperties(const HttpMsg *aMsg);
102
106
void updateOnNotModified(HttpReply const *other);
104
/* absorb: copy the contents of a new reply to the old one, destroy new one */
105
void absorb(HttpReply * new_rep);
107
/* set commonly used info with one call */
108
void setHeaders(HttpVersion ver, http_status status,
108
/** set commonly used info with one call */
109
void setHeaders(http_status status,
109
110
const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires);
111
/* mem-pack: returns a ready to use mem buffer with a packed reply */
112
/** \return a ready to use mem buffer with a packed reply */
114
/* construct a 304 reply and return it */
115
/** construct a 304 reply and return it */
115
116
HttpReply *make304() const;
117
118
void redirect(http_status, const char *);
119
int64_t bodySize(method_t) const;
120
int64_t bodySize(const HttpRequestMethod&) const;
122
/** Checks whether received body exceeds known maximum size.
123
* Requires a prior call to calcMaxBodySize().
125
bool receivedBodyTooLarge(HttpRequest&, int64_t receivedBodySize);
127
/** Checks whether expected body exceeds known maximum size.
128
* Requires a prior call to calcMaxBodySize().
130
bool expectedBodyTooLarge(HttpRequest& request);
121
132
int validatorsMatch (HttpReply const *other) const;
123
134
void packHeadersInto(Packer * p) const;
125
/// Clone this reply.
126
/// Could be done as a copy-contructor but we do not want to
127
/// accidently copy a HttpReply..
136
/** Clone this reply.
137
* Could be done as a copy-contructor but we do not want to accidently copy a HttpReply..
128
139
HttpReply *clone() const;
138
149
void packInto(Packer * p);
140
151
/* ez-routines */
141
/* construct 304 reply and pack it into MemBuf, return MemBuf */
152
/** \return construct 304 reply and pack it into a MemBuf */
142
153
MemBuf *packed304Reply();
144
155
/* header manipulation */
145
156
time_t hdrExpirationTime();
158
/** Calculates and stores maximum body size if needed.
159
* Used by receivedBodyTooLarge() and expectedBodyTooLarge().
161
void calcMaxBodySize(HttpRequest& request);
163
mutable int64_t bodySizeMax; /**< cached result of calcMaxBodySize */
148
166
virtual void packFirstLineInto(Packer * p, bool) const;