2 * Copyright (C) 1996-2017 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"
15 #include "http/forward.h"
16 #include "http/ProtocolVersion.h"
17 #include "http/StatusCode.h"
18 #include "HttpHeader.h"
20 /// common parts of HttpRequest and HttpReply
21 class HttpMsg
: public RefCountable
25 typedef RefCount
<HttpMsg
> Pointer
;
26 /// Who may have created or modified this message?
30 /* flags in 0xFFFF zone are for "secure" or "encrypted" sources */
31 srcHttps
= 1 << 0, ///< https_port or bumped http_port tunnel; HTTPS server
32 srcFtps
= 1 << 1, ///< ftps_port or SFTP server; currently unused
33 srcIcaps
= 1 << 2, ///< Secure ICAP service
34 srcEcaps
= 1 << 3, ///< eCAP service that is considered secure; currently unused
36 /* these flags "taint" the message: it may have been observed or mangled outside Squid */
37 srcHttp
= 1 << (16 + 0), ///< http_port or HTTP server
38 srcFtp
= 1 << (16 + 1), ///< ftp_port or FTP server
39 srcIcap
= 1 << (16 + 2), ///< traditional ICAP service without encryption
40 srcEcap
= 1 << (16 + 3), ///< eCAP service that uses insecure libraries/daemons
41 srcGopher
= 1 << (16 + 14), ///< Gopher server
42 srcWhois
= 1 << (16 + 15), ///< Whois server
43 srcUnsafe
= 0xFFFF0000, ///< Unsafe sources mask
44 srcSafe
= 0x0000FFFF ///< Safe sources mask
47 HttpMsg(http_hdr_owner_type owner
);
50 virtual void reset() = 0; // will have body when http*Clean()s are gone
52 void packInto(Packable
* p
, bool full_uri
) const;
54 ///< produce a message copy, except for a few connection-specific settings
55 virtual HttpMsg
*clone() const = 0; ///< \todo rename: not a true copy?
57 /// [re]sets Content-Length header and cached value
58 void setContentLength(int64_t clen
);
61 * \retval true the message sender asks to keep the connection open.
62 * \retval false the message sender will close the connection.
64 * Factors other than the headers may result in connection closure.
66 bool persistent() const;
69 /// HTTP-Version field in the first line of the message.
70 /// see RFC 7230 section 3.1
71 AnyP::ProtocolVersion http_ver
;
75 HttpHdrCc
*cache_control
;
77 /* Unsupported, writable, may disappear/change in the future
78 * For replies, sums _stored_ status-line, headers, and <CRLF>.
79 * Also used to report parsed header size if parse() is successful */
82 int64_t content_length
;
84 HttpMsgParseState pstate
; /* the current parsing state */
86 BodyPipe::Pointer body_pipe
; // optional pipeline to receive message body
88 uint32_t sources
; ///< The message sources
90 /// copies Cache-Control header to this message
91 void putCc(const HttpHdrCc
*otherCc
);
93 // returns true and sets hdr_sz on success
94 // returns false and sets *error to zero when needs more data
95 // returns false and sets *error to a positive Http::StatusCode on error
96 bool parse(const char *buf
, const size_t sz
, bool eol
, Http::StatusCode
*error
);
98 bool parseCharBuf(const char *buf
, ssize_t end
);
100 int httpMsgParseStep(const char *buf
, int len
, int atEnd
);
102 virtual int httpMsgParseError();
104 // Parser-NG transitional parsing of mime headers
105 bool parseHeader(Http1::Parser
&); // TODO move this function to the parser
107 virtual bool expectingBody(const HttpRequestMethod
&, int64_t&) const = 0;
109 void firstLineBuf(MemBuf
&);
111 virtual bool inheritProperties(const HttpMsg
*aMsg
) = 0;
115 * Validate the message start line is syntactically correct.
116 * Set HTTP error status according to problems found.
118 * \retval true Status line has no serious problems.
119 * \retval false Status line has a serious problem. Correct response is indicated by error.
121 virtual bool sanityCheckStartLine(const char *buf
, const size_t hdr_len
, Http::StatusCode
*error
) = 0;
123 virtual void packFirstLineInto(Packable
* p
, bool full_uri
) const = 0;
125 virtual bool parseFirstLine(const char *blk_start
, const char *blk_end
) = 0;
127 virtual void hdrCacheInit();
130 #define HTTPMSGUNLOCK(a) if (a) { if ((a)->unlock() == 0) delete (a); (a)=NULL; }
131 #define HTTPMSGLOCK(a) (a)->lock()
133 #endif /* SQUID_HTTPMSG_H */