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

Fix exception propagation for client errors#754

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
Show file tree
Hide file tree
Changes fromall commits
Commits
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
22 changes: 10 additions & 12 deletionsboost/network/protocol/http/client/connection/async_normal.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -160,11 +160,9 @@ struct http_async_connection
request_strand_(resolver.get_io_service()),
delegate_(std::move(delegate)) {}

// This is the main entry point for the connection/request pipeline.
// We're
// overriding async_connection_base<...>::start(...) here which is
// called
// by the client.
// This is the main entry point for the connection/request pipeline. We're
// overriding async_connection_base<...>::start(...) here which is called by
// the client.
virtual response start(request const& request, string_type const& method,
bool get_body, body_callback_function_type callback,
body_generator_function_type generator) {
Expand DownExpand Up@@ -198,13 +196,13 @@ struct http_async_connection
private:
void set_errors(boost::system::error_code const& ec, body_callback_function_type callback) {
boost::system::system_error error(ec);
this->version_promise.set_exception(std::make_exception_ptr(error));
this->status_promise.set_exception(std::make_exception_ptr(error));
this->status_message_promise.set_exception(std::make_exception_ptr(error));
this->headers_promise.set_exception(std::make_exception_ptr(error));
this->source_promise.set_exception(std::make_exception_ptr(error));
this->destination_promise.set_exception(std::make_exception_ptr(error));
this->body_promise.set_exception(std::make_exception_ptr(error));
this->version_promise.set_exception(boost::copy_exception(error));
this->status_promise.set_exception(boost::copy_exception(error));
this->status_message_promise.set_exception(boost::copy_exception(error));
this->headers_promise.set_exception(boost::copy_exception(error));
this->source_promise.set_exception(boost::copy_exception(error));
this->destination_promise.set_exception(boost::copy_exception(error));
this->body_promise.set_exception(boost::copy_exception(error));
if ( callback )
callback( boost::iterator_range<typename std::array<typename char_<Tag>::type, 1024>::const_iterator>(), ec );
this->timer_.cancel();
Expand Down
67 changes: 49 additions & 18 deletionsboost/network/protocol/http/message/async_message.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,13 +9,13 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <cstdint>
#include <boost/optional.hpp>
#include <cstdint>

// FIXME move this out to a trait
#include <set>
#include <boost/network/detail/wrapper_base.hpp>
#include <boost/thread/future.hpp>
#include <set>

namespace boost {
namespace network {
Expand All@@ -26,12 +26,11 @@ namespace impl {
template <class Tag>
struct ready_wrapper;

} // namespace impl
/* impl */
}// namespace impl
/* impl */

template <class Tag>
struct async_message {

typedef typename string<Tag>::type string_type;
typedef typename headers_container<Tag>::type headers_container_type;
typedef typename headers_container_type::value_type header_type;
Expand All@@ -54,63 +53,95 @@ struct async_message {
headers_(other.headers_),
body_(other.body_) {}

string_type const status_message() const { return status_message_.get(); }
string_type status_message() const {
status_message_.wait();
if (status_message_.has_exception())
boost::rethrow_exception(status_message_.get_exception_ptr());
return status_message_.get();
}

void status_message(boost::shared_future<string_type> const& future) const {
status_message_ = future;
}

string_type const version() const { return version_.get(); }
string_type version() const {
version_.wait();
if (version_.has_exception())
boost::rethrow_exception(version_.get_exception_ptr());
return version_.get();
}

void version(boost::shared_future<string_type> const& future) const {
version_ = future;
}

std::uint16_t status() const { return status_.get(); }
std::uint16_t status() const {
status_.wait();
if (status_.has_exception())
boost::rethrow_exception(status_.get_exception_ptr());
return status_.get();
}

void status(boost::shared_future<uint16_t> const& future) const {
status_ = future;
}

string_type const source() const { return source_.get(); }
string_type source() const {
source_.wait();
if (source_.has_exception())
boost::rethrow_exception(source_.get_exception_ptr());
return source_.get();
}

void source(boost::shared_future<string_type> const& future) const {
source_ = future;
}

string_type const destination() const { return destination_.get(); }
string_type destination() const {
destination_.wait();
if (destination_.has_exception())
boost::rethrow_exception(source_.get_exception_ptr());
return destination_.get();
}

void destination(boost::shared_future<string_type> const& future) const {
destination_ = future;
}

headers_container_type const& headers() const {
if (retrieved_headers_) return *retrieved_headers_;
if (headers_.has_exception())
boost::rethrow_exception(headers_.get_exception_ptr());
headers_container_type raw_headers = headers_.get();
raw_headers.insert(added_headers.begin(), added_headers.end());
for (string_type const& key : removed_headers) {
for (string_type const& key : removed_headers) {
raw_headers.erase(key);
}
retrieved_headers_ = raw_headers;
return *retrieved_headers_;
}

void headers(boost::shared_future<headers_container_type> const& future)
const {
void headers(
boost::shared_future<headers_container_type> const& future)const {
headers_ = future;
}

void add_header(typename headers_container_type::value_type const& pair_)
const {
void add_header(
typename headers_container_type::value_type const& pair_)const {
added_headers.insert(added_headers.end(), pair_);
}

void remove_header(typename headers_container_type::key_type const& key_)
const {
void remove_header(
typename headers_container_type::key_type const& key_)const {
removed_headers.insert(key_);
}

string_type const body() const { return body_.get(); }
string_type body() const {
body_.wait();
if (body_.has_exception())
boost::rethrow_exception(body_.get_exception_ptr());
return body_.get();
}

void body(boost::shared_future<string_type> const& future) const {
body_ = future;
Expand Down
11 changes: 11 additions & 0 deletionslibs/network/test/http/client_get_test.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
// Copyright 2010 Dean Michael Berris.
// Copyright 2017 Google, Inc.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
Expand DownExpand Up@@ -71,3 +72,13 @@ TYPED_TEST(HTTPClientTest, TemporaryClientObjectTest) {
EXPECT_TRUE(response.status() == 200u ||
(response.status() >= 300 && response.status() < 400));
}

TYPED_TEST(HTTPClientTest, PropagatesResolutionErrorsTest) {
using client = TypeParam;
typename client::request request("http://malformed.google.comq");
typename client::response response;
typename client::options options;
typename client::string_type response_body;
ASSERT_NO_THROW(response = client(options).get(request));
EXPECT_THROW(response_body = body(response), std::exception);
}

[8]ページ先頭

©2009-2025 Movatter.jp