diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-08-21 13:42:32 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-08-21 13:56:09 +0300 |
commit | 3391579f10b1bab2f82c4ea4921c794ab67e0d8b (patch) | |
tree | 0fb21299329110e5597fbf857ab902e9cc84afd9 /library/cpp | |
parent | 84b94f3b97a138085aafa50e6b06a49a8d742256 (diff) | |
download | ydb-3391579f10b1bab2f82c4ea4921c794ab67e0d8b.tar.gz |
Intermediate changes
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/http/push_parser/http_parser.cpp | 20 | ||||
-rw-r--r-- | library/cpp/http/push_parser/http_parser.h | 7 |
2 files changed, 13 insertions, 14 deletions
diff --git a/library/cpp/http/push_parser/http_parser.cpp b/library/cpp/http/push_parser/http_parser.cpp index b69818c15c..a646b349a3 100644 --- a/library/cpp/http/push_parser/http_parser.cpp +++ b/library/cpp/http/push_parser/http_parser.cpp @@ -261,13 +261,9 @@ void THttpParser::OnEof() { throw THttpException() << TStringBuf("incompleted http response"); } -bool THttpParser::DecodeContent() { - if (!DecodeContent_) { - return false; - } - +bool THttpParser::DecodeContent(TString& decodedContent) const { if (!ContentEncoding_ || ContentEncoding_ == "identity" || ContentEncoding_ == "none") { - DecodedContent_ = Content_; + decodedContent = Content_; return false; } @@ -277,7 +273,7 @@ bool THttpParser::DecodeContent() { if (!GzipAllowMultipleStreams_) { decompressor.SetAllowMultipleStreams(false); } - DecodedContent_ = decompressor.ReadAll(); + decodedContent = decompressor.ReadAll(); } else if (ContentEncoding_ == "deflate") { //https://tools.ietf.org/html/rfc1950 @@ -291,14 +287,14 @@ bool THttpParser::DecodeContent() { } try { - DecodedContent_ = TZLibDecompress(&in, definitelyNoZlibHeader ? ZLib::Raw : ZLib::ZLib).ReadAll(); + decodedContent = TZLibDecompress(&in, definitelyNoZlibHeader ? ZLib::Raw : ZLib::ZLib).ReadAll(); } catch(...) { if (definitelyNoZlibHeader) { throw; } TMemoryInput retryInput(Content_.data(), Content_.size()); - DecodedContent_ = TZLibDecompress(&retryInput, ZLib::Raw).ReadAll(); + decodedContent = TZLibDecompress(&retryInput, ZLib::Raw).ReadAll(); } } else if (ContentEncoding_.StartsWith("z-")) { // opposite for library/cpp/http/io/stream.h @@ -313,13 +309,13 @@ bool THttpParser::DecodeContent() { throw THttpParseException() << "Unsupported content-encoding method: " << exc.AsStrBuf(); } NBlockCodecs::TDecodedInput decoder(&in, codec); - DecodedContent_ = decoder.ReadAll(); + decodedContent = decoder.ReadAll(); } else if (ContentEncoding_ == "lz4") { const auto* codec = NBlockCodecs::Codec(TStringBuf(ContentEncoding_)); - DecodedContent_ = codec->Decode(Content_); + decodedContent = codec->Decode(Content_); } else if (ContentEncoding_ == "br") { TBrotliDecompress decoder(&in); - DecodedContent_ = decoder.ReadAll(); + decodedContent = decoder.ReadAll(); } else { throw THttpParseException() << "Unsupported content-encoding method: " << ContentEncoding_; } diff --git a/library/cpp/http/push_parser/http_parser.h b/library/cpp/http/push_parser/http_parser.h index a9a9186ba4..af3ce46dbd 100644 --- a/library/cpp/http/push_parser/http_parser.h +++ b/library/cpp/http/push_parser/http_parser.h @@ -53,7 +53,9 @@ public: /// sz == 0 signaling end of input stream bool Parse(const char* data, size_t sz) { if (ParseImpl(data, sz)) { - DecodeContent(); + if (DecodeContent_) { + DecodeContent(DecodedContent_); + } return true; } return false; @@ -111,6 +113,8 @@ public: FirstLine_.reserve(128); } + bool DecodeContent(TString& decodedContent) const; + private: bool ParseImpl(const char* data, size_t sz) { Data_ = data; @@ -135,7 +139,6 @@ private: void ParseHeaderLine(); void OnEof(); - bool DecodeContent(); void ApplyHeaderLine(const TStringBuf& name, const TStringBuf& val); |