#include <TeChunkedParser.h>

Inheritance diagram for Http::One::TeChunkedParser:
Collaboration diagram for Http::One::TeChunkedParser:

Public Types

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

Public Member Functions

 TeChunkedParser ()
virtual ~TeChunkedParser ()
void setPayloadBuffer (MemBuf *parsedContent)
 set the buffer to be used to store decoded chunk data More...
void parseExtensionValuesWith (ChunkExtensionValueParser *parser)
bool needsMoreSpace () const
virtual void clear ()
virtual bool parse (const SBuf &)
virtual Parser::size_type firstLineSize () const
 size in bytes of the first line including CRLF terminator 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

bool parseChunkSize (Tokenizer &tok)
 RFC 7230 section 4.1 chunk-size. More...
bool parseChunkMetadataSuffix (Tokenizer &)
void parseChunkExtensions (Tokenizer &)
void parseOneChunkExtension (Tokenizer &)
bool parseChunkBody (Tokenizer &tok)
bool parseChunkEnd (Tokenizer &tok)

Private Attributes

uint64_t theChunkSize
uint64_t theLeftBodySize

Detailed Description

An incremental parser for chunked transfer coding defined in RFC 7230 section 4.1. http://tools.ietf.org/html/rfc7230#section-4.1

The parser shovels content bytes from the raw input buffer into the content output buffer, both caller-supplied. Chunk extensions like use-original-body are handled via parseExtensionValuesWith(). Trailers are available via mimeHeader() if wanted.

Definition at line 51 of file TeChunkedParser.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

◆ TeChunkedParser()

Http::One::TeChunkedParser::TeChunkedParser ( )

◆ ~TeChunkedParser()

virtual Http::One::TeChunkedParser::~TeChunkedParser ( )

Definition at line 55 of file TeChunkedParser.h.

Member Function Documentation

◆ clear()

void Http::One::TeChunkedParser::clear ( )

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

Implements Http::One::Parser.

Definition at line 31 of file TeChunkedParser.cc.

References Http::One::Parser::buf_, SBuf::clear(), Http::One::HTTP_PARSE_NONE, NULL, Http::One::Parser::parsingStage_, theChunkSize, theLeftBodySize, and theOut.

Referenced by TeChunkedParser().

◆ DelimiterCharacters()

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

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

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

◆ firstLineSize()

virtual Parser::size_type Http::One::TeChunkedParser::firstLineSize ( ) const

Implements Http::One::Parser.

Definition at line 69 of file TeChunkedParser.h.

◆ getHeaderField()

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, 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 

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 Http::One::RequestParser::doParse(), Http::One::ResponseParser::parse(), and parse().

◆ headerBlockSize()

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 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().

◆ messageHeaderSize()

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 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

◆ mimeHeader()

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

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

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 Http::One::RequestParser::doParse(), Http::One::ResponseParser::parse(), parse(), Adaptation::Icap::ModXact::parseBody(), parseChunkBody(), testHttp1Parser::testDripFeed(), testHttp1Parser::testParserConstruct(), and testResults().

◆ needsMoreSpace()

bool Http::One::TeChunkedParser::needsMoreSpace ( ) const

◆ parse()

◆ parseChunkBody()

◆ parseChunkEnd()

bool Http::One::TeChunkedParser::parseChunkEnd ( Tokenizer tok)

◆ parseChunkExtensions()

void Http::One::TeChunkedParser::parseChunkExtensions ( Tokenizer tok)

Parses the chunk-ext list (RFC 7230 section 4.1.1 and its Errata #4667): chunk-ext = *( BWS ";" BWS chunk-ext-name [ BWS "=" BWS chunk-ext-val ] )

Definition at line 138 of file TeChunkedParser.cc.

References Http::One::Parser::buf_, Http::One::ParseBws(), and parseOneChunkExtension().

Referenced by parseChunkMetadataSuffix().

◆ parseChunkMetadataSuffix()

bool Http::One::TeChunkedParser::parseChunkMetadataSuffix ( Tokenizer tok)

Parses "[chunk-ext] CRLF" from RFC 7230 section 4.1.1: chunk = chunk-size [ chunk-ext ] CRLF chunk-data CRLF last-chunk = 1*"0" [ chunk-ext ] CRLF

Definition at line 118 of file TeChunkedParser.cc.

References Http::One::Parser::buf_, Http::One::HTTP_PARSE_CHUNK, Http::One::HTTP_PARSE_MIME, parseChunkExtensions(), Http::One::Parser::parsingStage_, Http::One::Parser::skipLineTerminator(), and theChunkSize.

Referenced by parse().

◆ parseChunkSize()

bool Http::One::TeChunkedParser::parseChunkSize ( Tokenizer tok)

◆ parseExtensionValuesWith()

void Http::One::TeChunkedParser::parseExtensionValuesWith ( ChunkExtensionValueParser parser)

Instead of ignoring all chunk extension values, give the supplied parser a chance to handle them. Only applied to last-chunk (for now).

Definition at line 62 of file TeChunkedParser.h.

References Http::One::ChunkExtensionValueParser::parse().

Referenced by Adaptation::Icap::ModXact::decideOnParsingBody().

◆ parseOneChunkExtension()

void Http::One::TeChunkedParser::parseOneChunkExtension ( Tokenizer tok)

Parses a single chunk-ext list element: chunk-ext = *( BWS ";" BWS chunk-ext-name [ BWS "=" BWS chunk-ext-val ] )

Definition at line 161 of file TeChunkedParser.cc.

References customExtensionValueParser, Http::One::ChunkExtensionValueParser::Ignore(), Http::One::ChunkExtensionValueParser::parse(), Http::One::ParseBws(), CharacterSet::TCHAR, and theChunkSize.

Referenced by parseChunkExtensions().

◆ remaining()

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

◆ setPayloadBuffer()

void Http::One::TeChunkedParser::setPayloadBuffer ( MemBuf parsedContent)

◆ skipLineTerminator()

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

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

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 parseChunkEnd(), parseChunkMetadataSuffix(), and Http::One::ResponseParser::parseResponseStatusAndReason().

◆ WhitespaceCharacters()

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 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_

◆ customExtensionValueParser

ChunkExtensionValueParser* Http::One::TeChunkedParser::customExtensionValueParser

An optional plugin for parsing and interpreting custom chunk-ext-val. This "visitor" object is owned by our creator.

Definition at line 85 of file TeChunkedParser.h.

Referenced by parseOneChunkExtension().

◆ hackExpectsMime_

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

Definition at line 160 of file Parser.h.

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

◆ Http1magic

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

◆ mimeHeaderBlock_

◆ msgProtocol_

◆ parseStatusCode

◆ parsingStage_

◆ theChunkSize

uint64_t Http::One::TeChunkedParser::theChunkSize

◆ theLeftBodySize

uint64_t Http::One::TeChunkedParser::theLeftBodySize

Definition at line 81 of file TeChunkedParser.h.

Referenced by clear(), parseChunkBody(), parseChunkEnd(), and parseChunkSize().

◆ theOut

MemBuf* Http::One::TeChunkedParser::theOut

Definition at line 79 of file TeChunkedParser.h.

Referenced by clear(), needsMoreSpace(), parse(), and parseChunkBody().

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






Web Site Translations