Skip to content

Commit c60bf39

Browse files
Mike-ECTglynos
authored andcommitted
Fixed a bug that too many bytes were expected during chunked body processing.
1 parent 6cb7388 commit c60bf39

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

boost/network/protocol/http/client/connection/sync_base.hpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,20 @@ namespace boost { namespace network { namespace http { namespace impl {
147147
throw boost::system::system_error(error);
148148
} else {
149149
bool stopping_inner = false;
150+
std::istreambuf_iterator<char> eos;
151+
std::istreambuf_iterator<char> stream_iterator0(&response_buffer);
152+
for (; chunk_size > 0 && stream_iterator0 != eos; --chunk_size)
153+
body_stream << *stream_iterator0++;
154+
150155
do {
151-
std::size_t chunk_bytes_read = read(socket_, response_buffer, boost::asio::transfer_at_least(chunk_size), error);
152-
if (chunk_bytes_read == 0) {
153-
if (error != boost::asio::error::eof) throw boost::system::system_error(error);
154-
stopping_inner = true;
156+
if (chunk_size != 0) {
157+
std::size_t chunk_bytes_read = read(socket_, response_buffer, boost::asio::transfer_at_least(chunk_size), error);
158+
if (chunk_bytes_read == 0) {
159+
if (error != boost::asio::error::eof) throw boost::system::system_error(error);
160+
stopping_inner = true;
161+
}
155162
}
156163

157-
std::istreambuf_iterator<char> eos;
158164
std::istreambuf_iterator<char> stream_iterator(&response_buffer);
159165
for (; chunk_size > 0 && stream_iterator != eos; --chunk_size)
160166
body_stream << *stream_iterator++;

0 commit comments

Comments
 (0)