3 * SQUID Web Proxy Cache http://www.squid-cache.org/
4 * ----------------------------------------------------------
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.
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.
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.
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.
31 #ifndef SQUID_HTTPMSG_H
32 #define SQUID_HTTPMSG_H
34 #include "base/Lock.h"
36 #include "http/ProtocolVersion.h"
37 #include "http/StatusCode.h"
38 #include "HttpHeader.h"
39 #include "HttpRequestMethod.h"
41 /// common parts of HttpRequest and HttpReply
42 class HttpMsg
: public RefCountable
46 typedef RefCount
<HttpMsg
> Pointer
;
48 HttpMsg(http_hdr_owner_type owner
);
51 virtual void reset() = 0; // will have body when http*Clean()s are gone
53 void packInto(Packer
* p
, bool full_uri
) const;
55 ///< produce a message copy, except for a few connection-specific settings
56 virtual HttpMsg
*clone() const = 0; ///< \todo rename: not a true copy?
58 /// [re]sets Content-Length header and cached value
59 void setContentLength(int64_t clen
);
62 * \retval true the message sender asks to keep the connection open.
63 * \retval false the message sender will close the connection.
65 * Factors other than the headers may result in connection closure.
67 bool persistent() const;
70 Http::ProtocolVersion http_ver
;
74 HttpHdrCc
*cache_control
;
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 */
81 int64_t content_length
;
83 AnyP::ProtocolType protocol
;
85 HttpMsgParseState pstate
; /* the current parsing state */
87 BodyPipe::Pointer body_pipe
; // optional pipeline to receive message body
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
);
94 bool parseCharBuf(const char *buf
, ssize_t end
);
96 int httpMsgParseStep(const char *buf
, int len
, int atEnd
);
98 virtual int httpMsgParseError();
100 virtual bool expectingBody(const HttpRequestMethod
&, int64_t&) const = 0;
102 void firstLineBuf(MemBuf
&);
104 virtual bool inheritProperties(const HttpMsg
*aMsg
) = 0;
108 * Validate the message start line is syntactically correct.
109 * Set HTTP error status according to problems found.
111 * \retval true Status line has no serious problems.
112 * \retval false Status line has a serious problem. Correct response is indicated by error.
114 virtual bool sanityCheckStartLine(MemBuf
*buf
, const size_t hdr_len
, Http::StatusCode
*error
) = 0;
116 virtual void packFirstLineInto(Packer
* p
, bool full_uri
) const = 0;
118 virtual bool parseFirstLine(const char *blk_start
, const char *blk_end
) = 0;
120 virtual void hdrCacheInit();
123 int httpMsgIsolateHeaders(const char **parse_start
, int len
, const char **blk_start
, const char **blk_end
);
125 #define HTTPMSGUNLOCK(a) if (a) { if ((a)->unlock() == 0) delete (a); (a)=NULL; }
126 #define HTTPMSGLOCK(a) (a)->lock()
128 #endif /* SQUID_HTTPMSG_H */