]>
Commit | Line | Data |
---|---|---|
774c051c | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
774c051c | 3 | * |
bbc27441 AJ |
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. | |
774c051c | 7 | */ |
bbc27441 | 8 | |
ff9d9458 FC |
9 | #ifndef SQUID_SRC_HTTP_ONE_TECHUNKEDPARSER_H |
10 | #define SQUID_SRC_HTTP_ONE_TECHUNKEDPARSER_H | |
51c3e7f0 | 11 | |
350ec67a | 12 | #include "http/one/Parser.h" |
774c051c | 13 | |
e1f7507e | 14 | class MemBuf; |
774c051c | 15 | |
51c3e7f0 AJ |
16 | namespace Http |
17 | { | |
18 | namespace One | |
19 | { | |
20 | ||
417da400 EB |
21 | using ::Parser::InsufficientInput; |
22 | ||
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 | |
30 | { | |
31 | public: | |
32 | typedef ::Parser::Tokenizer Tokenizer; | |
33 | ||
34 | /// extracts and ignores the value of a named extension | |
35 | static void Ignore(Tokenizer &tok, const SBuf &extName); | |
36 | ||
37 | /// extracts and then interprets (or ignores) the extension value | |
38 | virtual void parse(Tokenizer &tok, const SBuf &extName) = 0; | |
39 | }; | |
40 | ||
e1f7507e | 41 | /** |
db1720f8 | 42 | * An incremental parser for chunked transfer coding |
51c3e7f0 AJ |
43 | * defined in RFC 7230 section 4.1. |
44 | * http://tools.ietf.org/html/rfc7230#section-4.1 | |
45 | * | |
46 | * The parser shovels content bytes from the raw | |
e1f7507e | 47 | * input buffer into the content output buffer, both caller-supplied. |
417da400 | 48 | * Chunk extensions like use-original-body are handled via parseExtensionValuesWith(). |
be29ee33 | 49 | * Trailers are available via mimeHeader() if wanted. |
e1f7507e | 50 | */ |
db1720f8 | 51 | class TeChunkedParser : public Http1::Parser |
774c051c | 52 | { |
774c051c | 53 | public: |
db1720f8 | 54 | TeChunkedParser(); |
337b9aa4 | 55 | ~TeChunkedParser() override { theOut=nullptr; /* we do not own this object */ } |
774c051c | 56 | |
be29ee33 AJ |
57 | /// set the buffer to be used to store decoded chunk data |
58 | void setPayloadBuffer(MemBuf *parsedContent) {theOut = parsedContent;} | |
774c051c | 59 | |
417da400 EB |
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; } | |
63 | ||
774c051c | 64 | bool needsMoreSpace() const; |
774c051c | 65 | |
350ec67a | 66 | /* Http1::Parser API */ |
337b9aa4 AR |
67 | void clear() override; |
68 | bool parse(const SBuf &) override; | |
69 | Parser::size_type firstLineSize() const override {return 0;} // has no meaning with multiple chunks | |
774c051c | 70 | |
71 | private: | |
417da400 EB |
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); | |
774c051c | 78 | |
774c051c | 79 | MemBuf *theOut; |
47f6e231 | 80 | uint64_t theChunkSize; |
81 | uint64_t theLeftBodySize; | |
83c51da9 | 82 | |
417da400 EB |
83 | /// An optional plugin for parsing and interpreting custom chunk-ext-val. |
84 | /// This "visitor" object is owned by our creator. | |
85 | ChunkExtensionValueParser *customExtensionValueParser; | |
774c051c | 86 | }; |
87 | ||
51c3e7f0 AJ |
88 | } // namespace One |
89 | } // namespace Http | |
90 | ||
ff9d9458 | 91 | #endif /* SQUID_SRC_HTTP_ONE_TECHUNKEDPARSER_H */ |
f53969cc | 92 |