2 * Copyright (C) 1996-2022 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_SRC_HTTP_ONE_REQUESTPARSER_H
10 #define _SQUID_SRC_HTTP_ONE_REQUESTPARSER_H
12 #include "http/one/Parser.h"
13 #include "http/RequestMethod.h"
22 /** HTTP/1.x protocol request parser
24 * Works on a raw character I/O buffer and tokenizes the content into
25 * the major CRLF delimited segments of an HTTP/1 request message:
27 * \li request-line (method, URL, protocol, version)
28 * \li mime-header (set of RFC2616 syntax header fields)
30 class RequestParser
: public Http1::Parser
33 RequestParser() = default;
34 RequestParser(bool preserveParsed
) { preserveParsed_
= preserveParsed
; }
35 RequestParser(const RequestParser
&) = default;
36 RequestParser
&operator =(const RequestParser
&) = default;
37 RequestParser(RequestParser
&&) = default;
38 RequestParser
&operator =(RequestParser
&&) = default;
39 ~RequestParser() override
{}
41 /* Http::One::Parser API */
42 void clear() override
{*this = RequestParser();}
43 Http1::Parser::size_type
firstLineSize() const override
;
44 bool parse(const SBuf
&aBuf
) override
;
46 /// the HTTP method if this is a request message
47 const HttpRequestMethod
& method() const {return method_
;}
49 /// the request-line URI if this is a request message, or an empty string.
50 const SBuf
&requestUri() const {return uri_
;}
52 /// the accumulated parsed bytes
53 const SBuf
&parsed() const { Must(preserveParsed_
); return parsed_
; }
56 void skipGarbageLines();
57 int parseRequestFirstLine();
58 /// called from parse() to do the parsing
59 bool doParse(const SBuf
&aBuf
);
61 /* all these return false and set parseStatusCode on parsing failures */
62 bool parseMethodField(Tokenizer
&);
63 bool parseUriField(Tokenizer
&);
64 bool parseHttpVersionField(Tokenizer
&);
65 bool skipDelimiter(const size_t count
, const char *where
);
66 bool skipTrailingCrs(Tokenizer
&tok
);
68 bool http0() const {return !msgProtocol_
.major
;}
69 static const CharacterSet
&RequestTargetCharacters();
71 /// what request method has been found on the first line
72 HttpRequestMethod method_
;
74 /// raw copy of the original client request-line URI field
77 /// all parsed bytes (i.e., input prefix consumed by parse() calls)
78 /// meaningless unless preserveParsed_ is true
80 bool preserveParsed_
= false; ///< whether to accumulate parsed bytes (in parsed_)
86 #endif /* _SQUID_SRC_HTTP_ONE_REQUESTPARSER_H */