#include <RequestParser.h>

Inheritance diagram for Http::One::RequestParser:
Collaboration diagram for Http::One::RequestParser:

Public Types

typedef SBuf::size_type size_type
 
typedef ::Parser::Tokenizer Tokenizer
 

Public Member Functions

 RequestParser ()=default
 
 RequestParser (bool preserveParsed)
 
 RequestParser (const RequestParser &)=default
 
RequestParseroperator= (const RequestParser &)=default
 
 RequestParser (RequestParser &&)=default
 
RequestParseroperator= (RequestParser &&)=default
 
virtual ~RequestParser ()
 
virtual void clear ()
 
virtual Http1::Parser::size_type firstLineSize () const
 size in bytes of the first line including CRLF terminator More...
 
virtual bool parse (const SBuf &aBuf)
 
const HttpRequestMethodmethod () const
 the HTTP method if this is a request message More...
 
const SBufrequestUri () const
 the request-line URI if this is a request message, or an empty string. More...
 
const SBufparsed () const
 the accumulated parsed bytes More...
 
bool needsMoreData () const
 
size_type headerBlockSize () const
 
size_type messageHeaderSize () const
 
SBuf mimeHeader () const
 buffer containing HTTP mime headers, excluding message first-line. More...
 
const AnyP::ProtocolVersionmessageProtocol () const
 the protocol label for this message More...
 
char * getHeaderField (const char *name)
 
const SBufremaining () const
 the remaining unprocessed section of buffer More...
 

Static Public Member Functions

static const CharacterSetWhitespaceCharacters ()
 
static const CharacterSetDelimiterCharacters ()
 

Public Attributes

Http::StatusCode parseStatusCode = Http::scNone
 

Protected Member Functions

void skipLineTerminator (Tokenizer &) const
 
bool grabMimeBlock (const char *which, const size_t limit)
 

Protected Attributes

SBuf buf_
 bytes remaining to be parsed More...
 
ParseState parsingStage_ = HTTP_PARSE_NONE
 what stage the parser is currently up to More...
 
AnyP::ProtocolVersion msgProtocol_
 what protocol label has been found in the first line (if any) More...
 
SBuf mimeHeaderBlock_
 buffer holding the mime headers (if any) More...
 
bool hackExpectsMime_ = false
 Whether the invalid HTTP as HTTP/0.9 hack expects a mime header block. More...
 

Static Protected Attributes

static const SBuf Http1magic
 RFC 7230 section 2.6 - 7 magic octets. More...
 

Private Member Functions

void skipGarbageLines ()
 
int parseRequestFirstLine ()
 
bool doParse (const SBuf &aBuf)
 called from parse() to do the parsing More...
 
bool parseMethodField (Tokenizer &)
 
bool parseUriField (Tokenizer &)
 
bool parseHttpVersionField (Tokenizer &)
 
bool skipDelimiter (const size_t count, const char *where)
 
bool skipTrailingCrs (Tokenizer &tok)
 Parse CRs at the end of request-line, just before the terminating LF. More...
 
bool http0 () const
 

Static Private Member Functions

static const CharacterSetRequestTargetCharacters ()
 characters which Squid will accept in the HTTP request-target (URI) More...
 

Private Attributes

HttpRequestMethod method_
 what request method has been found on the first line More...
 
SBuf uri_
 raw copy of the original client request-line URI field More...
 
SBuf parsed_
 
bool preserveParsed_ = false
 whether to accumulate parsed bytes (in parsed_) More...
 

Detailed Description

HTTP/1.x protocol request parser

Works on a raw character I/O buffer and tokenizes the content into the major CRLF delimited segments of an HTTP/1 request message:

  • request-line (method, URL, protocol, version)
  • mime-header (set of RFC2616 syntax header fields)

Definition at line 30 of file RequestParser.h.

Member Typedef Documentation

◆ size_type

Definition at line 43 of file Parser.h.

◆ Tokenizer

Definition at line 44 of file Parser.h.

Constructor & Destructor Documentation

◆ RequestParser() [1/4]

Http::One::RequestParser::RequestParser ( )
default

◆ RequestParser() [2/4]

Http::One::RequestParser::RequestParser ( bool  preserveParsed)
inline

Definition at line 34 of file RequestParser.h.

◆ RequestParser() [3/4]

Http::One::RequestParser::RequestParser ( const RequestParser )
default

◆ RequestParser() [4/4]

Http::One::RequestParser::RequestParser ( RequestParser &&  )
default

