]>
Commit | Line | Data |
---|---|---|
eac61ce1 | 1 | /* |
f6e9a3ee | 2 | * Copyright (C) 1996-2019 The Squid Software Foundation and contributors |
eac61ce1 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 | ||
c99510dd AJ |
9 | #ifndef _SQUID_SRC_HTTP_ONE_REQUESTPARSER_H |
10 | #define _SQUID_SRC_HTTP_ONE_REQUESTPARSER_H | |
11 | ||
12 | #include "http/one/Parser.h" | |
13 | #include "http/RequestMethod.h" | |
c99510dd | 14 | |
947ca0c6 AJ |
15 | namespace Parser { |
16 | class Tokenizer; | |
17 | } | |
18 | ||
c99510dd AJ |
19 | namespace Http { |
20 | namespace One { | |
21 | ||
22 | /** HTTP/1.x protocol request parser | |
23 | * | |
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: | |
26 | * | |
f439fbd2 AJ |
27 | * \li request-line (method, URL, protocol, version) |
28 | * \li mime-header (set of RFC2616 syntax header fields) | |
c99510dd AJ |
29 | */ |
30 | class RequestParser : public Http1::Parser | |
31 | { | |
c99510dd | 32 | public: |
7a010fb2 AJ |
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; | |
f9688132 AJ |
39 | virtual ~RequestParser() {} |
40 | ||
c99510dd | 41 | /* Http::One::Parser API */ |
f9688132 | 42 | virtual void clear() {*this = RequestParser();} |
947ca0c6 | 43 | virtual Http1::Parser::size_type firstLineSize() const; |
c99510dd AJ |
44 | virtual bool parse(const SBuf &aBuf); |
45 | ||
46 | /// the HTTP method if this is a request message | |
47 | const HttpRequestMethod & method() const {return method_;} | |
48 | ||
49 | /// the request-line URI if this is a request message, or an empty string. | |
50 | const SBuf &requestUri() const {return uri_;} | |
51 | ||
6b2b6cfe CT |
52 | /// the accumulated parsed bytes |
53 | const SBuf &parsed() const { Must(preserveParsed_); return parsed_; } | |
54 | ||
c99510dd AJ |
55 | private: |
56 | void skipGarbageLines(); | |
57 | int parseRequestFirstLine(); | |
6b2b6cfe CT |
58 | /// called from parse() to do the parsing |
59 | bool doParse(const SBuf &aBuf); | |
e02f963c AR |
60 | |
61 | /* all these return false and set parseStatusCode on parsing failures */ | |
62 | bool parseMethodField(Http1::Tokenizer &); | |
63 | bool parseUriField(Http1::Tokenizer &); | |
64 | bool parseHttpVersionField(Http1::Tokenizer &); | |
f8b58a68 | 65 | bool skipDelimiter(const size_t count, const char *where); |
e02f963c AR |
66 | bool skipTrailingCrs(Http1::Tokenizer &tok); |
67 | ||
68 | bool http0() const {return !msgProtocol_.major;} | |
e02f963c | 69 | static const CharacterSet &RequestTargetCharacters(); |
c99510dd AJ |
70 | |
71 | /// what request method has been found on the first line | |
72 | HttpRequestMethod method_; | |
73 | ||
b521616b | 74 | /// raw copy of the original client request-line URI field |
c99510dd | 75 | SBuf uri_; |
6b2b6cfe CT |
76 | |
77 | /// all parsed bytes (i.e., input prefix consumed by parse() calls) | |
78 | /// meaningless unless preserveParsed_ is true | |
79 | SBuf parsed_; | |
7a010fb2 | 80 | bool preserveParsed_ = false; ///< whether to accumulate parsed bytes (in parsed_) |
c99510dd AJ |
81 | }; |
82 | ||
83 | } // namespace One | |
84 | } // namespace Http | |
85 | ||
86 | #endif /* _SQUID_SRC_HTTP_ONE_REQUESTPARSER_H */ | |
f53969cc | 87 |