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
Formatted source code and add source comments.
  • Loading branch information
@glynos
glynos committedSep 20, 2014
commitccebaeb240f826ff4decf91fe6278c094ce12f21
1 change: 0 additions & 1 deletionhttp/src/http/v2/client/client.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,6 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <future>
#include <boost/asio/strand.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/predicate.hpp>
Expand Down
27 changes: 26 additions & 1 deletionhttp/src/network/http/v2/client/client.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@

namespace network {
namespace http {
namespace v2 {
inlinenamespace v2 {
namespace client_connection {
class async_resolver;
class async_connection;
Expand DownExpand Up@@ -177,6 +177,7 @@ class client_options {
* \brief Tells the client to use a proxy.
* \param use_proxy If \c true, then the client must use a
* proxy, if \c false it doesn't.
* \returns \c *this
*/
client_options &use_proxy(bool use_proxy) {
use_proxy_ = use_proxy;
Expand All@@ -195,6 +196,7 @@ class client_options {
/**
* \brief Sets the client timeout in milliseconds.
* \param timeout The timeout value in milliseconds.
* \returns \c *this
*/
client_options &timeout(std::chrono::milliseconds timeout) {
timeout_ = timeout;
Expand All@@ -212,6 +214,7 @@ class client_options {
/**
* \brief Adds an OpenSSL certificate path.
* \param path The certificate path.
* \returns \c *this
*/
client_options &openssl_certificate_path(std::string path) {
openssl_certificate_paths_.emplace_back(std::move(path));
Expand All@@ -229,6 +232,7 @@ class client_options {
/**
* \brief Adds an OpenSSL verify path.
* \param path The verify path.
* \returns \c *this
*/
client_options &openssl_verify_path(std::string path) {
openssl_verify_paths_.emplace_back(std::move(path));
Expand All@@ -243,20 +247,36 @@ class client_options {
return openssl_verify_paths_;
}

/**
* \brief
* \returns \c *this
*/
client_options &always_verify_peer(bool always_verify_peer) {
always_verify_peer_ = always_verify_peer;
return *this;
}

/**
* \brief
* \returns
*/
bool always_verify_peer() const {
return always_verify_peer_;
}

/**
* \brief
* \returns \c *this
*/
client_options &user_agent(const std::string &user_agent) {
user_agent_ = user_agent;
return *this;
}

/**
* \brief
* \returns
*/
std::string user_agent() const {
return user_agent_;
}
Expand All@@ -275,6 +295,11 @@ class client_options {

};

/**
* \brief
* \param lhs
* \param rhs
*/
inline
void swap(client_options &lhs, client_options &rhs) noexcept {
lhs.swap(rhs);
Expand Down
6 changes: 3 additions & 3 deletionshttp/src/network/http/v2/client/client_errors.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@

namespace network {
namespace http {
namespace v2 {
inlinenamespace v2 {
/**
* \ingroup http_client
* \enum client_error network/http/v2/client/client_errors.hpp network/http/v2/client.hpp
Expand All@@ -29,8 +29,8 @@ enum class client_error {
invalid_request,

// response
invalid_response,
};
invalid_response,
};

/**
* \brief Gets the error category for HTTP client errors.
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,7 +20,7 @@

namespace network {
namespace http {
namespace v2 {
inlinenamespace v2 {
namespace client_connection {
/**
* \class async_connection network/http/v2/client/connection/async_connection.hpp
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@

namespace network {
namespace http {
namespace v2 {
inlinenamespace v2 {
namespace client_connection {
/**
* \class async_resolver network/http/v2/client/connection/async_resolver.hpp
Expand Down
116 changes: 72 additions & 44 deletionshttp/src/network/http/v2/client/connection/endpoint_cache.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,52 +18,80 @@

namespace network {
namespace http {
namespace v2 {
inlinenamespace v2 {
namespace client_connection {

class endpoint_cache {

typedef boost::asio::ip::tcp::resolver resolver;

typedef resolver::iterator resolver_iterator;

typedef std::unordered_map<std::string,
resolver_iterator> cache_type;

public:

typedef cache_type::iterator iterator;

cache_type::iterator begin() {
return endpoints_.begin();
}

cache_type::iterator end() {
return endpoints_.end();
}

void insert(const std::string &host,
resolver_iterator endpoint_iterator) {
endpoints_.insert(std::make_pair(host, endpoint_iterator));
}

iterator find(const std::string &host) {
return endpoints_.find(boost::to_lower_copy(host));
}

void clear() {
endpoint_cache().swap(*this);
}

void swap(endpoint_cache &other) noexcept {
endpoints_.swap(other.endpoints_);
}

private:

cache_type endpoints_;

};
/**
* \class endpoint_cache network/http/v2/client/connection/endpoint_cache.hpp
* \brief
*/
class endpoint_cache {

/**
* \brief
*/
typedef boost::asio::ip::tcp::resolver resolver;

typedef resolver::iterator resolver_iterator;

typedef std::unordered_map<std::string,
resolver_iterator> cache_type;

public:

/**
* \brief
*/
typedef cache_type::iterator iterator;

/**
* \brief
*/
cache_type::iterator begin() {
return endpoints_.begin();
}

/**
* \brief
*/
cache_type::iterator end() {
return endpoints_.end();
}

/**
* \brief
*/
void insert(const std::string &host,
resolver_iterator endpoint_iterator) {
endpoints_.insert(std::make_pair(host, endpoint_iterator));
}

/**
* \brief
*/
iterator find(const std::string &host) {
return endpoints_.find(boost::to_lower_copy(host));
}

/**
* \brief
*/
void clear() {
endpoint_cache().swap(*this);
}

/**
* \brief
*/
void swap(endpoint_cache &other) noexcept {
endpoints_.swap(other.endpoints_);
}

private:

cache_type endpoints_;

};
} // namespace client_connection
} // namespace v2
} // namespace http
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,59 +21,70 @@

namespace network {
namespace http {
namespace v2 {
inlinenamespace v2 {
namespace client_connection {
class normal_connection : public async_connection {

normal_connection(const normal_connection &) = delete;
normal_connection &operator = (const normal_connection &) = delete;
/**
* \class
* \brief
*/
class normal_connection : public async_connection {

public:
normal_connection(const normal_connection &) = delete;
normal_connection &operator = (const normal_connection &) = delete;

explicit normal_connection(boost::asio::io_service &io_service)
: io_service_(io_service) {
public:

}
/**
* \brief
*/
explicit normal_connection(boost::asio::io_service &io_service)
: io_service_(io_service) {

virtual ~normal_connection() noexcept {
}

}
/**
* \brief Destructor.
*/
virtual ~normal_connection() noexcept {

virtual void async_connect(const boost::asio::ip::tcp::endpoint &endpoint,
const std::string &host,
connect_callback callback) {
using boost::asio::ip::tcp;
socket_.reset(new tcp::socket{io_service_});
socket_->async_connect(endpoint, callback);
}
}

virtual void async_write(boost::asio::streambuf &command_streambuf,
write_callback callback) {
boost::asio::async_write(*socket_, command_streambuf, callback);
}
virtual void async_connect(const boost::asio::ip::tcp::endpoint &endpoint,
const std::string &host,
connect_callback callback) {
using boost::asio::ip::tcp;
socket_.reset(new tcp::socket{io_service_});
socket_->async_connect(endpoint, callback);
}

virtual void async_read_until(boost::asio::streambuf &command_streambuf,
const std::string &delim,
read_callback callback) {
boost::asio::async_read_until(*socket_, command_streambuf, delim, callback);
}
virtual void async_write(boost::asio::streambuf &command_streambuf,
write_callback callback) {
boost::asio::async_write(*socket_, command_streambuf, callback);
}

virtual voidasync_read(boost::asio::streambuf &command_streambuf,
read_callback callback) {
boost::asio::async_read(*socket_, command_streambuf,
boost::asio::transfer_at_least(1), callback);
}
virtual voidasync_read_until(boost::asio::streambuf &command_streambuf,
const std::string &delim,
read_callback callback) {
boost::asio::async_read_until(*socket_, command_streambuf, delim, callback);
}

virtual void cancel() {
socket_->cancel();
}
virtual void async_read(boost::asio::streambuf &command_streambuf,
read_callback callback) {
boost::asio::async_read(*socket_, command_streambuf,
boost::asio::transfer_at_least(1), callback);
}

private:
virtual void cancel() {
socket_->cancel();
}

boost::asio::io_service &io_service_;
std::unique_ptr<boost::asio::ip::tcp::socket> socket_;
private:

};
boost::asio::io_service &io_service_;
std::unique_ptr<boost::asio::ip::tcp::socket> socket_;

};
} // namespace client_connection
} // namespace v2
} // namespace http
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp