2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_SRC_HTTP_ONE_TeChunkedParser_H
10 #define SQUID_SRC_HTTP_ONE_TeChunkedParser_H
12 #include "http/one/Parser.h"
21 using ::Parser::InsufficientInput
;
23 // TODO: Move this class into http/one/ChunkExtensionValueParser.*
24 /// A customizable parser of a single chunk extension value (chunk-ext-val).
25 /// From RFC 7230 section 4.1.1 and its Errata #4667:
26 /// chunk-ext = *( BWS ";" BWS chunk-ext-name [ BWS "=" BWS chunk-ext-val ] )
27 /// chunk-ext-name = token
28 /// chunk-ext-val = token / quoted-string
29 class ChunkExtensionValueParser
32 typedef ::Parser::Tokenizer Tokenizer
;
34 /// extracts and ignores the value of a named extension
35 static void Ignore(Tokenizer
&tok
, const SBuf
&extName
);
37 /// extracts and then interprets (or ignores) the extension value
38 virtual void parse(Tokenizer
&tok
, const SBuf
&extName
) = 0;
42 * An incremental parser for chunked transfer coding
43 * defined in RFC 7230 section 4.1.
44 * http://tools.ietf.org/html/rfc7230#section-4.1
46 * The parser shovels content bytes from the raw
47 * input buffer into the content output buffer, both caller-supplied.
48 * Chunk extensions like use-original-body are handled via parseExtensionValuesWith().
49 * Trailers are available via mimeHeader() if wanted.
51 class TeChunkedParser
: public Http1::Parser
55 virtual ~TeChunkedParser() { theOut
=nullptr; /* we do not own this object */ }
57 /// set the buffer to be used to store decoded chunk data
58 void setPayloadBuffer(MemBuf
*parsedContent
) {theOut
= parsedContent
;}
60 /// Instead of ignoring all chunk extension values, give the supplied
61 /// parser a chance to handle them. Only applied to last-chunk (for now).
62 void parseExtensionValuesWith(ChunkExtensionValueParser
*parser
) { customExtensionValueParser
= parser
; }
64 bool needsMoreSpace() const;
66 /* Http1::Parser API */
68 virtual bool parse(const SBuf
&);
69 virtual Parser::size_type
firstLineSize() const {return 0;} // has no meaning with multiple chunks
72 bool parseChunkSize(Tokenizer
&tok
);
73 bool parseChunkMetadataSuffix(Tokenizer
&);
74 void parseChunkExtensions(Tokenizer
&);
75 void parseOneChunkExtension(Tokenizer
&);
76 bool parseChunkBody(Tokenizer
&tok
);
77 bool parseChunkEnd(Tokenizer
&tok
);
80 uint64_t theChunkSize
;
81 uint64_t theLeftBodySize
;
83 /// An optional plugin for parsing and interpreting custom chunk-ext-val.
84 /// This "visitor" object is owned by our creator.
85 ChunkExtensionValueParser
*customExtensionValueParser
;
91 #endif /* SQUID_SRC_HTTP_ONE_TeChunkedParser_H */