]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpMsg.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / HttpMsg.h
1 /*
2 * Copyright (C) 1996-2015 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 "http/forward.h"
15 #include "http/ProtocolVersion.h"
16 #include "http/StatusCode.h"
17 #include "HttpHeader.h"
18
19 /// common parts of HttpRequest and HttpReply
20 class HttpMsg : public RefCountable
21 {
22
23 public:
24 typedef RefCount<HttpMsg> Pointer;
25
26 HttpMsg(http_hdr_owner_type owner);
27 virtual ~HttpMsg();
28
29 virtual void reset() = 0; // will have body when http*Clean()s are gone
30
31 void packInto(Packer * p, bool full_uri) const;
32
33 ///< produce a message copy, except for a few connection-specific settings
34 virtual HttpMsg *clone() const = 0; ///< \todo rename: not a true copy?
35
36 /// [re]sets Content-Length header and cached value
37 void setContentLength(int64_t clen);
38
39 /**
40 * \retval true the message sender asks to keep the connection open.
41 * \retval false the message sender will close the connection.
42 *
43 * Factors other than the headers may result in connection closure.
44 */
45 bool persistent() const;
46
47 public:
48 /// HTTP-Version field in the first line of the message.
49 /// see RFC 7230 section 3.1
50 AnyP::ProtocolVersion http_ver;
51
52 HttpHeader header;
53
54 HttpHdrCc *cache_control;
55
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 */
59 int hdr_sz;
60
61 int64_t content_length;
62
63 HttpMsgParseState pstate; /* the current parsing state */
64
65 BodyPipe::Pointer body_pipe; // optional pipeline to receive message body
66
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(MemBuf *buf, bool eol, Http::StatusCode *error);
71
72 bool parseCharBuf(const char *buf, ssize_t end);
73
74 int httpMsgParseStep(const char *buf, int len, int atEnd);
75
76 virtual int httpMsgParseError();
77
78 virtual bool expectingBody(const HttpRequestMethod&, int64_t&) const = 0;
79
80 void firstLineBuf(MemBuf&);
81
82 virtual bool inheritProperties(const HttpMsg *aMsg) = 0;
83
84 protected:
85 /**
86 * Validate the message start line is syntactically correct.
87 * Set HTTP error status according to problems found.
88 *
89 * \retval true Status line has no serious problems.
90 * \retval false Status line has a serious problem. Correct response is indicated by error.
91 */
92 virtual bool sanityCheckStartLine(MemBuf *buf, const size_t hdr_len, Http::StatusCode *error) = 0;
93
94 virtual void packFirstLineInto(Packer * p, bool full_uri) const = 0;
95
96 virtual bool parseFirstLine(const char *blk_start, const char *blk_end) = 0;
97
98 virtual void hdrCacheInit();
99 };
100
101 #define HTTPMSGUNLOCK(a) if (a) { if ((a)->unlock() == 0) delete (a); (a)=NULL; }
102 #define HTTPMSGLOCK(a) (a)->lock()
103
104 #endif /* SQUID_HTTPMSG_H */
105