Skip to content

Commit 9d3b5cd

Browse files
authored
Don't close the output stream when reporting errors reading the body. (#1068)
This matches the asio implementation to what the winhttp implementation was doing. Also turned on a test that looked related; I'm not positive that this change fixed that test but it passes for me now.
1 parent 3f6f844 commit 9d3b5cd

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

Release/src/http/common/http_msg.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,25 @@ void http_msg_base::_complete(utility::size64_t body_size, const std::exception_
427427
{
428428
const auto& completionEvent = _get_data_available();
429429
auto closeTask = pplx::task_from_result();
430-
431-
if (exceptionPtr == std::exception_ptr())
430+
if (m_default_outstream)
432431
{
433-
if (m_default_outstream)
432+
// if the outstream is one we created by default on the customer's behalf, try to close it
433+
auto& out = outstream();
434+
if (out.is_valid())
434435
{
435-
closeTask = outstream().close();
436+
if (exceptionPtr == std::exception_ptr())
437+
{
438+
closeTask = out.close();
439+
}
440+
else
441+
{
442+
closeTask = out.close(exceptionPtr);
443+
}
436444
}
445+
}
437446

447+
if (exceptionPtr == std::exception_ptr())
448+
{
438449
inline_continuation(closeTask, [completionEvent, body_size](pplx::task<void> t) {
439450
try
440451
{
@@ -459,11 +470,6 @@ void http_msg_base::_complete(utility::size64_t body_size, const std::exception_
459470
}
460471
else
461472
{
462-
if (outstream().is_valid())
463-
{
464-
closeTask = outstream().close(exceptionPtr);
465-
}
466-
467473
inline_continuation(closeTask, [completionEvent, exceptionPtr](pplx::task<void> t) {
468474
// If closing stream throws an exception ignore since we already have an error.
469475
try

Release/tests/functional/http/client/connections_and_errors.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,7 @@ SUITE(connections_and_errors)
226226
http_response rsp = client.request(msg).get();
227227

228228
// The response body should timeout and we should receive an exception
229-
#ifndef _WIN32
230-
// CodePlex 295
231-
VERIFY_THROWS(rsp.content_ready().wait(), http_exception);
232-
#else
233229
VERIFY_THROWS_HTTP_ERROR_CODE(rsp.content_ready().wait(), std::errc::timed_out);
234-
#endif
235230
}
236231

237232
buf.close(std::ios_base::out).wait();
@@ -261,12 +256,7 @@ SUITE(connections_and_errors)
261256

262257
// The response body should timeout and we should receive an exception
263258
auto readTask = rsp.body().read_to_end(streams::producer_consumer_buffer<uint8_t>());
264-
#ifndef _WIN32
265-
// CodePlex 295
266-
VERIFY_THROWS(readTask.get(), http_exception);
267-
#else
268259
VERIFY_THROWS_HTTP_ERROR_CODE(readTask.wait(), std::errc::timed_out);
269-
#endif
270260
}
271261

272262
buf.close(std::ios_base::out).wait();

0 commit comments

Comments
 (0)