aboutsummaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2022-10-11 17:07:02 +0300
committerDaniil Cherednik <dan.cherednik@gmail.com>2022-10-11 17:07:02 +0300
commit0b931ad6e6868bca7e7ec4617999c0d6befd7003 (patch)
treec10d4fcf9f5a638745e9c2b725852f03e5a175ce /library
parente6c9b17192c56494adba359d5e132c431b241191 (diff)
downloadydb-0b931ad6e6868bca7e7ec4617999c0d6befd7003.tar.gz
Ydb stable 22-4-3022.4.30
x-stable-origin-commit: a5971297427891237b5f05b5389146b6ca2fff93
Diffstat (limited to 'library')
-rw-r--r--library/cpp/actors/http/http.cpp14
-rw-r--r--library/cpp/actors/http/http_ut.cpp12
-rw-r--r--library/cpp/mime/types/mime.cpp3
-rw-r--r--library/cpp/mime/types/mime.h1
4 files changed, 26 insertions, 4 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");
diff --git a/library/cpp/mime/types/mime.cpp b/library/cpp/mime/types/mime.cpp
index 706d776b24..e4cbcc86eb 100644
--- a/library/cpp/mime/types/mime.cpp
+++ b/library/cpp/mime/types/mime.cpp
@@ -84,7 +84,7 @@ const TMimeTypes::TRecord TMimeTypes::Records[] = {
{MIME_JAVASCRIPT, "application/javascript\0text/javascript\0", "js\0"},
{MIME_EPUB, "application/epub+zip\0", "epub\0"},
{MIME_TEX, "application/x-tex\0application/x-latex\0text/x-tex\0", "tex\0"},
- {MIME_JSON, "application/json\0", "json\0"},
+ {MIME_JSON, "application/json\0application/x-amz-json-1.0\0application/x-amz-json-1.1\0", "json\0"},
{MIME_APK, "application/vnd.android.package-archive\0", "apk\0"},
{MIME_CSS, "text/css\0", "css\0"},
{MIME_IMAGE_WEBP, "image/webp\0", "webp\0"},
@@ -99,6 +99,7 @@ const TMimeTypes::TRecord TMimeTypes::Records[] = {
{MIME_WOFF2, "font/woff2\0", "woff2\0"},
{MIME_TTF, "font/ttf\0", "ttf\0"},
{MIME_WEBMANIFEST, "application/manifest+json\0", "webmanifest\0"},
+ {MIME_CBOR, "application/cbor\0application/x-amz-cbor-1.1\0", "cbor\0"},
{MIME_MAX, nullptr, nullptr},
// Additional records
diff --git a/library/cpp/mime/types/mime.h b/library/cpp/mime/types/mime.h
index 05da389ea9..ffaebeff3e 100644
--- a/library/cpp/mime/types/mime.h
+++ b/library/cpp/mime/types/mime.h
@@ -58,6 +58,7 @@ enum MimeTypes {
MIME_WOFF2 = 44,
MIME_TTF = 45,
MIME_WEBMANIFEST = 46,
+ MIME_CBOR = 47,
MIME_MAX
};