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
Simplified the HTTP client, request and response classes.
  • Loading branch information
@glynos
glynos committedDec 25, 2014
commit42ab79d83d5ecb4d796dbb206a6fcbbc1df43dc8
9 changes: 5 additions & 4 deletionshttp/src/http/v2/client/client.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@
// http://www.boost.org/LICENSE_1_0.txt)

#include <boost/asio/strand.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/range/algorithm/find_first_of.hpp>
Expand DownExpand Up@@ -143,8 +144,6 @@ namespace network {
std::shared_ptr<request_context> context) {
std::future<response> res = context->response_promise_.get_future();

// TODO see linearize.hpp

// If there is no user-agent, provide one as a default.
auto user_agent = context->request_.header("User-Agent");
if (!user_agent) {
Expand DownExpand Up@@ -330,11 +329,13 @@ namespace network {

// if options_.follow_redirects()
// and if status in range 300 - 307
// then take the request and reset the URL
// then take the request and reset the URL from the 'Location' header
// restart connection
// Not that the 'Location' header can be a *relative* URI

std::shared_ptr<response> res(new response{});
res->set_version(version);
res->set_status(network::http::v2::status::code(status));
res->set_status(network::http::status::code(status));
res->set_status_message(boost::trim_copy(message));

// Read the response headers.
Expand Down
50 changes: 4 additions & 46 deletionshttp/src/network/http/v2/client/client.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,8 +20,6 @@
#include <string>
#include <vector>
#include <chrono>
#include <boost/asio/io_service.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/optional.hpp>
#include <network/config.hpp>
#include <network/version.hpp>
Expand DownExpand Up@@ -49,8 +47,7 @@ class client_options {
* \brief Constructor.
*/
client_options()
: io_service_(boost::none)
, follow_redirects_(false)
: follow_redirects_(false)
, cache_resolved_(false)
, use_proxy_(false)
, always_verify_peer_(false)
Expand All@@ -60,30 +57,12 @@ class client_options {
/**
* \brief Copy constructor.
*/
client_options(const client_options &other)
: io_service_(other.io_service_)
, follow_redirects_(other.follow_redirects_)
, cache_resolved_(other.cache_resolved_)
, use_proxy_(other.use_proxy_)
, always_verify_peer_(other.always_verify_peer_)
, user_agent_(other.user_agent_)
, timeout_(other.timeout_)
, openssl_certificate_paths_(other.openssl_certificate_paths_)
, openssl_verify_paths_(other.openssl_verify_paths_) { }
client_options(const client_options &other) = default;

/**
* \brief Move constructor.
*/
client_options(client_options &&other)
: io_service_(std::move(other.io_service_))
, follow_redirects_(std::move(other.follow_redirects_))
, cache_resolved_(std::move(other.cache_resolved_))
, use_proxy_(std::move(other.use_proxy_))
, always_verify_peer_(std::move(other.always_verify_peer_))
, user_agent_(std::move(other.user_agent_))
, timeout_(std::move(other.timeout_))
, openssl_certificate_paths_(std::move(other.openssl_certificate_paths_))
, openssl_verify_paths_(std::move(other.openssl_verify_paths_)) { }
client_options(client_options &&other) = default;

/**
* \brief Assignment operator.
Expand All@@ -96,16 +75,13 @@ class client_options {
/**
* \brief Destructor.
*/
~client_options() {

}
~client_options() = default;

/**
* \brief Swap.
*/
void swap(client_options &other) noexcept {
using std::swap;
std::swap(io_service_, other.io_service_);
swap(follow_redirects_, other.follow_redirects_);
swap(cache_resolved_, other.cache_resolved_);
swap(use_proxy_, other.use_proxy_);
Expand All@@ -116,23 +92,6 @@ class client_options {
swap(openssl_verify_paths_, other.openssl_verify_paths_);
}

/**
* \brief Overrides the client's I/O service.
* \param io_service The new io_service object to use.
*/
client_options &io_service(boost::asio::io_service &io_service) {
io_service_ = io_service;
return *this;
}

/**
* \brief Gets the overridden I/O service.
* \returns An optional io_service object.
*/
boost::optional<boost::asio::io_service &> io_service() const {
return io_service_;
}

/**
* \brief Tells the client to follow redirects.
* \param follow_redirects If \c true, then the client must
Expand DownExpand Up@@ -284,7 +243,6 @@ class client_options {

private:

boost::optional<boost::asio::io_service &> io_service_;
bool follow_redirects_;
bool cache_resolved_;
bool use_proxy_;
Expand Down
120 changes: 43 additions & 77 deletionshttp/src/network/http/v2/client/request.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,20 +62,12 @@ class request_options {
/**
* \brief Copy constructor.
*/
request_options(request_options const &other)
: resolve_timeout_(other.resolve_timeout_)
, read_timeout_(other.read_timeout_)
, total_timeout_(other.total_timeout_)
, max_redirects_(other.max_redirects_) { }
request_options(request_options const &other) = default;

/**
* \brief Move constructor.
*/
request_options(request_options &&other)
: resolve_timeout_(std::move(other.resolve_timeout_))
, read_timeout_(std::move(other.read_timeout_))
, total_timeout_(std::move(other.total_timeout_))
, max_redirects_(std::move(other.max_redirects_)) { }
request_options(request_options &&other) = default;

/**
* \brief Assignment operator.
Expand All@@ -88,9 +80,7 @@ class request_options {
/**
* \brief Destructor.
*/
~request_options() {

}
~request_options() = default;

/**
* \brief
Expand DownExpand Up@@ -312,14 +302,49 @@ class request {
/**
* \brief Constructor.
*/
request()
: byte_source_(nullptr) { }
request() = default;

/**
* \brief Constructor.
*/
explicit request(uri url)
: url_(url) {
explicit request(uri url) {
this->url(url);
}

/**
* \brief Copy constructor.
*/
request(const request &other) = default;

/**
* \brief Move constructor.
*/
request(request &&other) noexcept = default;

/**
* \brief Destructor.
*/
~request() = default;

/**
* \brief Swaps one request object with another.
* \param other The other request object.
*/
void swap(request &other) noexcept {
using std::swap;
swap(url_, other.url_);
swap(method_, other.method_);
swap(path_, other.path_);
swap(version_, other.version_);
swap(headers_, other.headers_);
swap(byte_source_, other.byte_source_);
}

/**
* \brief
* \returns
*/
request &url(const uri &url) {
if (auto scheme = url.scheme()) {
if ((!boost::equal(*scheme, boost::as_literal("http"))) &&
(!boost::equal(*scheme, boost::as_literal("https")))) {
Expand DownExpand Up@@ -356,65 +381,6 @@ class request {
else {
throw invalid_url();
}
}

/**
* \brief Copy constructor.
*/
request(const request &other)
: url_(other.url_)
, method_(other.method_)
, path_(other.path_)
, version_(other.version_)
, headers_(other.headers_)
, byte_source_(other.byte_source_) { }

/**
* \brief Move constructor.
*/
request(request &&other) noexcept
: url_(std::move(other.url_))
, method_(std::move(other.method_))
, path_(std::move(other.path_))
, version_(std::move(other.version_))
, headers_(std::move(other.headers_))
, byte_source_(std::move(other.byte_source_)) { }

/**
* \brief Assignment operator.
*/
request &operator = (request other) {
other.swap(*this);
return *this;
}

/**
* \brief Destructor.
*/
~request() {

}

/**
* \brief Swaps one request object with another.
* \param other The other request object.
*/
void swap(request &other) noexcept {
using std::swap;
swap(url_, other.url_);
swap(method_, other.method_);
swap(path_, other.path_);
swap(version_, other.version_);
swap(headers_, other.headers_);
swap(byte_source_, other.byte_source_);
}

/**
* \brief
* \returns
*/
request &url(const uri &url) {
// throw invalid_url
url_ = url;
return *this;
}
Expand DownExpand Up@@ -516,7 +482,7 @@ class request {
* Duplicates are allowed.
*/
request &append_header(string_type name, string_type value) {
headers_.emplace_back(std::make_pair(name, value));
headers_.emplace_back(name, value);
return *this;
}

Expand Down
29 changes: 3 additions & 26 deletionshttp/src/network/http/v2/client/response.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,42 +63,19 @@ class response {
/**
* \brief Constructor.
*/
response(){ }
response()= default;

/**
* \brief Copy constructor.
* \param other The other response object.
*/
response(const response &other)
: version_(other.version_)
, status_(other.status_)
, status_message_(other.status_message_)
, headers_(other.headers_)
, body_(other.body_) {

}
response(const response &other) = default;

/**
* \brief Move constructor.
* \param other The other response object.
*/
response(response &&other) noexcept
: version_(std::move(other.version_))
, status_(std::move(other.status_))
, status_message_(std::move(other.status_message_))
, headers_(std::move(other.headers_))
, body_(std::move(other.body_)) {

}

/**
* \brief Assignment operator.
* \param other The other response object.
*/
response &operator= (response other) {
other.swap(*this);
return *this;
}
response(response &&other) noexcept = default;

/**
* \brief Swap function.
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp