diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2023-09-18 13:07:44 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2023-09-18 13:27:47 +0300 |
commit | 1c65609dbbbc8bdc00ee5138f0c0385e4c07c298 (patch) | |
tree | 4360513a459f3f24ca88d1f7cf79255862dc1125 /library/cpp | |
parent | 1a51d3f4e6a171eb78d2a4b41719a4a07541e3e3 (diff) | |
download | ydb-1c65609dbbbc8bdc00ee5138f0c0385e4c07c298.tar.gz |
Intermediate changes
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/http/push_parser/http_parser.cpp | 6 | ||||
-rw-r--r-- | library/cpp/http/push_parser/http_parser.h | 10 |
2 files changed, 13 insertions, 3 deletions
diff --git a/library/cpp/http/push_parser/http_parser.cpp b/library/cpp/http/push_parser/http_parser.cpp index 5852a02d5b..b69818c15c 100644 --- a/library/cpp/http/push_parser/http_parser.cpp +++ b/library/cpp/http/push_parser/http_parser.cpp @@ -108,7 +108,7 @@ bool THttpParser::HeadersParser() { bool THttpParser::ContentParser() { DBGOUT("Content parsing()"); - if (HasContentLength_) { + if (HasContentLength_ && !BodyNotExpected_) { size_t rd = Min<size_t>(DataEnd_ - Data_, ContentLength_ - Content_.size()); Content_.append(Data_, rd); Data_ += rd; @@ -119,8 +119,8 @@ bool THttpParser::ContentParser() { } else { if (MessageType_ == Request) { return OnEndParsing(); //RFC2616 4.4-5 - } else if (Y_UNLIKELY(RetCode() < 200 || RetCode() == 204 || RetCode() == 304)) { - return OnEndParsing(); //RFC2616 4.4-1 (but not checked HEAD request type !) + } else if (Y_UNLIKELY(BodyNotExpected_ || RetCode() < 200 || RetCode() == 204 || RetCode() == 304)) { + return OnEndParsing(); //RFC2616 4.4-1 } Content_.append(Data_, DataEnd_); diff --git a/library/cpp/http/push_parser/http_parser.h b/library/cpp/http/push_parser/http_parser.h index c888235c33..a9a9186ba4 100644 --- a/library/cpp/http/push_parser/http_parser.h +++ b/library/cpp/http/push_parser/http_parser.h @@ -40,6 +40,14 @@ public: DecodeContent_ = false; } + /* + * Disable message-body parsing. + * Useful for parse HEAD method responses + */ + inline void BodyNotExpected() { + BodyNotExpected_ = true; + } + /// @return true on end parsing (GetExtraDataSize() return amount not used bytes) /// throw exception on bad http format (unsupported encoding, etc) /// sz == 0 signaling end of input stream @@ -54,6 +62,7 @@ public: const char* Data() const noexcept { return Data_; } + size_t GetExtraDataSize() const noexcept { return ExtraDataSize_; } @@ -137,6 +146,7 @@ private: bool CollectHeaders_ = true; bool GzipAllowMultipleStreams_ = true; bool DecodeContent_ = true; + bool BodyNotExpected_ = false; // parsed data const char* Data_ = nullptr; |