Browse Source

Intermediate changes

robot-piglet 1 year ago
parent
commit
1c65609dbb

+ 3 - 3
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_);

+ 10 - 0
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;