Merge pull request #47950 from ClickHouse/fix_http_warning

Set content-length for empty POST requests
This commit is contained in:
Alexander Tokmakov 2023-03-24 04:19:04 +03:00 committed by GitHub
commit ef57253518
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -159,6 +159,8 @@ namespace detail
if (out_stream_callback)
request.setChunkedTransferEncoding(true);
else if (method == Poco::Net::HTTPRequest::HTTP_POST)
request.setContentLength(0); /// No callback - no body
for (auto & [header, value] : http_header_entries)
request.set(header, value);

View File

@ -63,11 +63,9 @@ HTTPServerRequest::HTTPServerRequest(HTTPContextPtr context, HTTPServerResponse
}
else if (getMethod() != HTTPRequest::HTTP_GET && getMethod() != HTTPRequest::HTTP_HEAD && getMethod() != HTTPRequest::HTTP_DELETE)
{
/// That check for has_body may be false-negative in rare cases, but it's okay
bool has_body = in->hasPendingData();
stream = std::move(in);
if (!startsWith(getContentType(), "multipart/form-data") && has_body)
LOG_WARNING(&Poco::Logger::get("HTTPServerRequest"), "Got an HTTP request with no content length "
if (!startsWith(getContentType(), "multipart/form-data"))
LOG_WARNING(LogFrequencyLimiter(&Poco::Logger::get("HTTPServerRequest"), 10), "Got an HTTP request with no content length "
"and no chunked/multipart encoding, it may be impossible to distinguish graceful EOF from abnormal connection loss");
}
else