◆ ~RequestParser()

virtual Http::One::RequestParser::~RequestParser ( )
inlinevirtual

Definition at line 39 of file RequestParser.h.

Member Function Documentation

◆ clear()

virtual void Http::One::RequestParser::clear ( )
inlinevirtual

◆ DelimiterCharacters()

const CharacterSet & Http::One::Parser::DelimiterCharacters ( )
staticinherited

Whitespace between protocol elements in restricted contexts like request line, status line, asctime-date, and credentials Seen in RFCs as SP but may be "relaxed" by us. See also: WhitespaceCharacters(). XXX: Misnamed and overused.

Definition at line 59 of file Parser.cc.

References Config, SquidConfig::onoff, SquidConfig::relaxed_header_parser, RelaxedDelimiterCharacters(), and CharacterSet::SP.

Referenced by Http::ContentLengthInterpreter::goodSuffix(), parseMethodField(), parseRequestFirstLine(), Http::One::ResponseParser::parseResponseFirstLine(), and RequestTargetCharacters().

◆ doParse()

◆ firstLineSize()

Http1::Parser::size_type Http::One::RequestParser::firstLineSize ( ) const
virtual

Implements Http::One::Parser.

Definition at line 18 of file RequestParser.cc.

References HttpRequestMethod::image(), SBuf::length(), method_, and uri_.

◆ getHeaderField()

char * Http::One::Parser::getHeaderField ( const char *  name)
inherited

Scan the mime header block (badly) for a header with the given name.

BUG: omits lines when searching for headers with obs-fold or multiple entries.

BUG: limits output to just 1KB when Squid accepts up to 64KB line length.

Returns
A pointer to a field-value of the first matching field-name, or NULL.

Definition at line 219 of file Parser.cc.

References SBuf::caseCmp(), SBuf::chop(), SBuf::consume(), Http::One::CrLf(), debugs, GET_HDR_SZ, Http::One::Parser::headerBlockSize(), CharacterSet::LF, LineCharacters(), LOCAL_ARRAY, Http::One::Parser::mimeHeaderBlock_, NULL, p, SBufToCstring(), SBuf::substr(), SBuf::trim(), and CharacterSet::WSP.

Referenced by Http::One::Parser::messageProtocol().

◆ grabMimeBlock()

bool Http::One::Parser::grabMimeBlock ( const char *  which,
const size_t  limit 
)
protectedinherited

Scan to find the mime headers block for current message.

Return values
trueIf mime block (or a blocks non-existence) has been identified accurately within limit characters. mimeHeaderBlock_ has been updated and buf_ consumed.
falseAn error occurred, or no mime terminator found within limit.

Definition at line 163 of file Parser.cc.

References Http::One::Parser::buf_, Http::One::Parser::cleanMimePrefix(), SBuf::consume(), debugs, Http::One::Parser::firstLineSize(), Http::One::Parser::hackExpectsMime_, headersEnd(), Http::One::HTTP_PARSE_DONE, SBuf::length(), AnyP::ProtocolVersion::major, Http::One::Parser::mimeHeaderBlock_, Http::One::Parser::msgProtocol_, Http::One::Parser::parseStatusCode, Http::One::Parser::parsingStage_, AnyP::PROTO_HTTP, AnyP::PROTO_ICY, AnyP::ProtocolVersion::protocol, Http::scHeaderTooLarge, and Http::One::Parser::unfoldMime().

Referenced by doParse(), Http::One::ResponseParser::parse(), and Http::One::TeChunkedParser::parse().

◆ headerBlockSize()

size_type Http::One::Parser::headerBlockSize ( ) const
inlineinherited

size in bytes of the message headers including CRLF terminator(s) but excluding first-line bytes

Definition at line 73 of file Parser.h.

References SBuf::length(), and Http::One::Parser::mimeHeaderBlock_.

Referenced by Http::One::Parser::getHeaderField(), Http::One::Parser::messageHeaderSize(), and Http::Message::parseHeader().

◆ http0()

bool Http::One::RequestParser::http0 ( ) const
inlineprivate

Definition at line 68 of file RequestParser.h.

Referenced by parseRequestFirstLine().

◆ messageHeaderSize()

size_type Http::One::Parser::messageHeaderSize ( ) const
inlineinherited

size in bytes of HTTP message block, includes first-line and mime headers excludes any body/entity/payload bytes excludes any garbage prefix before the first-line

