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

Commit40e3b59

Browse files
committed
Added HTTP constants for client 1.0.x.
1 parent70a99a9 commit40e3b59

File tree

13 files changed

+714
-303
lines changed

13 files changed

+714
-303
lines changed

‎http/src/CMakeLists.txt‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,27 @@ if(NOT CPP-NETLIB_BUILD_SINGLE_LIB)
102102
)
103103
endif()
104104

105+
set(CPP-NETLIB_HTTP_CLIENT-V2_SRCS
106+
${CMAKE_CURRENT_SOURCE_DIR}/http/v2/constants.cpp)
107+
add_library(network-http-client-v2 ${CPP-NETLIB_HTTP_CLIENT-V2_SRCS})
108+
add_dependencies(network-http-client-v2
109+
cppnetlib-uri
110+
)
111+
target_link_libraries(network-http-client-v2
112+
${Boost_LIBRARIES}
113+
cppnetlib-uri
114+
)
115+
105116
# prepend current directory to make paths absolute
106117
prependToElements("${CMAKE_CURRENT_SOURCE_DIR}/"
107118
CPP-NETLIB_HTTP_MESSAGE_SRCS
108119
CPP-NETLIB_HTTP_MESSAGE_WRAPPERS_SRCS
109120
CPP-NETLIB_HTTP_CLIENT_CONNECTIONS_SRCS
110121
CPP-NETLIB_CONSTANTS_SRCS
111122
CPP-NETLIB_HTTP_SERVER_SRCS
112-
CPP-NETLIB_HTTP_CLIENT_SRCS )
123+
CPP-NETLIB_HTTP_CLIENT_SRCS
124+
CPP-NETLIB_HTTP_CLIENT-V2_SRCS )
125+
113126

