2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_HTTPMSG_H
10 #define SQUID_HTTPMSG_H
12 #include "base/Lock.h"
14 #include "http/forward.h"
15 #include "http/ProtocolVersion.h"
16 #include "http/StatusCode.h"
17 #include "HttpHeader.h"
19 /// common parts of HttpRequest and HttpReply
20 class HttpMsg
: public RefCountable
24 typedef RefCount
<HttpMsg
> Pointer
;
26 HttpMsg(http_hdr_owner_type owner
);
29 virtual void reset() = 0; // will have body when http*Clean()s are gone
31 void packInto(Packable
* p
, bool full_uri
) const;
33 ///< produce a message copy, except for a few connection-specific settings
34 virtual HttpMsg
*clone() const = 0; ///< \todo rename: not a true copy?
36 /// [re]sets Content-Length header and cached value
37 void setContentLength(int64_t clen
);
40 * \retval true the message sender asks to keep the connection open.
41 * \retval false the message sender will close the connection.
43 * Factors other than the headers may result in connection closure.
45 bool persistent() const;
48 /// HTTP-Version field in the first line of the message.
49 /// see RFC 7230 section 3.1
50 AnyP::ProtocolVersion http_ver
;
54 HttpHdrCc
*cache_control
;
56 /* Unsupported, writable, may disappear/change in the future
57 * For replies, sums _stored_ status-line, headers, and <CRLF>.
58 * Also used to report parsed header size if parse() is successful */
61 int64_t content_length
;
63 HttpMsgParseState pstate
; /* the current parsing state */
65 BodyPipe::Pointer body_pipe
; // optional pipeline to receive message body
67 // returns true and sets hdr_sz on success
68 // returns false and sets *error to zero when needs more data
69 // returns false and sets *error to a positive Http::StatusCode on error
70 bool parse(const char *buf
, const size_t sz
, bool eol
, Http::StatusCode
*error
);
72 bool parseCharBuf(const char *buf
, ssize_t end
);
74 int httpMsgParseStep(const char *buf
, int len
, int atEnd
);
76 virtual int httpMsgParseError();
78 virtual bool expectingBody(const HttpRequestMethod
&, int64_t&) const = 0;
80 void firstLineBuf(MemBuf
&);
82 virtual bool inheritProperties(const HttpMsg
*aMsg
) = 0;
86 * Validate the message start line is syntactically correct.
87 * Set HTTP error status according to problems found.
89 * \retval true Status line has no serious problems.
90 * \retval false Status line has a serious problem. Correct response is indicated by error.
92 virtual bool sanityCheckStartLine(const char *buf
, const size_t hdr_len
, Http::StatusCode
*error
) = 0;
94 virtual void packFirstLineInto(Packable
* p
, bool full_uri
) const = 0;
96 virtual bool parseFirstLine(const char *blk_start
, const char *blk_end
) = 0;
98 virtual void hdrCacheInit();
101 #define HTTPMSGUNLOCK(a) if (a) { if ((a)->unlock() == 0) delete (a); (a)=NULL; }
102 #define HTTPMSGLOCK(a) (a)->lock()
104 #endif /* SQUID_HTTPMSG_H */