]>
Commit | Line | Data |
---|---|---|
f1974911 | 1 | /* |
ef57eb7b | 2 | * Copyright (C) 1996-2016 The Squid Software Foundation and contributors |
f1974911 | 3 | * |
bbc27441 AJ |
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. | |
f1974911 | 7 | */ |
8 | ||
9 | #ifndef SQUID_HTTPMSG_H | |
10 | #define SQUID_HTTPMSG_H | |
11 | ||
5444ee48 AJ |
12 | #include "base/Lock.h" |
13 | #include "BodyPipe.h" | |
e1ba42a4 | 14 | #include "enums.h" |
f35c0145 | 15 | #include "http/forward.h" |
602d9612 A |
16 | #include "http/ProtocolVersion.h" |
17 | #include "http/StatusCode.h" | |
f1974911 | 18 | #include "HttpHeader.h" |
f1974911 | 19 | |
b248c2a3 | 20 | /// common parts of HttpRequest and HttpReply |
5444ee48 | 21 | class HttpMsg : public RefCountable |
f1974911 | 22 | { |
23 | ||
24 | public: | |
b248c2a3 | 25 | typedef RefCount<HttpMsg> Pointer; |
88df846b CT |
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 | }; | |
db260341 | 46 | |
f1974911 | 47 | HttpMsg(http_hdr_owner_type owner); |
4a56ee8d | 48 | virtual ~HttpMsg(); |
f1974911 | 49 | |
50 | virtual void reset() = 0; // will have body when http*Clean()s are gone | |
51 | ||
17802cf1 | 52 | void packInto(Packable * p, bool full_uri) const; |
f1974911 | 53 | |
26ac0430 AJ |
54 | ///< produce a message copy, except for a few connection-specific settings |
55 | virtual HttpMsg *clone() const = 0; ///< \todo rename: not a true copy? | |
fa0e6114 | 56 | |
3ff65596 AR |
57 | /// [re]sets Content-Length header and cached value |
58 | void setContentLength(int64_t clen); | |
59 | ||
cb1f4d34 | 60 | /** |
4a1acc56 AJ |
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 | ||
f1974911 | 68 | public: |
4e3f4dc7 | 69 | /// HTTP-Version field in the first line of the message. |
bf484584 | 70 | /// see RFC 7230 section 3.1 |
2592bc70 | 71 | AnyP::ProtocolVersion http_ver; |
4a56ee8d | 72 | |
f1974911 | 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 | ||
47f6e231 | 82 | int64_t content_length; |
4a56ee8d | 83 | |
e3ab4be3 | 84 | HttpMsgParseState pstate; /* the current parsing state */ |
4a56ee8d | 85 | |
5f8252d2 | 86 | BodyPipe::Pointer body_pipe; // optional pipeline to receive message body |
87 | ||
88df846b CT |
88 | uint32_t sources; ///< The message sources |
89 | ||
e3ab4be3 | 90 | // returns true and sets hdr_sz on success |
91 | // returns false and sets *error to zero when needs more data | |
955394ce | 92 | // returns false and sets *error to a positive Http::StatusCode on error |
84ae6223 | 93 | bool parse(const char *buf, const size_t sz, bool eol, Http::StatusCode *error); |
4a56ee8d | 94 | |
59eed7dc | 95 | bool parseCharBuf(const char *buf, ssize_t end); |
4a56ee8d | 96 | |
666f514b | 97 | int httpMsgParseStep(const char *buf, int len, int atEnd); |
4a56ee8d | 98 | |
fb525683 | 99 | virtual int httpMsgParseError(); |
4a56ee8d | 100 | |
af2980f3 AJ |
101 | // Parser-NG transitional parsing of mime headers |
102 | bool parseHeader(Http1::Parser &); // TODO move this function to the parser | |
103 | ||
60745f24 | 104 | virtual bool expectingBody(const HttpRequestMethod&, int64_t&) const = 0; |
e3ab4be3 | 105 | |
4a56ee8d | 106 | void firstLineBuf(MemBuf&); |
26ac0430 | 107 | |
d67acb4e | 108 | virtual bool inheritProperties(const HttpMsg *aMsg) = 0; |
f1974911 | 109 | |
110 | protected: | |
e1381638 AJ |
111 | /** |
112 | * Validate the message start line is syntactically correct. | |
113 | * Set HTTP error status according to problems found. | |
114 | * | |
115 | * \retval true Status line has no serious problems. | |
116 | * \retval false Status line has a serious problem. Correct response is indicated by error. | |
117 | */ | |
84ae6223 | 118 | virtual bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error) = 0; |
4a56ee8d | 119 | |
17802cf1 | 120 | virtual void packFirstLineInto(Packable * p, bool full_uri) const = 0; |
4a56ee8d | 121 | |
429f7150 | 122 | virtual bool parseFirstLine(const char *blk_start, const char *blk_end) = 0; |
4a56ee8d | 123 | |
07947ad8 | 124 | virtual void hdrCacheInit(); |
f1974911 | 125 | }; |
126 | ||
b248c2a3 AJ |
127 | #define HTTPMSGUNLOCK(a) if (a) { if ((a)->unlock() == 0) delete (a); (a)=NULL; } |
128 | #define HTTPMSGLOCK(a) (a)->lock() | |
66c38d9a | 129 | |
f1974911 | 130 | #endif /* SQUID_HTTPMSG_H */ |
f53969cc | 131 |