Definition at line 78 of file Parser.h.

References Http::One::Parser::firstLineSize(), and Http::One::Parser::headerBlockSize().

Referenced by Http::Message::parseHeader().

◆ messageProtocol()

const AnyP::ProtocolVersion& Http::One::Parser::messageProtocol ( ) const
inlineinherited

◆ method()

const HttpRequestMethod& Http::One::RequestParser::method ( ) const
inline

Definition at line 47 of file RequestParser.h.

◆ mimeHeader()

SBuf Http::One::Parser::mimeHeader ( ) const
inlineinherited

Definition at line 81 of file Parser.h.

References Http::One::Parser::mimeHeaderBlock_.

Referenced by Http::Message::parseHeader().

◆ needsMoreData()

bool Http::One::Parser::needsMoreData ( ) const
inlineinherited

Whether the parser is waiting on more data to complete parsing a message. Use to distinguish between incomplete data and error results when parse() returns false.

Definition at line 66 of file Parser.h.

References Http::One::Parser::firstLineSize(), Http::One::HTTP_PARSE_DONE, and Http::One::Parser::parsingStage_.

Referenced by doParse(), Http::One::ResponseParser::parse(), Http::One::TeChunkedParser::parse(), Adaptation::Icap::ModXact::parseBody(), Http::One::TeChunkedParser::parseChunkBody(), testHttp1Parser::testDripFeed(), testHttp1Parser::testParserConstruct(), and testResults().

◆ operator=() [1/2]

RequestParser& Http::One::RequestParser::operator= ( const RequestParser )
default

◆ operator=() [2/2]

RequestParser& Http::One::RequestParser::operator= ( RequestParser &&  )
default

◆ parse()

bool Http::One::RequestParser::parse ( const SBuf aBuf)
virtual

attempt to parse a message from the buffer

Return values
trueif a full message was found and parsed
falseif incomplete, invalid or no message was found

Implements Http::One::Parser.

Definition at line 338 of file RequestParser.cc.

References SBuf::append(), assert, doParse(), SBuf::length(), parsed_, preserveParsed_, Http::One::Parser::remaining(), and SBuf::substr().

Referenced by testResults().

◆ parsed()

const SBuf& Http::One::RequestParser::parsed ( ) const
inline

Definition at line 53 of file RequestParser.h.

References Must.

◆ parseHttpVersionField()

◆ parseMethodField()

bool Http::One::RequestParser::parseMethodField ( Tokenizer tok)
private

Attempt to parse the method field out of an HTTP message request-line.

Governed by: RFC 1945 section 5.1 RFC 7230 section 2.6, 3.1 and 3.5

Definition at line 62 of file RequestParser.cc.

References debugs, Http::One::Parser::DelimiterCharacters(), Http::One::ErrorLevel(), method_, Http::One::Parser::parseStatusCode, Http::scBadRequest, skipDelimiter(), and CharacterSet::TCHAR.

Referenced by parseRequestFirstLine().

◆ parseRequestFirstLine()

int Http::One::RequestParser::parseRequestFirstLine ( )
private

Attempt to parse the first line of a new request message.

Governed by: RFC 1945 section 5.1 RFC 7230 section 2.6, 3.1 and 3.5

Return values
-1an error occurred. parseStatusCode indicates HTTP status result.
1successful parse. member fields contain the request-line items
0more data is needed to complete the parse

Definition at line 277 of file RequestParser.cc.

References Http::One::Parser::buf_, CharacterSet::complement(), Config, DBG_DATA, debugs, Http::One::Parser::DelimiterCharacters(), Http::One::ErrorLevel(), http0(), SBuf::length(), CharacterSet::LF, SquidConfig::maxRequestHeaderSize, parseHttpVersionField(), parseMethodField(), Http::One::Parser::parseStatusCode, parseUriField(), Http::scBadRequest, Http::scOkay, Http::scUriTooLong, skipDelimiter(), and skipTrailingCrs().

Referenced by doParse().

◆ parseUriField()

bool Http::One::RequestParser::parseUriField ( Tokenizer tok)
private

◆ remaining()

const SBuf& Http::One::Parser::remaining ( ) const
inlineinherited

◆ RequestTargetCharacters()

const CharacterSet & Http::One::RequestParser::RequestTargetCharacters ( )
staticprivate

◆ requestUri()

const SBuf& Http::One::RequestParser::requestUri ( ) const
inline

Definition at line 50 of file RequestParser.h.

