]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpMsg.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / HttpMsg.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
31 #ifndef SQUID_HTTPMSG_H
32 #define SQUID_HTTPMSG_H
33
34 #include "base/Lock.h"
35 #include "BodyPipe.h"
36 #include "http/ProtocolVersion.h"
37 #include "http/StatusCode.h"
38 #include "HttpHeader.h"
39 #include "HttpRequestMethod.h"
40
41 /// common parts of HttpRequest and HttpReply
42 class HttpMsg : public RefCountable
43 {
44
45 public:
46 typedef RefCount<HttpMsg> Pointer;
47
48 HttpMsg(http_hdr_owner_type owner);
49 virtual ~HttpMsg();
50
51 virtual void reset() = 0; // will have body when http*Clean()s are gone
52
53 void packInto(Packer * p, bool full_uri) const;
54
55 ///< produce a message copy, except for a few connection-specific settings
56 virtual HttpMsg *clone() const = 0; ///< \todo rename: not a true copy?
57
58 /// [re]sets Content-Length header and cached value
59 void setContentLength(int64_t clen);
60
61 /**
62 * \retval true the message sender asks to keep the connection open.
63 * \retval false the message sender will close the connection.
64 *
65 * Factors other than the headers may result in connection closure.
66 */
67 bool persistent() const;
68
69 public:
70 Http::ProtocolVersion http_ver;
71
72 HttpHeader header;
73
74 HttpHdrCc *cache_control;
75
76 /* Unsupported, writable, may disappear/change in the future
77 * For replies, sums _stored_ status-line, headers, and <CRLF>.
78 * Also used to report parsed header size if parse() is successful */
79 int hdr_sz;
80
81 int64_t content_length;
82
83 AnyP::ProtocolType protocol;
84
85 HttpMsgParseState pstate; /* the current parsing state */
86
87 BodyPipe::Pointer body_pipe; // optional pipeline to receive message body
88
89 // returns true and sets hdr_sz on success
90 // returns false and sets *error to zero when needs more data
91 // returns false and sets *error to a positive Http::StatusCode on error
92 bool parse(MemBuf *buf, bool eol, Http::StatusCode *error);
93
94 bool parseCharBuf(const char *buf, ssize_t end);
95
96 int httpMsgParseStep(const char *buf, int len, int atEnd);
97
98 virtual int httpMsgParseError();
99
100 virtual bool expectingBody(const HttpRequestMethod&, int64_t&) const = 0;
101
102 void firstLineBuf(MemBuf&);
103
104 virtual bool inheritProperties(const HttpMsg *aMsg) = 0;
105
106 protected:
107 /**
108 * Validate the message start line is syntactically correct.
109 * Set HTTP error status according to problems found.
110 *
111 * \retval true Status line has no serious problems.
112 * \retval false Status line has a serious problem. Correct response is indicated by error.
113 */
114 virtual bool sanityCheckStartLine(MemBuf *buf, const size_t hdr_len, Http::StatusCode *error) = 0;
115
116 virtual void packFirstLineInto(Packer * p, bool full_uri) const = 0;
117
118 virtual bool parseFirstLine(const char *blk_start, const char *blk_end) = 0;
119
120 virtual void hdrCacheInit();
121 };
122
123 int httpMsgIsolateHeaders(const char **parse_start, int len, const char **blk_start, const char **blk_end);
124
125 #define HTTPMSGUNLOCK(a) if (a) { if ((a)->unlock() == 0) delete (a); (a)=NULL; }
126 #define HTTPMSGLOCK(a) (a)->lock()
127
128 #endif /* SQUID_HTTPMSG_H */