114127
# propagate sources to parent directory for one-lib-build
115128
set(CPP-NETLIB_HTTP_MESSAGE_SRCS ${CPP-NETLIB_HTTP_MESSAGE_SRCS} PARENT_SCOPE)
@@ -118,3 +131,4 @@ set(CPP-NETLIB_HTTP_CLIENT_CONNECTIONS_SRCS ${CPP-NETLIB_HTTP_CLIENT_CONNECTIONS
118131
set(CPP-NETLIB_HTTP_CLIENT_SRCS ${CPP-NETLIB_HTTP_CLIENT_SRCS} PARENT_SCOPE)
119132
set(CPP-NETLIB_HTTP_SERVER_SRCS ${CPP-NETLIB_HTTP_SERVER_SRCS} PARENT_SCOPE)
120133
set(CPP-NETLIB_CONSTANTS_SRCS ${CPP-NETLIB_CONSTANTS_SRCS} PARENT_SCOPE)
134+
set(CPP-NETLIB_HTTP_CLIENT-V2_SRCS ${CPP-NETLIB_HTTP_CLIENT-V2_SRCS} PARENT SCOPE)

‎http/src/http/v2/constants.cpp‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (C) 2013 by Glyn Matthews
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
#include<network/http/v2/constants.hpp>
7+
#include<unordered_map>
8+
9+
static std::unordered_map<int, std::string>status_message_map() {
10+
std::unordered_map<int, std::string> status_messages;
11+
status_messages[100] ="Continue";
12+
status_messages[101] ="Switching Protocols";
13+
status_messages[200] ="OK";
14+
status_messages[201] ="Created";
15+
status_messages[202] ="Accepted";
16+
status_messages[203] ="Non-Authoritative Information";
17+
status_messages[204] ="No Content";
18+
status_messages[205] ="Reset Content";
19+
status_messages[206] ="Partial Content";
20+
status_messages[300] ="Multiple Choices";
21+
status_messages[301] ="Moved Permanently";
22+
status_messages[302] ="Found";
23+
status_messages[303] ="See Other";
24+
status_messages[304] ="Not Modified";
25+
status_messages[305] ="Use Proxy";
26+
status_messages[307] ="Temporary Redirect";
27+
status_messages[400] ="Bad Request";
28+
status_messages[401] ="Unauthorized";
29+
status_messages[402] ="Payment Required";
30+
status_messages[403] ="Forbidden";
31+
status_messages[404] ="Not Found";
32+
status_messages[405] ="Method Not Allowed";
33+
status_messages[406] ="Not Acceptable";
34+
status_messages[407] ="Proxy Authentication Required";
35+
status_messages[408] ="Request Timeout";
36+
status_messages[409] ="Conflict";
37+
status_messages[410] ="Gone";
38+
status_messages[411] ="Length Required";
39+
status_messages[412] ="Precondition Failed";
40+
status_messages[413] ="Request Entity Too Large";
41+
status_messages[414] ="Request Uri Too Large";
42+
status_messages[415] ="Unsupported Media Type";
43+
status_messages[416] ="Request Range Not Satisfiable";
44+
status_messages[417] ="Expectation Failed";
45+
status_messages[500] ="Internal Error";
46+
status_messages[501] ="Not Implemented";
47+
status_messages[502] ="Bad Gateway";
48+
status_messages[503] ="Service Unavailable";
49+
status_messages[504] ="Gateway Timeout";
50+
status_messages[505] ="HTTP Version Not Supported";
51+
}
52+
53+
54+
std::stringstatus_message(int status_code) {
55+
staticconstauto status_messages =status_message_map();
56+
auto it = status_messages.find(status_code);
57+
if (it != status_messages.end()) {
58+
return it->second;
59+
}
60+
return"Invalid Status Code";
61+
}

‎http/src/network/http/v2/client/client.hpp‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
#include<cstdint>
1010

1111
namespacenetwork {
12-
namespacehttp {
13-
namespacev2 {
14-
classclient {
12+
namespacehttp {
13+
namespacev2 {
14+
classclient {
1515

16-
public:
16+
public:
1717

18-
client() { }
19-
client(clientconst &) =delete;
20-
client(client &&) =delete;
18+
client() { }
19+
client(clientconst &) =delete;
20+
client(client &&) =delete;
2121

22-
};
23-
}// namespace v2
24-
}// namespace http
22+
};
23+
}// namespace v2
24+
}// namespace http
2525
}// namespace network
2626

2727
#endif// __NETWORK_HTTP_V2_CLIENT_INC__

‎http/src/network/http/v2/client/client_options.hpp‎

Lines changed: 96 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -13,102 +13,102 @@
1313
#include<chrono>
1414

1515
namespacenetwork {
16-
namespacehttp {
17-
namespacev2 {
18-
classclient_options {
19-
20-
public:
21-
22-
// default timeout is 30 seconds
23-
client_options()
24-
: follow_redirects_(false)
25-
, cache_resolved_(false)
26-
, use_proxy_(false)
27-
, timeout_(30000) { }
28-
29-
client_options(client_optionsconst &) =default;
30-
client_options(client_options &&) =default;
31-
32-
client_options &operator = (client_options other) {
33-
other.swap(*this);
34-
return *this;
35-
}
36-
37-
voidswap(client_options &other)noexcept {
38-
std::swap(follow_redirects_, other.follow_redirects_);
39-
std::swap(cache_resolved_, other.cache_resolved_);
40-
std::swap(use_proxy_, other.use_proxy_);
41-
std::swap(timeout_, other.timeout_);
42-
std::swap(openssl_certificate_paths_, other.openssl_certificate_paths_);
43-
std::swap(openssl_verify_paths_, other.openssl_verify_paths_);
44-
}
45-
46-
client_options &follow_redirects(bool follow_redirects)noexcept {
47-
follow_redirects_ = follow_redirects;
48-
return *this;
49-
}
50-
51-
boolfollow_redirects()constnoexcept {
52-
return follow_redirects_;
53-
}
54-
55-
client_options &cache_resolved(bool cache_resolved)noexcept {
56-
cache_resolved_ = cache_resolved;
57-
return *this;
58-
}
59-
60-
boolcache_resolved()constnoexcept {
61-
return cache_resolved_;
62-
}
63-
64-
client_options &use_proxy(bool use_proxy)noexcept {
65-
use_proxy_ = use_proxy;
66-
return *this;
67-
}
68-
69-
booluse_proxy()constnoexcept {
70-
return use_proxy_;
71-
}
72-
73-
client_options &timeout(std::chrono::milliseconds timeout)noexcept {
74-
timeout_ = timeout;
75-
return *this;
76-
}
77-
78-
std::chrono::millisecondstimeout()constnoexcept {
79-
return timeout_;
80-
}
81-
82-
client_options &openssl_certificate_path(std::string path) {
83-
openssl_certificate_paths_.emplace_back(std::move(path));
84-
return *this;
85-
}
86-
87-
std::vector<std::string>openssl_certificate_paths()const {
88-
return openssl_certificate_paths_;
89-
}
90-
91-
client_options &openssl_verify_path(std::string path) {
92-
openssl_verify_paths_.emplace_back(std::move(path));
93-
return *this;
94-
}
95-
96-
std::vector<std::string>openssl_verify_paths()const {
97-
return openssl_verify_paths_;
98-
}
99-
100-
private:
101-
102-
bool follow_redirects_;
103-
bool cache_resolved_;
104-
bool use_proxy_;
105-
std::chrono::milliseconds timeout_;
106-
std::vector<std::string> openssl_certificate_paths_;
107-
std::vector<std::string> openssl_verify_paths_;
108-
109-
};
110-
}// namespace v2
111-
}// namespace http
16+
namespacehttp {
17+
namespacev2 {
18+
classclient_options {
19+
20+
public:
21+
22+
// default timeout is 30 seconds
23+
client_options()
24+
: follow_redirects_(false)
25+
, cache_resolved_(false)
26+
, use_proxy_(false)
27+
, timeout_(30000) { }
28+
29+
client_options(client_optionsconst &) =default;
30+
client_options(client_options &&) =default;
31+
32+
client_options &operator = (client_options other) {
33+
other.swap(*this);
34+
return *this;
35+
}
36+
37+
voidswap(client_options &other)noexcept {
38+
std::swap(follow_redirects_, other.follow_redirects_);
39+
std::swap(cache_resolved_, other.cache_resolved_);
40+
std::swap(use_proxy_, other.use_proxy_);
41+
std::swap(timeout_, other.timeout_);
42+
std::swap(openssl_certificate_paths_, other.openssl_certificate_paths_);
43+
std::swap(openssl_verify_paths_, other.openssl_verify_paths_);
44+
}
45+
46+
client_options &follow_redirects(bool follow_redirects)noexcept {
47+
follow_redirects_ = follow_redirects;
48+
return *this;
49+
}
50+
51+
boolfollow_redirects()constnoexcept {
52+
return follow_redirects_;
53+
}
54+
55+
client_options &cache_resolved(bool cache_resolved)noexcept {
56+
cache_resolved_ = cache_resolved;
57+
return *this;
58+
}
59+
60+
boolcache_resolved()constnoexcept {
61+
return cache_resolved_;
62+
}
63+
64+
client_options &use_proxy(bool use_proxy)noexcept {
65+
use_proxy_ = use_proxy;
66+
return *this;
67+
}
68+
69+
booluse_proxy()constnoexcept {
70+
return use_proxy_;
71+
}
72+
73+
client_options &timeout(std::chrono::milliseconds timeout)noexcept {
74+
timeout_ = timeout;
75+
return *this;
76+
}
77+
78+
std::chrono::millisecondstimeout()constnoexcept {
79+
return timeout_;
80+
}
81+
82+
client_options &openssl_certificate_path(std::string path) {
83+
openssl_certificate_paths_.emplace_back(std::move(path));
84+
return *this;
85+
}
86+
87+
std::vector<std::string>openssl_certificate_paths()const {
88+
return openssl_certificate_paths_;
89+
}
90+
91+
client_options &openssl_verify_path(std::string path) {
92+
openssl_verify_paths_.emplace_back(std::move(path));
93+
return *this;
94+
}
95+
96+
std::vector<std::string>openssl_verify_paths()const {
97+
return openssl_verify_paths_;
98+
}
99+
100+
private:
101+
102+
bool follow_redirects_;
103+
bool cache_resolved_;
104+
bool use_proxy_;
105+
std::chrono::milliseconds timeout_;
106+
std::vector<std::string> openssl_certificate_paths_;
107+
std::vector<std::string> openssl_verify_paths_;
108+
109+
};
110+
}// namespace v2
111+
}// namespace http
112112
}// namespace network
113113

114114
#endif// __NETWORK_HTTP_V2_CLIENT_OPTIONS_INC__

‎http/src/network/http/v2/client/connection.hpp‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,38 @@
1212
#include<boost/utility/string_ref.hpp>
1313

1414
namespacenetwork {
15-
namespacehttp {
16-
namespacev2 {
15+
namespacehttp {
16+
namespacev2 {
1717

18-
classresponse;
19-
classrequest;
20-
classrequest_options;
18+
classresponse;
19+
classrequest;
20+
classrequest_options;
2121

22-
classconnection {
22+
classconnection {
2323

24-
public:
24+
public:
2525

26-
typedef std::function<void (boost::string_ref, boost::system::error_code)> callback_type;
26+
typedef std::function<void (boost::string_ref, boost::system::error_code)> callback_type;
2727

28-
connection() =default;
28+
connection() =default;
2929

30-
connection(const connection &) =delete;
30+
connection(const connection &) =delete;
3131

32-
connection &operator = (const connection &) =delete;
32+
connection &operator = (const connection &) =delete;
3333

34-
virtualconnection() = default;
34+
virtualconnection() = default;
3535

36-
virtual responsesend_request(std::string method,
37-
request req,
38-
bool get_body,
39-
callback_type callback,
40-
request_options) = 0;
36+
virtual responsesend_request(std::string method,
37+
request req,
38+
bool get_body,
39+
callback_type callback,
40+
request_options) = 0;
4141

42-
virtualvoidreset() = 0;
42+
virtualvoidreset() = 0;
4343

44-
};
45-
}// namespace v2
46-
}// namespace http
44+
};
45+
}// namespace v2
46+
}// namespace http
4747
}// namespace network
4848

4949

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp