Squid Web Cache master
Loading...
Searching...
No Matches
RequestParser.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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_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"
14
15namespace Parser {
16class Tokenizer;
17}
18
19namespace Http {
20namespace One {
21
31{
32public:
33 RequestParser() = default;
34 RequestParser(bool preserveParsed) { preserveParsed_ = preserveParsed; }
35 RequestParser(const RequestParser &) = default;
39 ~RequestParser() override {}
40
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;
45
47 const HttpRequestMethod & method() const {return method_;}
48
50 const SBuf &requestUri() const {return uri_;}
51
53 const SBuf &parsed() const { Must(preserveParsed_); return parsed_; }
54
55private:
56 void skipGarbageLines();
59 bool doParse(const SBuf &aBuf);
60
61 /* all these return false and set parseStatusCode on parsing failures */
65 bool skipDelimiter(const size_t count, const char *where);
67
68 bool http0() const {return !msgProtocol_.major;}
70
73
76
80 bool preserveParsed_ = false;
81};
82
83} // namespace One
84} // namespace Http
85
86#endif /* SQUID_SRC_HTTP_ONE_REQUESTPARSER_H */
87
#define Must(condition)
unsigned int major
major version number
optimized set of C chars, with quick membership test and merge support
AnyP::ProtocolVersion msgProtocol_
what protocol label has been found in the first line (if any)
Definition Parser.h:152
::Parser::Tokenizer Tokenizer
Definition Parser.h:44
bool parseMethodField(Tokenizer &)
bool doParse(const SBuf &aBuf)
called from parse() to do the parsing
Http1::Parser::size_type firstLineSize() const override
size in bytes of the first line including CRLF terminator
static const CharacterSet & RequestTargetCharacters()
characters which Squid will accept in the HTTP request-target (URI)
RequestParser(const RequestParser &)=default
bool parse(const SBuf &aBuf) override
const SBuf & requestUri() const
the request-line URI if this is a request message, or an empty string.
bool skipDelimiter(const size_t count, const char *where)
bool parseHttpVersionField(Tokenizer &)
HttpRequestMethod method_
what request method has been found on the first line
RequestParser(RequestParser &&)=default
bool parseUriField(Tokenizer &)
SBuf uri_
raw copy of the original client request-line URI field
RequestParser(bool preserveParsed)
const SBuf & parsed() const
the accumulated parsed bytes
const HttpRequestMethod & method() const
the HTTP method if this is a request message
RequestParser & operator=(const RequestParser &)=default
bool preserveParsed_
whether to accumulate parsed bytes (in parsed_)
bool skipTrailingCrs(Tokenizer &tok)
Parse CRs at the end of request-line, just before the terminating LF.
Definition SBuf.h:94
Definition forward.h:18
Generic protocol-agnostic parsing tools.
Definition parse.c:160