Skip to content

Commit 2c44282

Browse files
committed
Merge pull request cpp-netlib#476 from glynos/master
Refactored HTTP client v2.
2 parents 28c7400 + 42ab79d commit 2c44282

18 files changed

+1969
-1733
lines changed

contrib/http_examples/simple_wget.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
namespace http = network::http;
2222

2323
namespace {
24-
std::string get_filename(const std::string& path) {
25-
auto index = path.find_last_of('/');
26-
auto filename = path.substr(index + 1);
27-
return filename.empty() ? "index.html" : filename;
28-
}
24+
std::string get_filename(const std::string& path) {
25+
auto index = path.find_last_of('/');
26+
auto filename = path.substr(index + 1);
27+
return filename.empty() ? "index.html" : filename;
28+
}
2929
} // namespace
3030

3131
int main(int argc, char* argv[]) {

http/src/http/v2/client/client.cpp

Lines changed: 307 additions & 182 deletions
Large diffs are not rendered by default.
Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2013 by Glyn Matthews
1+
// Copyright (C) 2013, 2014 by Glyn Matthews
22
// Distributed under the Boost Software License, Version 1.0.
33
// (See accompanying file LICENSE_1_0.txt or copy at
44
// http://www.boost.org/LICENSE_1_0.txt)
@@ -9,71 +9,57 @@
99

1010
namespace network {
1111
namespace http {
12-
namespace v2 {
13-
12+
inline namespace v2 {
1413
class client_category_impl : public std::error_category {
1514

16-
public:
17-
18-
client_category_impl() = default;
15+
public:
16+
client_category_impl() = default;
1917

20-
virtual ~client_category_impl() noexcept;
18+
virtual ~client_category_impl() noexcept override;
2119

22-
virtual const char *name() const noexcept;
23-
24-
virtual std::string message(int ev) const;
20+
virtual const char *name() const noexcept override;
2521

22+
virtual std::string message(int ev) const override;
2623
};
2724

28-
client_category_impl::~client_category_impl() noexcept {
29-
30-
}
25+
client_category_impl::~client_category_impl() noexcept {}
3126

3227
const char *client_category_impl::name() const noexcept {
33-
static const char name[] = "client_error";
34-
return name;
28+
static const char name[] = "client_error";
29+
return name;
3530
}
3631

3732
std::string client_category_impl::message(int ev) const {
38-
switch (client_error(ev)) {
39-
40-
case client_error::invalid_request:
41-
return "Invalid HTTP request.";
42-
case client_error::invalid_response:
43-
return "Invalid HTTP response.";
44-
default:
45-
break;
46-
}
47-
return "Unknown client error.";
33+
switch (client_error(ev)) {
34+
35+
case client_error::invalid_request:
36+
return "Invalid HTTP request.";
37+
case client_error::invalid_response:
38+
return "Invalid HTTP response.";
39+
default:
40+
break;
41+
}
42+
return "Unknown client error.";
4843
}
4944

5045
const std::error_category &client_category() {
51-
static client_category_impl client_category;
52-
return client_category;
46+
static client_category_impl client_category;
47+
return client_category;
5348
}
5449

5550
std::error_code make_error_code(client_error e) {
56-
return std::error_code(static_cast<int>(e), client_category());
51+
return std::error_code(static_cast<int>(e), client_category());
5752
}
5853

5954
invalid_url::invalid_url()
60-
: std::invalid_argument("Requires HTTP or HTTPS URL.") {
61-
62-
}
55+
: std::invalid_argument("Requires HTTP or HTTPS URL.") {}
6356

64-
invalid_url::~invalid_url() noexcept {
65-
66-
}
57+
invalid_url::~invalid_url() noexcept {}
6758

6859
client_exception::client_exception(client_error error)
69-
: std::system_error(make_error_code(error)) {
70-
71-
}
72-
73-
client_exception::~client_exception() noexcept {
74-
75-
}
60+
: std::system_error(make_error_code(error)) {}
7661

77-
} // namespace v2
78-
} // namespace network
79-
} // namespace network
62+
client_exception::~client_exception() noexcept {}
63+
} // namespace v2
64+
} // namespace http
65+
} // namespace network

0 commit comments

Comments
 (0)