◆ skipDelimiter()

bool Http::One::RequestParser::skipDelimiter ( const size_t  count,
const char *  where 
)
private

Skip characters separating request-line fields. To handle bidirectional parsing, the caller does the actual skipping and we just check how many character the caller has skipped.

Definition at line 231 of file RequestParser.cc.

References Config, debugs, Http::One::ErrorLevel(), SquidConfig::onoff, Http::One::Parser::parseStatusCode, SquidConfig::relaxed_header_parser, and Http::scBadRequest.

Referenced by parseMethodField(), and parseRequestFirstLine().

◆ skipGarbageLines()

void Http::One::RequestParser::skipGarbageLines ( )
private

Attempt to parse the first line of a new request message.

Governed by RFC 7230 section 3.5 " In the interest of robustness, a server that is expecting to receive and parse a request-line SHOULD ignore at least one empty line (CRLF) received prior to the request-line. "

Parsing state is stored between calls to avoid repeating buffer scans. If garbage is found the parsing offset is incremented.

Definition at line 39 of file RequestParser.cc.

References Http::One::Parser::buf_, Config, SBuf::consume(), DBG_IMPORTANT, debugs, SBuf::isEmpty(), SquidConfig::onoff, and SquidConfig::relaxed_header_parser.

Referenced by doParse().

◆ skipLineTerminator()

void Http::One::Parser::skipLineTerminator ( Tokenizer tok) const
protectedinherited

detect and skip the CRLF or (if tolerant) LF line terminator consume from the tokenizer.

Exceptions
exceptionon bad or InsuffientInput.
Return values
trueonly if line terminator found.
falseincomplete or missing line terminator, need more data.

Definition at line 66 of file Parser.cc.

References Config, Http::One::CrLf(), CharacterSet::LF, SquidConfig::onoff, SquidConfig::relaxed_header_parser, and TexcHere.

Referenced by Http::One::TeChunkedParser::parseChunkEnd(), Http::One::TeChunkedParser::parseChunkMetadataSuffix(), and Http::One::ResponseParser::parseResponseStatusAndReason().

◆ skipTrailingCrs()

bool Http::One::RequestParser::skipTrailingCrs ( Tokenizer tok)
private

◆ WhitespaceCharacters()

const CharacterSet & Http::One::Parser::WhitespaceCharacters ( )
staticinherited

Whitespace between regular protocol elements. Seen in RFCs as OWS, RWS, BWS, SP/HTAB but may be "relaxed" by us. See also: DelimiterCharacters().

Definition at line 52 of file Parser.cc.

References Config, SquidConfig::onoff, SquidConfig::relaxed_header_parser, RelaxedDelimiterCharacters(), and CharacterSet::WSP.

Referenced by Http::One::ParseBws().

Member Data Documentation

◆ buf_

◆ hackExpectsMime_

bool Http::One::Parser::hackExpectsMime_ = false
protectedinherited

Definition at line 160 of file Parser.h.

Referenced by Http::One::Parser::grabMimeBlock().

◆ Http1magic

const SBuf Http::One::Parser::Http1magic
staticprotectedinherited

◆ method_

HttpRequestMethod Http::One::RequestParser::method_
private

◆ mimeHeaderBlock_

◆ msgProtocol_

◆ parsed_

SBuf Http::One::RequestParser::parsed_
private

all parsed bytes (i.e., input prefix consumed by parse() calls) meaningless unless preserveParsed_ is true

Definition at line 79 of file RequestParser.h.

Referenced by parse().

◆ parseStatusCode

Http::StatusCode Http::One::Parser::parseStatusCode = Http::scNone
inherited

HTTP status code resulting from the parse process. to be used on the invalid message handling.

Http::scNone indicates incomplete parse, Http::scOkay indicates no error, other codes represent a parse error.

Definition at line 108 of file Parser.h.

Referenced by doParse(), Http::One::Parser::grabMimeBlock(), Http::One::ResponseParser::parse(), parseHttpVersionField(), parseMethodField(), parseRequestFirstLine(), parseUriField(), skipDelimiter(), skipTrailingCrs(), testHttp1Parser::testParserConstruct(), and testResults().

◆ parsingStage_

◆ preserveParsed_

bool Http::One::RequestParser::preserveParsed_ = false
private

Definition at line 80 of file RequestParser.h.

Referenced by parse().

◆ uri_

SBuf Http::One::RequestParser::uri_
private

The documentation for this class was generated from the following files:

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors