From 53b57c36eb29184c8f10db73ed831da3bca28436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Sun, 15 Oct 2023 11:20:05 +0200 Subject: [PATCH] fix sending trailer: HTTPOutputStream actually shuts down socket, so final \r\n would not be sent. May be related to #4180 --- Net/src/HTTPChunkedStream.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Net/src/HTTPChunkedStream.cpp b/Net/src/HTTPChunkedStream.cpp index 49ca241fb..f62bddc71 100644 --- a/Net/src/HTTPChunkedStream.cpp +++ b/Net/src/HTTPChunkedStream.cpp @@ -13,7 +13,7 @@ #include "Poco/Net/HTTPChunkedStream.h" -#include "Poco/Net/HTTPStream.h" +#include "Poco/Net/HTTPHeaderStream.h" #include "Poco/Net/HTTPSession.h" #include "Poco/NumberFormatter.h" #include "Poco/NumberParser.h" @@ -53,13 +53,17 @@ void HTTPChunkedStreamBuf::close() if (_mode & std::ios::out) { sync(); - _session.write("0\r\n", 3); if (_pTrailer && !_pTrailer->empty()) { - HTTPOutputStream hos(_session); + HTTPHeaderOutputStream hos(_session); + hos.write("0\r\n", 3); _pTrailer->write(hos); + hos.write("\r\n", 2); + } + else + { + _session.write("0\r\n\r\n", 5); // If possible, send in one write } - _session.write("\r\n", 2); } } @@ -79,7 +83,7 @@ int HTTPChunkedStreamBuf::readFromDevice(char* buffer, std::streamsize length) unsigned chunk; if (NumberParser::tryParseHex(chunkLen, chunk)) { - _chunk = (std::streamsize) chunk; + _chunk = static_cast(chunk); } else { @@ -99,7 +103,7 @@ int HTTPChunkedStreamBuf::readFromDevice(char* buffer, std::streamsize length) int ch = _session.peek(); if (ch != eof && ch != '\r' && ch != '\n') { - HTTPInputStream his(_session); + HTTPHeaderInputStream his(_session); if (_pTrailer) { _pTrailer->read(his);