]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpReply.h
Merge from trunk rev.13532
[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 "http/StatusLine.h"
34 #include "HttpBody.h"
35 #include "HttpMsg.h"
36 #include "HttpRequest.h"
37
38 void httpReplyInitModule(void);
39
40 /* Sync changes here with HttpReply.cc */
41
42 class HttpHdrContRange;
43
44 class HttpHdrSc;
45
46 class HttpReply: public HttpMsg
47 {
48
49 public:
50 typedef RefCount<HttpReply> Pointer;
51
52 MEMPROXY_CLASS(HttpReply);
53 HttpReply();
54 ~HttpReply();
55
56 virtual void reset();
57
58 /**
59 \retval true on success
60 \retval false and sets *error to zero when needs more data
61 \retval false and sets *error to a positive Http::StatusCode on error
62 */
63 virtual bool sanityCheckStartLine(MemBuf *buf, const size_t hdr_len, Http::StatusCode *error);
64
65 /** \par public, readable; never update these or their .hdr equivalents directly */
66 time_t date;
67
68 time_t last_modified;
69
70 time_t expires;
71
72 String content_type;
73
74 HttpHdrSc *surrogate_control;
75
76 HttpHdrContRange *content_range;
77
78 short int keep_alive;
79
80 /** \par public, writable, but use httpReply* interfaces when possible */
81 Http::StatusLine sline;
82
83 HttpBody body; /**< for small constant memory-resident text bodies only */
84
85 String protoPrefix; /**< e.g., "HTTP/" */
86
87 bool do_clean;
88
89 public:
90 virtual int httpMsgParseError();
91
92 virtual bool expectingBody(const HttpRequestMethod&, int64_t&) const;
93
94 virtual bool inheritProperties(const HttpMsg *aMsg);
95
96 void updateOnNotModified(HttpReply const *other);
97
98 /** set commonly used info with one call */
99 void setHeaders(Http::StatusCode status,
100 const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires);
101
102 /** \return a ready to use mem buffer with a packed reply */
103 MemBuf *pack();
104
105 /** construct a 304 reply and return it */
106 HttpReply *make304() const;
107
108 void redirect(Http::StatusCode, const char *);
109
110 int64_t bodySize(const HttpRequestMethod&) const;
111
112 /** Checks whether received body exceeds known maximum size.
113 * Requires a prior call to calcMaxBodySize().
114 */
115 bool receivedBodyTooLarge(HttpRequest&, int64_t receivedBodySize);
116
117 /** Checks whether expected body exceeds known maximum size.
118 * Requires a prior call to calcMaxBodySize().
119 */
120 bool expectedBodyTooLarge(HttpRequest& request);
121
122 int validatorsMatch (HttpReply const *other) const;
123
124 void packHeadersInto(Packer * p) const;
125
126 /** Clone this reply.
127 * Could be done as a copy-contructor but we do not want to accidently copy a HttpReply..
128 */
129 HttpReply *clone() const;
130
131 /// Remove Warnings with warn-date different from Date value
132 void removeStaleWarnings();
133
134 virtual void hdrCacheInit();
135
136 private:
137 /** initialize */
138 void init();
139
140 void clean();
141
142 void hdrCacheClean();
143
144 void packInto(Packer * p);
145
146 /* ez-routines */
147 /** \return construct 304 reply and pack it into a MemBuf */
148 MemBuf *packed304Reply();
149
150 /* header manipulation */
151 time_t hdrExpirationTime();
152
153 /** Calculates and stores maximum body size if needed.
154 * Used by receivedBodyTooLarge() and expectedBodyTooLarge().
155 */
156 void calcMaxBodySize(HttpRequest& request) const;
157
158 String removeStaleWarningValues(const String &value);
159
160 mutable int64_t bodySizeMax; /**< cached result of calcMaxBodySize */
161
162 protected:
163 virtual void packFirstLineInto(Packer * p, bool) const { sline.packInto(p); }
164
165 virtual bool parseFirstLine(const char *start, const char *end);
166 };
167
168 MEMPROXY_CLASS_INLINE(HttpReply);
169
170 #endif /* SQUID_HTTPREPLY_H */