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
Added transfer direction callback.
  • Loading branch information
@glynos
glynos committedSep 20, 2014
commit2b1c0e260972a78547556057663e1a47f6dc568e
10 changes: 5 additions & 5 deletionscontrib/http_examples/simple_wget.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,11 +21,11 @@
namespace http = network::http;

namespace {
std::string get_filename(const std::string& path) {
auto index = path.find_last_of('/');
auto filename = path.substr(index + 1);
return filename.empty() ? "index.html" : filename;
}
std::string get_filename(const std::string& path) {
auto index = path.find_last_of('/');
auto filename = path.substr(index + 1);
return filename.empty() ? "index.html" : filename;
}
} // namespace

int main(int argc, char* argv[]) {
Expand Down
6 changes: 3 additions & 3 deletionshttp/src/http/v2/client/client.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2013 by Glyn Matthews
// Copyright (C) 2013, 2014 by Glyn Matthews
// 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@@ -206,7 +206,7 @@ void client::impl::read_response(const boost::system::error_code &ec,

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

std::shared_ptr<response> res(new response{});
Expand DownExpand Up@@ -302,7 +302,7 @@ void client::impl::read_response_body(const boost::system::error_code &ec,
std::shared_ptr<response> res) {
helper->total_bytes_read_ += bytes_read;
if (auto progress = helper->options_.progress()) {
progress(client_message::message_direction::bytes_read, helper->total_bytes_read_);
progress(client_message::transfer_direction::bytes_read, helper->total_bytes_read_);
}

if (bytes_read == 0) {
Expand Down
92 changes: 45 additions & 47 deletionshttp/src/http/v2/client/client_errors.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,72 +8,70 @@
#include <string>

namespace network {
namespace http {
namespace v2 {
namespace http {
namespace v2 {
class client_category_impl : public std::error_category {

class client_category_impl :public std::error_category {
public:

public:
client_category_impl() = default;

client_category_impl()= default;
virtual ~client_category_impl()noexcept;

virtual~client_category_impl() noexcept;
virtualconst char *name() const noexcept;

virtual const char *name() const noexcept;
virtual std::string message(int ev) const;

virtual std::string message(int ev) const;
};

};
client_category_impl::~client_category_impl() noexcept {

client_category_impl::~client_category_impl() noexcept {
}

}
const char *client_category_impl::name() const noexcept {
static const char name[] = "client_error";
return name;
}

const char *client_category_impl::name() const noexcept {
static const char name[] = "client_error";
return name;
}
std::string client_category_impl::message(int ev) const {
switch (client_error(ev)) {

std::string client_category_impl::message(int ev) const {
switch (client_error(ev)) {
case client_error::invalid_request:
return "Invalid HTTP request.";
case client_error::invalid_response:
return "Invalid HTTP response.";
default:
break;
}
return "Unknown client error.";
}

case client_error::invalid_request:
return "Invalid HTTP request.";
case client_error::invalid_response:
return "Invalid HTTP response.";
default:
break;
}
return "Unknown client error.";
}
const std::error_category &client_category() {
static client_category_impl client_category;
return client_category;
}

const std::error_category &client_category() {
static client_category_impl client_category;
return client_category;
}
std::error_code make_error_code(client_error e) {
return std::error_code(static_cast<int>(e), client_category());
}

std::error_code make_error_code(client_error e) {
return std::error_code(static_cast<int>(e), client_category());
}
invalid_url::invalid_url()
: std::invalid_argument("Requires HTTP or HTTPS URL.") {

invalid_url::invalid_url()
: std::invalid_argument("Requires HTTP or HTTPS URL.") {
}

}
invalid_url::~invalid_url() noexcept {

invalid_url::~invalid_url() noexcept {
}

}
client_exception::client_exception(client_error error)
: std::system_error(make_error_code(error)) {

client_exception::client_exception(client_error error)
: std::system_error(make_error_code(error)) {
}

}
client_exception::~client_exception() noexcept {

client_exception::~client_exception() noexcept {

}

} // namespace v2
} // namespace network
}
} // namespace v2
} // namespace http
} // namespace network
138 changes: 69 additions & 69 deletionshttp/src/network/http/v2/client/client_errors.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,75 +17,75 @@
#include <network/config.hpp>

namespace network {
namespace http {
namespace v2 {
/**
* \ingroup http_client
* \enum client_error network/http/v2/client/client_errors.hpp network/http/v2/client.hpp
* \brief An enumeration of all types of client error.
*/
enum class client_error {
// request
invalid_request,

// response
invalid_response,
};

/**
* \brief Gets the error category for HTTP client errors.
*/
const std::error_category &client_category();

/**
* \brief Makes an error code object from a client_error enum.
*/
std::error_code make_error_code(client_error e);

/**
* \ingroup http_client
* \class invalid_url network/http/v2/client/client_errors.hpp network/http/v2/client.hpp
* \brief An exception thrown if the URL provides is invalid.
*/
class invalid_url : public std::invalid_argument {

public:

/**
* \brief Constructor.
*/
explicit invalid_url();

/**
* \brief Destructor.
*/
virtual ~invalid_url() noexcept;

};

/**
* \ingroup http_client
* \class client_exception network/http/v2/client/client_errors.hpp network/http/v2/client.hpp
* \brief An exception thrown when there is a client error.
*/
class client_exception : public std::system_error {

public:

/**
* \brief Constructor.
*/
explicit client_exception(client_error error);

/**
* \brief Destructor.
*/
virtual ~client_exception() noexcept;

};

} // namespace v2
} // namespace http
namespace http {
namespace v2 {
/**
* \ingroup http_client
* \enum client_error network/http/v2/client/client_errors.hpp network/http/v2/client.hpp
* \brief An enumeration of all types of client error.
*/
enum class client_error {
// request
invalid_request,

// response
invalid_response,
};

/**
* \brief Gets the error category for HTTP client errors.
*/
const std::error_category &client_category();

/**
* \brief Makes an error code object from a client_error enum.
*/
std::error_code make_error_code(client_error e);

/**
* \ingroup http_client
* \class invalid_url network/http/v2/client/client_errors.hpp network/http/v2/client.hpp
* \brief An exception thrown if the URL provides is invalid.
*/
class invalid_url : public std::invalid_argument {

public:

/**
* \brief Constructor.
*/
explicit invalid_url();

/**
* \brief Destructor.
*/
virtual ~invalid_url() noexcept;

};

/**
* \ingroup http_client
* \class client_exception network/http/v2/client/client_errors.hpp network/http/v2/client.hpp
* \brief An exception thrown when there is a client error.
*/
class client_exception : public std::system_error {

public:

/**
* \brief Constructor.
*/
explicit client_exception(client_error error);

/**
* \brief Destructor.
*/
virtual ~client_exception() noexcept;

};

} // namespace v2
} // namespace http
} // namespace network

#endif // NETWORK_HTTP_V2_CLIENT_CLIENT_ERRORS_INC
8 changes: 4 additions & 4 deletionshttp/src/network/http/v2/client/request.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ namespace network {
namespace http {
namespace v2 {
namespace client_message {
enum classmessage_direction {
enum classtransfer_direction {
bytes_written, bytes_read,
};

Expand DownExpand Up@@ -135,12 +135,12 @@ class request_options {
return max_redirects_;
}

request_options &progress(std::function<void (message_direction, std::uint64_t)> handler) {
request_options &progress(std::function<void (transfer_direction, std::uint64_t)> handler) {
progress_handler_ = handler;
return *this;
}

std::function<void (message_direction, std::uint64_t)> progress() const {
std::function<void (transfer_direction, std::uint64_t)> progress() const {
return progress_handler_;
}

Expand All@@ -150,7 +150,7 @@ class request_options {
std::uint64_t read_timeout_;
std::uint64_t total_timeout_;
int max_redirects_;
std::function<void (message_direction, std::uint64_t)> progress_handler_;
std::function<void (transfer_direction, std::uint64_t)> progress_handler_;

};

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp