@@ -97,8 +97,7 @@ namespace web { namespace http
97
97
size_t m_current_size;
98
98
bool m_needChunked;
99
99
bool m_timedout;
100
- boost::asio::streambuf m_request_buf;
101
- boost::asio::streambuf m_response_buf;
100
+ boost::asio::streambuf m_body_buf;
102
101
std::unique_ptr<boost::asio::deadline_timer> m_timer;
103
102
104
103
template <typename socket_type>
@@ -216,7 +215,7 @@ namespace web { namespace http
216
215
}
217
216
218
217
const auto &host = m_uri.host ();
219
- std::ostream request_stream (&ctx->m_request_buf );
218
+ std::ostream request_stream (&ctx->m_body_buf );
220
219
221
220
request_stream << method << " " << encoded_resource << " " << " HTTP/1.1" << CRLF << " Host: " << host;
222
221
@@ -338,7 +337,7 @@ namespace web { namespace http
338
337
}
339
338
else
340
339
{
341
- boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf , boost::bind (&linux_client::handle_write_request, this , boost::asio::placeholders::error, ctx));
340
+ boost::asio::async_write (*ctx->m_socket , ctx->m_body_buf , boost::bind (&linux_client::handle_write_request, this , boost::asio::placeholders::error, ctx));
342
341
}
343
342
}
344
343
else if (endpoints == tcp::resolver::iterator ())
@@ -384,10 +383,11 @@ namespace web { namespace http
384
383
void handle_handshake (const boost::system::error_code& ec, std::shared_ptr<linux_request_context> ctx)
385
384
{
386
385
if (!ec)
387
- boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf , boost::bind (&linux_client::handle_write_request, this , boost::asio::placeholders::error, ctx));
386
+ boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_body_buf , boost::bind (&linux_client::handle_write_request, this , boost::asio::placeholders::error, ctx));
388
387
else
389
388
ctx->report_error (" Error code in handle_handshake is " , ec, httpclient_errorcode_context::handshake);
390
389
}
390
+
391
391
void handle_write_chunked_body (const boost::system::error_code& ec, std::shared_ptr<linux_request_context> ctx)
392
392
{
393
393
if (ec)
@@ -404,7 +404,7 @@ namespace web { namespace http
404
404
}
405
405
406
406
auto readbuf = ctx->_get_readbuffer ();
407
- uint8_t *buf = boost::asio::buffer_cast<uint8_t *>(ctx->m_request_buf .prepare (client_config ().chunksize () + http::details::chunked_encoding::additional_encoding_space));
407
+ uint8_t *buf = boost::asio::buffer_cast<uint8_t *>(ctx->m_body_buf .prepare (client_config ().chunksize () + http::details::chunked_encoding::additional_encoding_space));
408
408
readbuf.getn (buf + http::details::chunked_encoding::data_offset, client_config ().chunksize ()).then ([=](pplx::task<size_t > op)
409
409
{
410
410
size_t readSize = 0 ;
@@ -415,15 +415,15 @@ namespace web { namespace http
415
415
return ;
416
416
}
417
417
size_t offset = http::details::chunked_encoding::add_chunked_delimiters (buf, client_config ().chunksize () + http::details::chunked_encoding::additional_encoding_space, readSize);
418
- ctx->m_request_buf .commit (readSize + http::details::chunked_encoding::additional_encoding_space);
419
- ctx->m_request_buf .consume (offset);
418
+ ctx->m_body_buf .commit (readSize + http::details::chunked_encoding::additional_encoding_space);
419
+ ctx->m_body_buf .consume (offset);
420
420
ctx->m_current_size += readSize;
421
421
ctx->m_uploaded += (size64_t )readSize;
422
422
if (ctx->m_ssl_stream )
423
- boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf ,
423
+ boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_body_buf ,
424
424
boost::bind (readSize != 0 ? &linux_client::handle_write_chunked_body : &linux_client::handle_write_body, this , boost::asio::placeholders::error, ctx));
425
425
else
426
- boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf ,
426
+ boost::asio::async_write (*ctx->m_socket , ctx->m_body_buf ,
427
427
boost::bind (readSize != 0 ? &linux_client::handle_write_chunked_body : &linux_client::handle_write_body, this , boost::asio::placeholders::error, ctx));
428
428
});
429
429
}
@@ -448,7 +448,7 @@ namespace web { namespace http
448
448
auto readbuf = ctx->_get_readbuffer ();
449
449
size_t readSize = std::min (client_config ().chunksize (), ctx->m_known_size - ctx->m_current_size );
450
450
451
- readbuf.getn (boost::asio::buffer_cast<uint8_t *>(ctx->m_request_buf .prepare (readSize)), readSize).then ([=](pplx::task<size_t > op)
451
+ readbuf.getn (boost::asio::buffer_cast<uint8_t *>(ctx->m_body_buf .prepare (readSize)), readSize).then ([=](pplx::task<size_t > op)
452
452
{
453
453
size_t actualSize = 0 ;
454
454
try { actualSize = op.get (); }
@@ -459,12 +459,12 @@ namespace web { namespace http
459
459
}
460
460
ctx->m_uploaded += (size64_t )actualSize;
461
461
ctx->m_current_size += actualSize;
462
- ctx->m_request_buf .commit (actualSize);
462
+ ctx->m_body_buf .commit (actualSize);
463
463
if (ctx->m_ssl_stream )
464
- boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf ,
464
+ boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_body_buf ,
465
465
boost::bind (&linux_client::handle_write_large_body, this , boost::asio::placeholders::error, ctx));
466
466
else
467
- boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf ,
467
+ boost::asio::async_write (*ctx->m_socket , ctx->m_body_buf ,
468
468
boost::bind (&linux_client::handle_write_large_body, this , boost::asio::placeholders::error, ctx));
469
469
});
470
470
}
@@ -502,10 +502,10 @@ namespace web { namespace http
502
502
503
503
// Read until the end of entire headers
504
504
if (ctx->m_ssl_stream )
505
- boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_response_buf , CRLF+CRLF,
505
+ boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_body_buf , CRLF+CRLF,
506
506
boost::bind (&linux_client::handle_status_line, this , boost::asio::placeholders::error, ctx));
507
507
else
508
- boost::asio::async_read_until (*ctx->m_socket , ctx->m_response_buf , CRLF+CRLF,
508
+ boost::asio::async_read_until (*ctx->m_socket , ctx->m_body_buf , CRLF+CRLF,
509
509
boost::bind (&linux_client::handle_status_line, this , boost::asio::placeholders::error, ctx));
510
510
}
511
511
else
@@ -518,7 +518,7 @@ namespace web { namespace http
518
518
{
519
519
if (!ec)
520
520
{
521
- std::istream response_stream (&ctx->m_response_buf );
521
+ std::istream response_stream (&ctx->m_body_buf );
522
522
std::string http_version;
523
523
response_stream >> http_version;
524
524
status_code status_code;
@@ -549,7 +549,7 @@ namespace web { namespace http
549
549
void read_headers (std::shared_ptr<linux_request_context> ctx)
550
550
{
551
551
ctx->m_needChunked = false ;
552
- std::istream response_stream (&ctx->m_response_buf );
552
+ std::istream response_stream (&ctx->m_body_buf );
553
553
std::string header;
554
554
while (std::getline (response_stream, header) && header != " \r " )
555
555
{
@@ -600,10 +600,10 @@ namespace web { namespace http
600
600
else
601
601
{
602
602
if (ctx->m_ssl_stream )
603
- boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_response_buf , CRLF,
603
+ boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_body_buf , CRLF,
604
604
boost::bind (&linux_client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
605
605
else
606
- boost::asio::async_read_until (*ctx->m_socket , ctx->m_response_buf , CRLF,
606
+ boost::asio::async_read_until (*ctx->m_socket , ctx->m_body_buf , CRLF,
607
607
boost::bind (&linux_client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
608
608
}
609
609
}
@@ -615,23 +615,23 @@ namespace web { namespace http
615
615
size_t size_to_read = 0 ;
616
616
if (ctx->m_ssl_stream )
617
617
{
618
- if (ctx->m_response_buf .size () < size)
619
- size_to_read = size - ctx->m_response_buf .size ();
620
- boost::asio::async_read (*ctx->m_ssl_stream , ctx->m_response_buf , boost::asio::transfer_at_least (size_to_read), handler);
618
+ if (ctx->m_body_buf .size () < size)
619
+ size_to_read = size - ctx->m_body_buf .size ();
620
+ boost::asio::async_read (*ctx->m_ssl_stream , ctx->m_body_buf , boost::asio::transfer_at_least (size_to_read), handler);
621
621
}
622
622
else
623
623
{
624
- if (ctx->m_response_buf .size () < size)
625
- size_to_read = size - ctx->m_response_buf .size ();
626
- boost::asio::async_read (*ctx->m_socket , ctx->m_response_buf , boost::asio::transfer_at_least (size_to_read), handler);
624
+ if (ctx->m_body_buf .size () < size)
625
+ size_to_read = size - ctx->m_body_buf .size ();
626
+ boost::asio::async_read (*ctx->m_socket , ctx->m_body_buf , boost::asio::transfer_at_least (size_to_read), handler);
627
627
}
628
628
}
629
629
630
630
void handle_chunk_header (const boost::system::error_code& ec, std::shared_ptr<linux_request_context> ctx)
631
631
{
632
632
if (!ec)
633
633
{
634
- std::istream response_stream (&ctx->m_response_buf );
634
+ std::istream response_stream (&ctx->m_body_buf );
635
635
std::string line;
636
636
std::getline (response_stream, line);
637
637
@@ -671,7 +671,7 @@ namespace web { namespace http
671
671
672
672
if (to_read == 0 )
673
673
{
674
- ctx->m_response_buf .consume (CRLF.size ());
674
+ ctx->m_body_buf .consume (CRLF.size ());
675
675
ctx->_get_writebuffer ().sync ().then ([ctx](pplx::task<void > op)
676
676
{
677
677
try {
@@ -687,21 +687,21 @@ namespace web { namespace http
687
687
else
688
688
{
689
689
auto writeBuffer = ctx->_get_writebuffer ();
690
- writeBuffer.putn (boost::asio::buffer_cast<const uint8_t *>(ctx->m_response_buf .data ()), to_read).then ([=](pplx::task<size_t > op)
690
+ writeBuffer.putn (boost::asio::buffer_cast<const uint8_t *>(ctx->m_body_buf .data ()), to_read).then ([=](pplx::task<size_t > op)
691
691
{
692
692
try { op.wait (); }
693
693
catch (...)
694
694
{
695
695
ctx->report_exception (std::current_exception ());
696
696
return ;
697
697
}
698
- ctx->m_response_buf .consume (to_read + CRLF.size ()); // consume crlf
698
+ ctx->m_body_buf .consume (to_read + CRLF.size ()); // consume crlf
699
699
700
700
if (ctx->m_ssl_stream )
701
- boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_response_buf , CRLF,
701
+ boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_body_buf , CRLF,
702
702
boost::bind (&linux_client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
703
703
else
704
- boost::asio::async_read_until (*ctx->m_socket , ctx->m_response_buf , CRLF,
704
+ boost::asio::async_read_until (*ctx->m_socket , ctx->m_body_buf , CRLF,
705
705
boost::bind (&linux_client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
706
706
});
707
707
}
@@ -719,7 +719,7 @@ namespace web { namespace http
719
719
if (ec)
720
720
{
721
721
if (ec == boost::asio::error::eof && ctx->m_known_size == std::numeric_limits<size_t >::max ())
722
- ctx->m_known_size = ctx->m_current_size + ctx->m_response_buf .size ();
722
+ ctx->m_known_size = ctx->m_current_size + ctx->m_body_buf .size ();
723
723
else
724
724
{
725
725
ctx->report_error (" Failed to read response body" , ec, httpclient_errorcode_context::readbody);
@@ -739,16 +739,16 @@ namespace web { namespace http
739
739
if (ctx->m_current_size < ctx->m_known_size )
740
740
{
741
741
// more data need to be read
742
- writeBuffer.putn (boost::asio::buffer_cast<const uint8_t *>(ctx->m_response_buf .data ()),
743
- std::min (ctx->m_response_buf .size (), ctx->m_known_size - ctx->m_current_size )).then ([=](pplx::task<size_t > op)
742
+ writeBuffer.putn (boost::asio::buffer_cast<const uint8_t *>(ctx->m_body_buf .data ()),
743
+ std::min (ctx->m_body_buf .size (), ctx->m_known_size - ctx->m_current_size )).then ([=](pplx::task<size_t > op)
744
744
{
745
745
size_t writtenSize = 0 ;
746
746
try
747
747
{
748
748
writtenSize = op.get ();
749
749
ctx->m_downloaded += (size64_t )writtenSize;
750
750
ctx->m_current_size += writtenSize;
751
- ctx->m_response_buf .consume (writtenSize);
751
+ ctx->m_body_buf .consume (writtenSize);
752
752
async_read_until_buffersize (std::min (client_config ().chunksize (), ctx->m_known_size - ctx->m_current_size ),
753
753
boost::bind (&linux_client::handle_read_content, this , boost::asio::placeholders::error, ctx), ctx);
754
754
}
0 commit comments