#include <Parser.h>

Inheritance diagram for Http::One::Parser:
Collaboration diagram for Http::One::Parser:

Public Types

typedef SBuf::size_type size_type

Public Member Functions

 Parser ()=default
 Parser (const Parser &)=default
Parseroperator= (const Parser &)=default
 Parser (Parser &&)=default
Parseroperator= (Parser &&)=default
virtual ~Parser ()
virtual void clear ()=0
virtual bool parse (const SBuf &aBuf)=0
bool needsMoreData () const
virtual size_type firstLineSize () const =0
 size in bytes of the first line including CRLF terminator More...
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

bool skipLineTerminator (Http1::Tokenizer &tok) 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 cleanMimePrefix ()
void unfoldMime ()

Detailed Description

HTTP/1.x protocol parser

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

  • first-line (request-line / simple-request / status-line)
  • mime-header 0*( header-name ':' SP field-value CRLF)

Definition at line 39 of file Parser.h.

Member Typedef Documentation

Definition at line 42 of file Parser.h.

Constructor & Destructor Documentation

Http::One::Parser::Parser ( )
Http::One::Parser::Parser ( const Parser )
Http::One::Parser::Parser ( Parser &&  )
virtual Http::One::Parser::~Parser ( )

Definition at line 49 of file Parser.h.

Member Function Documentation

void Http::One::Parser::cleanMimePrefix ( )

Remove invalid lines (if any) from the mime prefix

RFC 7230 section 3: "A recipient that receives whitespace between the start-line and the first header field MUST ... consume each whitespace-preceded line without further processing of it."

We need to always use the relaxed delimiters here to prevent line smuggling through strict parsers.

Note that 'whitespace' in RFC 7230 includes CR. So that means sequences of CRLF will be pruned, but not sequences of bare-LF.

Definition at line 103 of file Parser.cc.

References Parser::Tokenizer::atEnd(), Http::One::CrLf(), CharacterSet::LF, LineCharacters(), RelaxedDelimiterCharacters(), Parser::Tokenizer::remaining(), Parser::Tokenizer::skipAll(), and Parser::Tokenizer::skipOne().

void Http::One::Parser::clear ( )
pure virtual

Set this parser back to a default state. Will DROP any reference to a buffer (does not free).

Implemented in Http::One::TeChunkedParser, Http::One::RequestParser, and Http::One::ResponseParser.

Definition at line 26 of file Parser.cc.

References buf_, SBuf::clear(), Http::One::HTTP_PARSE_NONE, mimeHeaderBlock_, msgProtocol_, NULL, parsingStage_, and Ftp::ProtocolVersion().

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

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 58 of file Parser.cc.

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

Referenced by Http::ContentLengthInterpreter::goodSuffix().

virtual size_type Http::One::Parser::firstLineSize ( ) const
pure virtual
char * Http::One::Parser::getHeaderField ( const char *  name)

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.

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, CharacterSet::LF, LineCharacters(), LOCAL_ARRAY, NULL, p, Parser::Tokenizer::prefix(), Parser::Tokenizer::remaining(), SBufToCstring(), Parser::Tokenizer::skipAll(), Parser::Tokenizer::skipOne(), SBuf::substr(), SBuf::trim(), and CharacterSet::WSP.

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

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 debugs, headersEnd(), Http::One::HTTP_PARSE_DONE, AnyP::PROTO_HTTP, AnyP::PROTO_ICY, and Http::scHeaderTooLarge.

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

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

Definition at line 71 of file Parser.h.

References SBuf::length(), and mimeHeaderBlock_.

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

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

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 76 of file Parser.h.

References firstLineSize(), and headerBlockSize().

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

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

Definition at line 82 of file Parser.h.

References msgProtocol_.

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

Definition at line 79 of file Parser.h.

References mimeHeaderBlock_.

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

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

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 64 of file Parser.h.

References Http::One::HTTP_PARSE_DONE, and parsingStage_.

Referenced by ConnStateData::handleChunkedRequestBody(), testHttp1Parser::testDripFeed(), testHttp1Parser::testParserConstruct(), and testResults().

Parser& Http::One::Parser::operator= ( const Parser )
Parser& Http::One::Parser::operator= ( Parser &&  )
virtual bool Http::One::Parser::parse ( const SBuf aBuf)
pure 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

Implemented in Http::One::RequestParser, Http::One::TeChunkedParser, and Http::One::ResponseParser.

const SBuf& Http::One::Parser::remaining ( ) const
bool Http::One::Parser::skipLineTerminator ( Http1::Tokenizer tok) const

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

throws if non-terminator is detected.

Return values
trueonly if line terminator found.
falseincomplete or missing line terminator, need more data.

Definition at line 65 of file Parser.cc.

References SBuf::at(), Parser::Tokenizer::atEnd(), Config, Http::One::CrLf(), SBuf::length(), CharacterSet::LF, SquidConfig::onoff, SquidConfig::relaxed_header_parser, Parser::Tokenizer::remaining(), Parser::Tokenizer::skip(), Parser::Tokenizer::skipOne(), and TexcHere.

void Http::One::Parser::unfoldMime ( )

Replace obs-fold with a single SP,

RFC 7230 section 3.2.4 "A server that receives an obs-fold in a request message that is not within a message/http container MUST ... replace each received obs-fold with one or more SP octets prior to interpreting the field value or forwarding the message downstream."

"A proxy or gateway that receives an obs-fold in a response message that is not within a message/http container MUST ... replace each received obs-fold with one or more SP octets prior to interpreting the field value or forwarding the message downstream."

Definition at line 138 of file Parser.cc.

References Parser::Tokenizer::atEnd(), CharacterSet::CR, CharacterSet::LF, Parser::Tokenizer::remaining(), CharacterSet::rename(), Parser::Tokenizer::skipAll(), Parser::Tokenizer::skipOne(), and CharacterSet::WSP.

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

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 51 of file Parser.cc.

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

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

Member Data Documentation

SBuf Http::One::Parser::buf_

Definition at line 146 of file Parser.h.

Referenced by clear(), remaining(), testHttp1Parser::testParserConstruct(), and testResults().

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

Definition at line 158 of file Parser.h.

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

Definition at line 143 of file Parser.h.

Referenced by Http::One::ResponseParser::firstLineSize().

SBuf Http::One::Parser::mimeHeaderBlock_

Definition at line 155 of file Parser.h.

Referenced by clear(), headerBlockSize(), and mimeHeader().

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

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 106 of file Parser.h.

Referenced by testHttp1Parser::testParserConstruct(), and testResults().

ParseState Http::One::Parser::parsingStage_ = HTTP_PARSE_NONE

Definition at line 149 of file Parser.h.

Referenced by clear(), needsMoreData(), testHttp1Parser::testParserConstruct(), and testResults().

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






Web Site Translations