Skip to content

Commit bacaffa

Browse files
committed
Starting to re-enable some of the http_client request stream tests.
1 parent 132c739 commit bacaffa

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

Release/src/http/client/http_linux.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ namespace web { namespace http
274274
}
275275

276276
std::unique_ptr<boost::asio::ssl::stream<tcp::socket &> > m_ssl_stream;
277-
uint64_t m_known_size;
277+
uint64_t m_content_length;
278278
bool m_needChunked;
279279
bool m_timedout;
280280
boost::asio::streambuf m_body_buf;
@@ -381,7 +381,7 @@ namespace web { namespace http
381381
{
382382
ctx->m_needChunked = true;
383383
}
384-
else if (!ctx->m_request.headers().match(header_names::content_length, ctx->m_known_size))
384+
else if (!ctx->m_request.headers().match(header_names::content_length, ctx->m_content_length))
385385
{
386386
// Stream without content length is the signal of requiring transfer encoding chunked.
387387
if (ctx->m_request.body())
@@ -627,7 +627,7 @@ namespace web { namespace http
627627

628628
void handle_write_large_body(const boost::system::error_code& ec, const std::shared_ptr<linux_client_request_context> &ctx)
629629
{
630-
if (ec || ctx->m_uploaded >= ctx->m_known_size)
630+
if (ec || ctx->m_uploaded >= ctx->m_content_length)
631631
{
632632
// Reuse error handling.
633633
return handle_write_body(ec, ctx);
@@ -664,7 +664,7 @@ namespace web { namespace http
664664
}
665665
};
666666

667-
const auto readSize = static_cast<size_t>(std::min(static_cast<uint64_t>(client_config().chunksize()), ctx->m_known_size - ctx->m_uploaded));
667+
const auto readSize = static_cast<size_t>(std::min(static_cast<uint64_t>(client_config().chunksize()), ctx->m_content_length - ctx->m_uploaded));
668668

669669
auto readbuf = ctx->_get_readbuffer();
670670
readbuf.getn(boost::asio::buffer_cast<uint8_t *>(ctx->m_body_buf.prepare(readSize)), readSize)
@@ -829,12 +829,12 @@ namespace web { namespace http
829829
}
830830
ctx->complete_headers();
831831

832-
ctx->m_known_size = std::numeric_limits<size_t>::max(); // Without Content-Length header, size should be same as TCP stream - set it size_t max.
833-
ctx->m_response.headers().match(header_names::content_length, ctx->m_known_size);
832+
ctx->m_content_length = std::numeric_limits<size_t>::max(); // Without Content-Length header, size should be same as TCP stream - set it size_t max.
833+
ctx->m_response.headers().match(header_names::content_length, ctx->m_content_length);
834834

835835
// note: need to check for 'chunked' here as well, azure storage sends both
836836
// transfer-encoding:chunked and content-length:0 (although HTTP says not to)
837-
if (ctx->m_request.method() == U("HEAD") || (!needChunked && ctx->m_known_size == 0))
837+
if (ctx->m_request.method() == U("HEAD") || (!needChunked && ctx->m_content_length == 0))
838838
{
839839
// we can stop early - no body
840840
auto progress = ctx->m_request._get_impl()->_progress_handler();
@@ -857,7 +857,7 @@ namespace web { namespace http
857857
{
858858
if (!needChunked)
859859
{
860-
async_read_until_buffersize(static_cast<size_t>(std::min(ctx->m_known_size, static_cast<uint64_t>(client_config().chunksize()))),
860+
async_read_until_buffersize(static_cast<size_t>(std::min(ctx->m_content_length, static_cast<uint64_t>(client_config().chunksize()))),
861861
boost::bind(&linux_client::handle_read_content, shared_from_this(), boost::asio::placeholders::error, ctx), ctx);
862862
}
863863
else
@@ -1003,9 +1003,9 @@ namespace web { namespace http
10031003

10041004
if (ec)
10051005
{
1006-
if (ec == boost::asio::error::eof && ctx->m_known_size == std::numeric_limits<size_t>::max())
1006+
if (ec == boost::asio::error::eof && ctx->m_content_length == std::numeric_limits<size_t>::max())
10071007
{
1008-
ctx->m_known_size = ctx->m_downloaded + ctx->m_body_buf.size();
1008+
ctx->m_content_length = ctx->m_downloaded + ctx->m_body_buf.size();
10091009
}
10101010
else
10111011
{
@@ -1028,13 +1028,13 @@ namespace web { namespace http
10281028
}
10291029
}
10301030

1031-
if (ctx->m_downloaded < ctx->m_known_size)
1031+
if (ctx->m_downloaded < ctx->m_content_length)
10321032
{
10331033
ctx->reset_timer(static_cast<int>(client_config().timeout().count()));
10341034

10351035
// more data need to be read
10361036
writeBuffer.putn(boost::asio::buffer_cast<const uint8_t *>(ctx->m_body_buf.data()),
1037-
static_cast<size_t>(std::min(static_cast<uint64_t>(ctx->m_body_buf.size()), ctx->m_known_size - ctx->m_downloaded)))
1037+
static_cast<size_t>(std::min(static_cast<uint64_t>(ctx->m_body_buf.size()), ctx->m_content_length - ctx->m_downloaded)))
10381038
.then([=](pplx::task<size_t> op)
10391039
{
10401040
size_t writtenSize = 0;
@@ -1044,7 +1044,7 @@ namespace web { namespace http
10441044
ctx->m_downloaded += static_cast<uint64_t>(writtenSize);
10451045
ctx->m_body_buf.consume(writtenSize);
10461046

1047-
async_read_until_buffersize(static_cast<size_t>(std::min(static_cast<uint64_t>(client_config().chunksize()), ctx->m_known_size - ctx->m_downloaded)),
1047+
async_read_until_buffersize(static_cast<size_t>(std::min(static_cast<uint64_t>(client_config().chunksize()), ctx->m_content_length - ctx->m_downloaded)),
10481048
boost::bind(&linux_client::handle_read_content, shared_from_this(), boost::asio::placeholders::error, ctx), ctx);
10491049
}
10501050
catch (...)
@@ -1094,7 +1094,7 @@ namespace web { namespace http
10941094
http_request request,
10951095
const std::shared_ptr<linux_connection> &connection)
10961096
: request_context(client, request)
1097-
, m_known_size(0)
1097+
, m_content_length(0)
10981098
, m_needChunked(false)
10991099
, m_timedout(false)
11001100
, m_timeout_timer(crossplat::threadpool::shared_instance().service())

Release/src/http/client/http_win7.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ class winhttp_client : public _http_client_communicator
567567
}
568568

569569
// There is a request body that needs to be transferred.
570-
571570
if (content_length == std::numeric_limits<size_t>::max())
572571
{
573572
// The content length is unknown and the application set a stream. This is an

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,9 @@ class test_exception : public std::exception
316316
}
317317
};
318318

319-
TEST_FIXTURE(uri_address, set_body_stream_exception, "Ignore", "940704")
319+
// Ignore on WinRT only CodePlex 144
320+
#if !defined(__cplusplus_winrt)
321+
TEST_FIXTURE(uri_address, set_body_stream_exception)
320322
{
321323
utility::string_t fname = U("set_body_stream_exception.txt");
322324
fill_file(fname);
@@ -334,9 +336,11 @@ TEST_FIXTURE(uri_address, set_body_stream_exception, "Ignore", "940704")
334336

335337
VERIFY_THROWS(client.request(msg).get(), test_exception);
336338
}
339+
#endif
337340

341+
// These tests aren't possible on WinRT because they don't
342+
// specify a Content-Length.
338343
#if !defined(__cplusplus_winrt)
339-
340344
TEST_FIXTURE(uri_address, stream_close_early)
341345
{
342346
http_client client(m_uri);
@@ -356,7 +360,7 @@ TEST_FIXTURE(uri_address, stream_close_early)
356360

357361
buf.close(std::ios::out);
358362

359-
// Verify that the task completes succesfully
363+
// Verify that the task completes successfully
360364
http_asserts::assert_response_equals(responseTask.get(), status_codes::OK);
361365
}
362366

@@ -383,6 +387,8 @@ TEST_FIXTURE(uri_address, stream_close_early)
383387
}
384388
#endif
385389

390+
// Ignore on WinRT only CodePlex 144
391+
#if !defined(__cplusplus_winrt)
386392
TEST_FIXTURE(uri_address, stream_close_early_with_exception_and_contentlength,
387393
"Ignore", "825361",
388394
"Ignore:Linux", "TBD",
@@ -404,7 +410,10 @@ TEST_FIXTURE(uri_address, stream_close_early_with_exception_and_contentlength,
404410
// Verify that the responseTask throws the exception set when closing the stream
405411
VERIFY_THROWS(responseTask.get(), test_exception);
406412
}
413+
#endif
407414

415+
// Ignore on WinRT only CodePlex 144
416+
#if !defined(__cplusplus_winrt)
408417
TEST_FIXTURE(uri_address, stream_close_early_with_contentlength,
409418
"Ignore", "825361",
410419
"Ignore:Linux", "TBD",
@@ -426,6 +435,7 @@ TEST_FIXTURE(uri_address, stream_close_early_with_contentlength,
426435
// Verify that the responseTask throws the exception set when closing the stream
427436
VERIFY_THROWS(responseTask.get(), http_exception);
428437
}
438+
#endif
429439

430440
TEST_FIXTURE(uri_address, get_with_body_nono)
431441
{

0 commit comments

Comments
 (0)