Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Refactored HTTP client v2.#476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
deanberris merged 17 commits intocpp-netlib:masterfromglynos:master
Jan 2, 2015
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
17 commits
Select commitHold shift + click to select a range
0b49d2b
Added a facility to track upload/download progress.
glynosFeb 16, 2014
1bc435b
Removed ssl_connection from client.
glynosFeb 17, 2014
2b1c0e2
Added transfer direction callback.
glynosMar 23, 2014
d00f99f
Renamed request_helper as request_context.
glynosMar 23, 2014
47ced49
Updated uri submodule.
glynosMar 26, 2014
03dddb2
Removed noexcept from destructors; added some flags for chunked trans…
glynosApr 12, 2014
ccebaeb
Formatted source code and add source comments.
glynosMay 11, 2014
ad273ec
Added some comments; fixed tests so that they compile for Boost.Optio…
glynosSep 10, 2014
862263d
Updated uri submodule.
glynosSep 10, 2014
4f2f0e2
Formatted files with clang-format.
glynosSep 10, 2014
907a176
Updated uri submodule.
glynosSep 21, 2014
ff5f714
Merge remote-tracking branch 'upstream/master'
glynosDec 19, 2014
4e0add7
Use std::unique_ptr for pimpl idiom in HTTP client.
glynosDec 24, 2014
6771a55
Added connection timeout check to HTTP client.
glynosDec 24, 2014
50f3a4c
Fixed bug in error handling in the HTTP client.
glynosDec 24, 2014
e2da305
Minor refactoring in the HTTP client.
glynosDec 24, 2014
42ab79d
Simplified the HTTP client, request and response classes.
glynosDec 25, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Removed noexcept from destructors; added some flags for chunked trans…
…fer and timeouts.
  • Loading branch information
@glynos
glynos committedSep 20, 2014
commit03dddb20b86f6bcd5e7429a7c469f24490550589
53 changes: 43 additions & 10 deletionshttp/src/http/v2/client/client.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,16 +34,22 @@ struct request_context {
boost::asio::streambuf request_buffer_;
boost::asio::streambuf response_buffer_;

// TODO configure chunked transfer encoding
bool chunked_;

// TODO configure deadline timer for timeouts
bool timedout_;

std::uint64_t total_bytes_written_, total_bytes_read_;

request_context(std::shared_ptr<client_connection::async_connection> connection,
request request,
request_options options)
request request,
request_options options)
: connection_(connection)
, request_(request)
, options_(options)
, chunked_(false)
, timedout_(false)
, total_bytes_written_(0)
, total_bytes_read_(0) { }

Expand All@@ -57,7 +63,7 @@ struct client::impl {
std::unique_ptr<client_connection::async_connection> mock_connection,
client_options options);

~impl() noexcept;
~impl();

std::future<response> execute(std::shared_ptr<request_context> context);

Expand All@@ -68,6 +74,10 @@ struct client::impl {
void write_request(const boost::system::error_code &ec,
std::shared_ptr<request_context> context);

void write_body(const boost::system::error_code &ec,
std::size_t bytes_written,
std::shared_ptr<request_context> context);

void read_response(const boost::system::error_code &ec,
std::size_t bytes_written,
std::shared_ptr<request_context> context);
Expand DownExpand Up@@ -117,7 +127,7 @@ client::impl::impl(std::unique_ptr<client_connection::async_resolver> mock_resol

}

client::impl::~impl()noexcept{
client::impl::~impl() {
sentinel_.reset();
lifetime_thread_.join();
}
Expand DownExpand Up@@ -186,14 +196,37 @@ void client::impl::write_request(const boost::system::error_code &ec,
context->response_promise_.set_exception(std::make_exception_ptr(client_exception(client_error::invalid_request)));
}

context->connection_->async_write(context->request_buffer_,
strand_.wrap([=] (const boost::system::error_code &ec,
std::size_t bytes_written) {
write_body(ec, bytes_written, context);
}));
}

void client::impl::write_body(const boost::system::error_code &ec,
std::size_t bytes_written,
std::shared_ptr<request_context> context) {
if (ec) {
context->response_promise_.set_exception(std::make_exception_ptr(std::system_error(ec.value(), std::system_category())));
return;
}

context->total_bytes_written_ += bytes_written;
if (auto progress = context->options_.progress()) {
progress(client_message::transfer_direction::bytes_written, context->total_bytes_written_);
}

std::ostream request_stream(&context->request_buffer_);
// TODO write payload to request_buffer_
if (!request_stream) {
context->response_promise_.set_exception(std::make_exception_ptr(client_exception(client_error::invalid_request)));
}

context->connection_->async_write(context->request_buffer_,
strand_.wrap([=] (const boost::system::error_code &ec,
std::size_t bytes_written) {
// TODO write chunked or write body
read_response(ec, bytes_written, context);
}));
strand_.wrap([=] (const boost::system::error_code &ec,
std::size_t bytes_written) {
read_response(ec, bytes_written, context);
}));
}

void client::impl::read_response(const boost::system::error_code &ec,
Expand DownExpand Up@@ -335,7 +368,7 @@ client::client(std::unique_ptr<client_connection::async_resolver> mock_resolver,

}

client::~client()noexcept{
client::~client() {
delete pimpl_;
}

Expand Down
4 changes: 2 additions & 2 deletionshttp/src/network/http/v2/client/client.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -95,7 +95,7 @@ class client_options {
/**
* \brief Destructor.
*/
~client_options()noexcept{
~client_options() {

}

Expand DownExpand Up@@ -316,7 +316,7 @@ class client {
/**
* \brief Destructor.
*/
~client() noexcept;
~client();

/**
* \brief Executes an HTTP request.
Expand Down
6 changes: 3 additions & 3 deletionshttp/src/network/http/v2/client/request.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -88,7 +88,7 @@ class request_options {
/**
* \brief Destructor.
*/
~request_options()noexcept{
~request_options() {

}

Expand DownExpand Up@@ -184,7 +184,7 @@ class byte_source {
/**
* \brief Destructor.
*/
virtual ~byte_source()noexcept{}
virtual ~byte_source() {}

/**
* \brief Allows the request to read the data into a local
Expand DownExpand Up@@ -342,7 +342,7 @@ class request {
/**
* \brief Destructor.
*/
~request()noexcept{
~request() {

}

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp