]> git.ipfire.org Git - thirdparty/squid.git/blame - src/http/one/ResponseParser.h
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / http / one / ResponseParser.h
CommitLineData
ad20e647 1/*
f70aedc4 2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
ad20e647
AJ
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
f1d5359e
AJ
9#ifndef _SQUID_SRC_HTTP_ONE_RESPONSEPARSER_H
10#define _SQUID_SRC_HTTP_ONE_RESPONSEPARSER_H
11
12#include "http/one/Parser.h"
13#include "http/StatusCode.h"
14
15namespace Http {
16namespace One {
17
18/** HTTP/1.x protocol response parser
19 *
20 * Also capable of parsing unexpected ICY responses and
21 * upgrading HTTP/0.9 syntax responses to HTTP/1.1
22 *
23 * Works on a raw character I/O buffer and tokenizes the content into
24 * the major CRLF delimited segments of an HTTP/1 respone message:
25 *
f439fbd2
AJ
26 * \li status-line (version SP status SP reash-phrase)
27 * \li mime-header (set of RFC2616 syntax header fields)
f1d5359e
AJ
28 */
29class ResponseParser : public Http1::Parser
30{
31public:
20b1beab
AJ
32 ResponseParser() = default;
33 ResponseParser(const ResponseParser &) = default;
34 ResponseParser &operator =(const ResponseParser &) = default;
35 ResponseParser(ResponseParser &&) = default;
36 ResponseParser &operator =(ResponseParser &&) = default;
f1d5359e
AJ
37 virtual ~ResponseParser() {}
38
39 /* Http::One::Parser API */
40 virtual void clear() {*this=ResponseParser();}
41 virtual Http1::Parser::size_type firstLineSize() const;
42 virtual bool parse(const SBuf &aBuf);
43
44 /* respone specific fields, read-only */
45 Http::StatusCode messageStatus() const { return statusCode_;}
46 SBuf reasonPhrase() const { return reasonPhrase_;}
47
38da9c24
EB
48 /// extracts response status-code and the following delimiter; validates status-code
49 /// \param[out] code syntactically valid status-code (unchanged on syntax errors)
50 /// \throws InsuffientInput and other exceptions on syntax and validation errors
51 static void ParseResponseStatus(Tokenizer &, StatusCode &code);
52
f1d5359e 53private:
5aea71e7 54 int parseResponseFirstLine();
38da9c24 55 int parseResponseStatusAndReason(Tokenizer &);
f1d5359e
AJ
56
57 /// magic prefix for identifying ICY response messages
58 static const SBuf IcyMagic;
59
60 /// Whether we found the status code yet.
61 /// We cannot rely on status value because server may send "000".
7a010fb2 62 bool completedStatus_ = false;
f1d5359e
AJ
63
64 /// HTTP/1 status-line status code
7a010fb2 65 Http::StatusCode statusCode_ = Http::scNone;
f1d5359e
AJ
66
67 /// HTTP/1 status-line reason phrase
68 SBuf reasonPhrase_;
69};
70
71} // namespace One
72} // namespace Http
73
74#endif /* _SQUID_SRC_HTTP_ONE_RESPONSEPARSER_H */
1810a0cb 75