@@ -22,7 +22,7 @@ namespace http {
2222namespace v2 {
2323using boost::asio::ip::tcp;
2424
25- struct request_helper {
25+ struct request_context {
2626
2727 std::shared_ptr<client_connection::async_connection> connection_;
2828
@@ -38,7 +38,7 @@ struct request_helper {
3838
3939 std::uint64_t total_bytes_written_, total_bytes_read_;
4040
41- request_helper (std::shared_ptr<client_connection::async_connection> connection,
41+ request_context (std::shared_ptr<client_connection::async_connection> connection,
4242 request request,
4343 request_options options)
4444 : connection_(connection)
@@ -59,32 +59,32 @@ struct client::impl {
5959
6060~impl ()noexcept ;
6161
62- std::future<response>execute (std::shared_ptr<request_helper> helper );
62+ std::future<response>execute (std::shared_ptr<request_context> context );
6363
6464void connect (const boost::system::error_code &ec,
6565 tcp::resolver::iterator endpoint_iterator,
66- std::shared_ptr<request_helper> helper );
66+ std::shared_ptr<request_context> context );
6767
6868void write_request (const boost::system::error_code &ec,
69- std::shared_ptr<request_helper> helper );
69+ std::shared_ptr<request_context> context );
7070
7171void read_response (const boost::system::error_code &ec,
7272 std::size_t bytes_written,
73- std::shared_ptr<request_helper> helper );
73+ std::shared_ptr<request_context> context );
7474
7575void read_response_status (const boost::system::error_code &ec,
7676 std::size_t bytes_written,
77- std::shared_ptr<request_helper> helper ,
77+ std::shared_ptr<request_context> context ,
7878 std::shared_ptr<response> res);
7979
8080void read_response_headers (const boost::system::error_code &ec,
8181 std::size_t bytes_read,
82- std::shared_ptr<request_helper> helper ,
82+ std::shared_ptr<request_context> context ,
8383 std::shared_ptr<response> res);
8484
8585void read_response_body (const boost::system::error_code &ec,
8686 std::size_t bytes_read,
87- std::shared_ptr<request_helper> helper ,
87+ std::shared_ptr<request_context> context ,
8888 std::shared_ptr<response> res);
8989
9090 client_options options_;
@@ -122,112 +122,112 @@ client::impl::~impl() noexcept {
122122 lifetime_thread_.join ();
123123}
124124
125- std::future<response>client::impl::execute (std::shared_ptr<request_helper> helper ) {
126- std::future<response> res =helper ->response_promise_ .get_future ();
125+ std::future<response>client::impl::execute (std::shared_ptr<request_context> context ) {
126+ std::future<response> res =context ->response_promise_ .get_future ();
127127
128128// TODO see linearize.hpp
129129
130130// If there is no user-agent, provide one as a default.
131- auto user_agent =helper ->request_ .header (" User-Agent" );
131+ auto user_agent =context ->request_ .header (" User-Agent" );
132132if (!user_agent) {
133- helper ->request_ .append_header (" User-Agent" , options_.user_agent ());
133+ context ->request_ .append_header (" User-Agent" , options_.user_agent ());
134134 }
135135
136- auto url =helper ->request_ .url ();
136+ auto url =context ->request_ .url ();
137137auto host = url.host ()?
138138uri::string_type (std::begin (*url.host ()),std::end (*url.host ())) :uri::string_type ();
139139auto port = url.port <std::uint16_t >()? *url.port <std::uint16_t >() :80 ;
140140
141141 resolver_->async_resolve (host, port,
142142 strand_.wrap ([=](const boost::system::error_code &ec,
143143 tcp::resolver::iterator endpoint_iterator) {
144- connect (ec, endpoint_iterator,helper );
144+ connect (ec, endpoint_iterator,context );
145145 }));
146146
147147return res;
148148}
149149
150150void client::impl::connect (const boost::system::error_code &ec,
151151 tcp::resolver::iterator endpoint_iterator,
152- std::shared_ptr<request_helper> helper ) {
152+ std::shared_ptr<request_context> context ) {
153153if (ec) {
154- helper ->response_promise_ .set_exception (std::make_exception_ptr (std::system_error (ec.value (),std::system_category ())));
154+ context ->response_promise_ .set_exception (std::make_exception_ptr (std::system_error (ec.value (),std::system_category ())));
155155return ;
156156 }
157157
158- auto host =helper ->request_ .url ().host ();
158+ auto host =context ->request_ .url ().host ();
159159 tcp::endpointendpoint (*endpoint_iterator);
160- helper ->connection_ ->async_connect (endpoint,
160+ context ->connection_ ->async_connect (endpoint,
161161std::string (std::begin (*host),std::end (*host)),
162162 strand_.wrap ([=] (const boost::system::error_code &ec) {
163163if (ec && endpoint_iterator !=tcp::resolver::iterator ()) {
164164// copy iterator because it is const after the lambda
165165// capture
166166auto it = endpoint_iterator;
167167 boost::system::error_code ignore;
168- connect (ignore, ++it,helper );
168+ connect (ignore, ++it,context );
169169return ;
170170 }
171171
172- write_request (ec,helper );
172+ write_request (ec,context );
173173 }));
174174 }
175175
176176void client::impl::write_request (const boost::system::error_code &ec,
177- std::shared_ptr<request_helper> helper ) {
177+ std::shared_ptr<request_context> context ) {
178178if (ec) {
179- helper ->response_promise_ .set_exception (std::make_exception_ptr (std::system_error (ec.value (),std::system_category ())));
179+ context ->response_promise_ .set_exception (std::make_exception_ptr (std::system_error (ec.value (),std::system_category ())));
180180return ;
181181 }
182182
183- std::ostreamrequest_stream (&helper ->request_buffer_ );
184- request_stream <<helper ->request_ ;
183+ std::ostreamrequest_stream (&context ->request_buffer_ );
184+ request_stream <<context ->request_ ;
185185if (!request_stream) {
186- helper ->response_promise_ .set_exception (std::make_exception_ptr (client_exception (client_error::invalid_request)));
186+ context ->response_promise_ .set_exception (std::make_exception_ptr (client_exception (client_error::invalid_request)));
187187 }
188188
189189// TODO write payload to request_buffer_
190190
191- helper ->connection_ ->async_write (helper ->request_buffer_ ,
191+ context ->connection_ ->async_write (context ->request_buffer_ ,
192192 strand_.wrap ([=] (const boost::system::error_code &ec,
193193 std::size_t bytes_written) {
194194// TODO write chunked or write body
195- read_response (ec, bytes_written,helper );
195+ read_response (ec, bytes_written,context );
196196 }));
197197}
198198
199199void client::impl::read_response (const boost::system::error_code &ec,
200200 std::size_t bytes_written,
201- std::shared_ptr<request_helper> helper ) {
201+ std::shared_ptr<request_context> context ) {
202202if (ec) {
203- helper ->response_promise_ .set_exception (std::make_exception_ptr (std::system_error (ec.value (),std::system_category ())));
203+ context ->response_promise_ .set_exception (std::make_exception_ptr (std::system_error (ec.value (),std::system_category ())));
204204return ;
205205 }
206206
207- helper ->total_bytes_written_ += bytes_written;
208- if (auto progress =helper ->options_ .progress ()) {
209- progress (client_message::transfer_direction::bytes_written,helper ->total_bytes_written_ );
207+ context ->total_bytes_written_ += bytes_written;
208+ if (auto progress =context ->options_ .progress ()) {
209+ progress (client_message::transfer_direction::bytes_written,context ->total_bytes_written_ );
210210 }
211211
212212 std::shared_ptr<response>res (new response{});
213- helper ->connection_ ->async_read_until (helper ->response_buffer_ ,
213+ context ->connection_ ->async_read_until (context ->response_buffer_ ,
214214" \r\n " ,
215215 strand_.wrap ([=] (const boost::system::error_code &ec,
216216 std::size_t bytes_read) {
217- read_response_status (ec, bytes_read,helper , res);
217+ read_response_status (ec, bytes_read,context , res);
218218 }));
219219}
220220
221221void client::impl::read_response_status (const boost::system::error_code &ec,
222222 std::size_t ,
223- std::shared_ptr<request_helper> helper ,
223+ std::shared_ptr<request_context> context ,
224224 std::shared_ptr<response> res) {
225225if (ec) {
226- helper ->response_promise_ .set_exception (std::make_exception_ptr (std::system_error (ec.value (),std::system_category ())));
226+ context ->response_promise_ .set_exception (std::make_exception_ptr (std::system_error (ec.value (),std::system_category ())));
227227return ;
228228 }
229229
230- std::istreamis (&helper ->response_buffer_ );
230+ std::istreamis (&context ->response_buffer_ );
231231 string_type version;
232232 is >> version;
233233unsigned int status;
@@ -239,25 +239,25 @@ void client::impl::read_response_status(const boost::system::error_code &ec,
239239 res->set_status (network::http::v2::status::code (status));
240240 res->set_status_message (boost::trim_copy (message));
241241
242- helper ->connection_ ->async_read_until (helper ->response_buffer_ ,
242+ context ->connection_ ->async_read_until (context ->response_buffer_ ,
243243" \r\n\r\n " ,
244244 strand_.wrap ([=] (const boost::system::error_code &ec,
245245 std::size_t bytes_read) {
246- read_response_headers (ec, bytes_read,helper , res);
246+ read_response_headers (ec, bytes_read,context , res);
247247 }));
248248}
249249
250250void client::impl::read_response_headers (const boost::system::error_code &ec,
251251 std::size_t ,
252- std::shared_ptr<request_helper> helper ,
252+ std::shared_ptr<request_context> context ,
253253 std::shared_ptr<response> res) {
254254if (ec) {
255- helper ->response_promise_ .set_exception (std::make_exception_ptr (std::system_error (ec.value (),std::system_category ())));
255+ context ->response_promise_ .set_exception (std::make_exception_ptr (std::system_error (ec.value (),std::system_category ())));
256256return ;
257257 }
258258
259259// fill headers
260- std::istreamis (&helper ->response_buffer_ );
260+ std::istreamis (&context ->response_buffer_ );
261261 string_type header;
262262while (std::getline (is, header) && (header !=" \r " )) {
263263auto delim =boost::find_first_of (header," :" );
@@ -267,10 +267,10 @@ void client::impl::read_response_headers(const boost::system::error_code &ec,
267267 res->add_header (key, value);
268268 }
269269
270- helper ->connection_ ->async_read (helper ->response_buffer_ ,
270+ context ->connection_ ->async_read (context ->response_buffer_ ,
271271 strand_.wrap ([=] (const boost::system::error_code &ec,
272272 std::size_t bytes_read) {
273- read_response_body (ec, bytes_read,helper , res);
273+ read_response_body (ec, bytes_read,context , res);
274274 }));
275275}
276276
@@ -298,28 +298,28 @@ std::istream &getline_with_newline(std::istream &is, std::string &line) {
298298
299299void client::impl::read_response_body (const boost::system::error_code &ec,
300300 std::size_t bytes_read,
301- std::shared_ptr<request_helper> helper ,
301+ std::shared_ptr<request_context> context ,
302302 std::shared_ptr<response> res) {
303- helper ->total_bytes_read_ += bytes_read;
304- if (auto progress =helper ->options_ .progress ()) {
305- progress (client_message::transfer_direction::bytes_read,helper ->total_bytes_read_ );
303+ context ->total_bytes_read_ += bytes_read;
304+ if (auto progress =context ->options_ .progress ()) {
305+ progress (client_message::transfer_direction::bytes_read,context ->total_bytes_read_ );
306306 }
307307
308308if (bytes_read ==0 ) {
309- helper ->response_promise_ .set_value (*res);
309+ context ->response_promise_ .set_value (*res);
310310return ;
311311 }
312312
313- std::istreamis (&helper ->response_buffer_ );
313+ std::istreamis (&context ->response_buffer_ );
314314 string_type line;
315315while (!getline_with_newline (is, line).eof ()) {
316316 res->append_body (line);
317317 }
318318
319- helper ->connection_ ->async_read (helper ->response_buffer_ ,
319+ context ->connection_ ->async_read (context ->response_buffer_ ,
320320 strand_.wrap ([=] (const boost::system::error_code &ec,
321321 std::size_t bytes_read) {
322- read_response_body (ec, bytes_read,helper , res);
322+ read_response_body (ec, bytes_read,context , res);
323323 }));
324324}
325325
@@ -348,7 +348,7 @@ std::future<response> client::execute(request req, request_options options) {
348348// TODO factory based on HTTP or HTTPS
349349 connection = std::make_shared<client_connection::normal_connection>(pimpl_->io_service_ );
350350 }
351- return pimpl_->execute (std::make_shared<request_helper >(connection, req, options));
351+ return pimpl_->execute (std::make_shared<request_context >(connection, req, options));
352352}
353353
354354std::future<response>client::get (request req, request_options options) {