Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jan 2, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions contrib/http_examples/simple_wget.cpp
Original file line number Diff line number Diff 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
489 changes: 307 additions & 182 deletions http/src/http/v2/client/client.cpp

Large diffs are not rendered by default.

74 changes: 30 additions & 44 deletions http/src/http/v2/client/client_errors.cpp
Original file line number Diff line number Diff 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 All @@ -9,71 +9,57 @@

namespace network {
namespace http {
namespace v2 {

inline namespace v2 {
class client_category_impl : public std::error_category {

public:

client_category_impl() = default;
public:
client_category_impl() = default;

virtual ~client_category_impl() noexcept;
virtual ~client_category_impl() noexcept override;

virtual const char *name() const noexcept;

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

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

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;
static const char name[] = "client_error";
return name;
}

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.";
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.";
}

const std::error_category &client_category() {
static client_category_impl client_category;
return 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());
return std::error_code(static_cast<int>(e), client_category());
}

invalid_url::invalid_url()
: std::invalid_argument("Requires HTTP or HTTPS 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() noexcept {

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

} // namespace v2
} // namespace network
} // namespace network
client_exception::~client_exception() noexcept {}
} // namespace v2
} // namespace http
} // namespace network
Loading