]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpMsg.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / HttpMsg.h
1 /*
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 #ifndef SQUID_HTTPMSG_H
10 #define SQUID_HTTPMSG_H
11
12 #include "base/Lock.h"
13 #include "BodyPipe.h"
14 #include "enums.h"
15 #include "http/forward.h"
16 #include "http/ProtocolVersion.h"
17 #include "http/StatusCode.h"
18 #include "HttpHeader.h"
19
20 /// common parts of HttpRequest and HttpReply
21 class HttpMsg : public RefCountable
22 {
23
24 public:
25 typedef RefCount<HttpMsg> Pointer;
26 /// Who may have created or modified this message?
27 enum Sources {
28 srcUnknown = 0,
29
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
35
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
45 };
46
47 HttpMsg(http_hdr_owner_type owner);
48 virtual ~HttpMsg();
49
50 virtual void reset() = 0; // will have body when http*Clean()s are gone
51
52 void packInto(Packable * p, bool full_uri) const;
53
54 ///< produce a message copy, except for a few connection-specific settings
55 virtual HttpMsg *clone() const = 0; ///< \todo rename: not a true copy?
56
57 /// [re]sets Content-Length header and cached value
58 void setContentLength(int64_t clen);
59
60 /**
61 * \retval true the message sender asks to keep the connection open.
62 * \retval false the message sender will close the connection.
63 *
64 * Factors other than the headers may result in connection closure.
65 */
66 bool persistent() const;
67
68 public:
69 /// HTTP-Version field in the first line of the message.
70 /// see RFC 7230 section 3.1
71 AnyP::ProtocolVersion http_ver;
72
73 HttpHeader header;
74
75 HttpHdrCc *cache_control;
76
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 */
80 int hdr_sz;
81
82 int64_t content_length;
83
84 HttpMsgParseState pstate; /* the current parsing state */
85
86 BodyPipe::Pointer body_pipe; // optional pipeline to receive message body
87
88 uint32_t sources; ///< The message sources
89
90 /// copies Cache-Control header to this message
91 void putCc(const HttpHdrCc *otherCc);
92
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);
97
98 bool parseCharBuf(const char *buf, ssize_t end);
99
100 int httpMsgParseStep(const char *buf, int len, int atEnd);
101
102 virtual int httpMsgParseError();
103
104 // Parser-NG transitional parsing of mime headers
105 bool parseHeader(Http1::Parser &); // TODO move this function to the parser
106
107 virtual bool expectingBody(const HttpRequestMethod&, int64_t&) const = 0;
108
109 void firstLineBuf(MemBuf&);
110
111 virtual bool inheritProperties(const HttpMsg *aMsg) = 0;
112
113 protected:
114 /**
115 * Validate the message start line is syntactically correct.
116 * Set HTTP error status according to problems found.
117 *
118 * \retval true Status line has no serious problems.
119 * \retval false Status line has a serious problem. Correct response is indicated by error.
120 */
121 virtual bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error) = 0;
122
123 virtual void packFirstLineInto(Packable * p, bool full_uri) const = 0;
124
125 virtual bool parseFirstLine(const char *blk_start, const char *blk_end) = 0;
126
127 virtual void hdrCacheInit();
128 };
129
130 #define HTTPMSGUNLOCK(a) if (a) { if ((a)->unlock() == 0) delete (a); (a)=NULL; }
131 #define HTTPMSGLOCK(a) (a)->lock()
132
133 #endif /* SQUID_HTTPMSG_H */
134