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