aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorxenoxeno <xeno@ydb.tech>2022-08-15 20:08:27 +0300
committerxenoxeno <xeno@ydb.tech>2022-08-15 20:08:27 +0300
commita8d35537b553beaac9e3b10847b9c83f44c5ba9b (patch)
tree954853823fc19469da7c620fa8bc2dc096bc1b4b /library/cpp
parent2f7c14c05b7d0a36336cf6bf025c4173048b9124 (diff)
downloadydb-a8d35537b553beaac9e3b10847b9c83f44c5ba9b.tar.gz
fix content-length 0 in requests
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/actors/http/http.cpp14
-rw-r--r--library/cpp/actors/http/http_ut.cpp12
2 files changed, 23 insertions, 3 deletions
diff --git a/library/cpp/actors/http/http.cpp b/library/cpp/actors/http/http.cpp
index ef25a17a8a..7da6ace0b9 100644
--- a/library/cpp/actors/http/http.cpp
+++ b/library/cpp/actors/http/http.cpp
@@ -108,7 +108,9 @@ void THttpParser<THttpRequest, TSocketBuffer>::Advance(size_t len) {
case EParseStage::Header: {
if (ProcessData(Header, data, "\r\n", MaxHeaderSize)) {
if (Header.empty()) {
- if (HaveBody()) {
+ if (HaveBody() && (ContentLength.empty() || ContentLength != "0")) {
+ Stage = EParseStage::Body;
+ } else if (TotalSize.has_value() && !data.empty()) {
Stage = EParseStage::Body;
} else {
Stage = EParseStage::Done;
@@ -118,7 +120,10 @@ void THttpParser<THttpRequest, TSocketBuffer>::Advance(size_t len) {
}
Headers = TStringBuf(Headers.data(), data.data() - Headers.data());
}
- break;
+ if (Stage != EParseStage::Body) {
+ break;
+ }
+ [[fallthrough]];
}
case EParseStage::Body: {
if (!ContentLength.empty()) {
@@ -271,7 +276,10 @@ void THttpParser<THttpResponse, TSocketBuffer>::Advance(size_t len) {
}
Headers = TStringBuf(Headers.data(), data.data() - Headers.data());
}
- break;
+ if (Stage != EParseStage::Body) {
+ break;
+ }
+ [[fallthrough]];
}
case EParseStage::Body: {
if (!ContentLength.empty()) {
diff --git a/library/cpp/actors/http/http_ut.cpp b/library/cpp/actors/http/http_ut.cpp
index d7d4f5567f..90efd09015 100644
--- a/library/cpp/actors/http/http_ut.cpp
+++ b/library/cpp/actors/http/http_ut.cpp
@@ -139,6 +139,18 @@ Y_UNIT_TEST_SUITE(HttpProxy) {
UNIT_ASSERT_EQUAL(response->Body, "this is test.");
}
+ Y_UNIT_TEST(BasicParsingContentLength0) {
+ NHttp::THttpIncomingRequestPtr request = new NHttp::THttpIncomingRequest();
+ EatPartialString(request, "GET /test HTTP/1.1\r\nHost: test\r\nContent-Length: 0\r\n\r\n");
+ UNIT_ASSERT_EQUAL(request->Stage, NHttp::THttpIncomingRequest::EParseStage::Done);
+ UNIT_ASSERT_EQUAL(request->Method, "GET");
+ UNIT_ASSERT_EQUAL(request->URL, "/test");
+ UNIT_ASSERT_EQUAL(request->Protocol, "HTTP");
+ UNIT_ASSERT_EQUAL(request->Version, "1.1");
+ UNIT_ASSERT_EQUAL(request->Host, "test");
+ UNIT_ASSERT_EQUAL(request->Headers, "Host: test\r\nContent-Length: 0\r\n\r\n");
+ }
+
Y_UNIT_TEST(AdvancedParsing) {
NHttp::THttpIncomingRequestPtr request = new NHttp::THttpIncomingRequest();
EatWholeString(request, "GE");