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

Commit0610d08

Browse files
committed
Updated errors and the HTTP request.
1 parent88f6faf commit0610d08

File tree

12 files changed

+113
-62
lines changed

12 files changed

+113
-62
lines changed

‎http/src/http/v2/client/client_errors.cpp‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ namespace network {
1919

2020
std::stringclient_category_impl::message(int ev)const {
2121
switch (client_error(ev)) {
22-
case client_error::invalid_scheme:
23-
return"Requires HTTP or HTTPS scheme.";
22+
case client_error::invalid_url:
23+
return"Requires HTTP or HTTPS URL.";
24+
case client_error::resolver_error:
25+
return"Unable to resolve host";
26+
case client_error::connection_timeout:
27+
return"Connection timeout.";
28+
case client_error::https_not_supported:
29+
return"HTTPS is not supported.";
2430
default:
2531
break;
2632
}
@@ -36,30 +42,30 @@ namespace network {
3642
returnstd::error_code(static_cast<int>(e),client_category());
3743
}
3844

39-
invalid_scheme::invalid_scheme(const std::string &scheme)
40-
: std::system_error(make_error_code(client_error::invalid_scheme),"Invalid scheme:" + scheme) {
45+
invalid_url::invalid_url()
46+
: std::system_error(make_error_code(client_error::invalid_url)) {
4147

4248
}
4349

44-
invalid_scheme::~invalid_scheme()noexcept {
50+
invalid_url::~invalid_url()noexcept {
4551

4652
}
4753

48-
resolver_error::resolver_error(const std::string &msg)
49-
: std::system_error(make_error_code(client_error::resolver_error), msg) {
54+
resolver_error::resolver_error()
55+
: std::system_error(make_error_code(client_error::resolver_error)) {
5056

5157
}
5258

5359
resolver_error::~resolver_error() {
5460

5561
}
5662

57-
connection_timeout::connection_timeout()
58-
: std::system_error(make_error_code(client_error::connection_timeout)) {
63+
connection_error::connection_error(client_error error)
64+
: std::system_error(make_error_code(error)) {
5965

6066
}
6167

62-
connection_timeout::~connection_timeout() {
68+
connection_error::~connection_error() {
6369

6470
}
6571

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ namespace network {
1313
namespacehttp {
1414
namespacev2 {
1515
enumclassclient_error {
16-
//scheme
17-
invalid_scheme,
16+
//url
17+
invalid_url,
1818

1919
// resolution
2020
resolver_error,
2121

2222
// connection
2323
connection_timeout,
24+
https_not_supported,
2425
};
2526

2627
classclient_category_impl :publicstd::error_category {
@@ -41,13 +42,13 @@ namespace network {
4142

4243
std::error_codemake_error_code(client_error e);
4344

44-
classinvalid_scheme :publicstd::system_error {
45+
classinvalid_url :publicstd::system_error {
4546

4647
public:
4748

48-
explicitinvalid_scheme(const std::string &scheme);
49+
explicitinvalid_url();
4950

50-
virtual~invalid_scheme()noexcept;
51+
virtual~invalid_url()noexcept;
5152

5253
};
5354

@@ -56,21 +57,22 @@ namespace network {
5657

5758
public:
5859

59-
explicitresolver_error(const std::string &msg);
60+
explicitresolver_error();
6061

6162
virtual~resolver_error()noexcept;
6263

6364
};
6465

65-
classconnection_timeout :publicstd::system_error {
66+
classconnection_error :publicstd::system_error {
6667

6768
public:
6869

69-
connection_timeout();
70+
explicitconnection_error(client_error error);
7071

71-
virtual~connection_timeout()noexcept;
72+
virtual~connection_error()noexcept;
7273

7374
};
75+
7476
}// namespace v2
7577
}// namespace http
7678
}// namespace network

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ namespace network {
4242

4343
}
4444

45-
4645
/**
4746
* \brief Resolves a host asynchronously.
4847
*/

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ namespace network {
3939
virtualvoidconnect(boost::asio::ip::tcp::endpoint &endpoint,
4040
const std::string &host,
4141
std::function<void (const boost::system::error_code &)> handler) {
42-
context_.reset(
43-
newboost::asio::ssl::context(boost::asio::ssl::context::sslv23));
42+
context_.reset(newboost::asio::ssl::context(boost::asio::ssl::context::sslv23));
4443
std::vector<std::string>const& certificate_paths =
4544
options_.openssl_certificate_paths();
4645
std::vector<std::string>const& verifier_paths =
4746
options_.openssl_verify_paths();
48-
bool use_default_verification = certificate_paths.empty() &&
49-
verifier_paths.empty();
47+
bool use_default_verification = certificate_paths.empty() && verifier_paths.empty();
5048
if (!use_default_verification) {
5149
for (auto path : certificate_paths) {
5250
context_->load_verify_file(path);
@@ -56,7 +54,8 @@ namespace network {
5654
}
5755
context_->set_verify_mode(boost::asio::ssl::context::verify_peer);
5856
context_->set_verify_callback(boost::asio::ssl::rfc2818_verification(host));
59-
}else {
57+
}
58+
else {
6059
context_->set_default_verify_paths();
6160
context_->set_verify_mode(boost::asio::ssl::context::verify_none);
6261
}

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

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
#include<string>
1111
#include<vector>
1212
#include<utility>
13-
#include<network/http/v2/constants.hpp>
14-
#include<network/http/v2/message_base.hpp>
15-
#include<network/http/v2/client/client_errors.hpp>
13+
#include"network/http/v2/constants.hpp"
14+
#include"network/http/v2/method.hpp"
15+
#include"network/http/v2/client/client_errors.hpp"
16+
#include"network/uri.hpp"
1617
#include<boost/range/iterator_range.hpp>
1718
#include<boost/range/algorithm/equal.hpp>
1819
#include<boost/range/as_literal.hpp>
19-
#include<network/uri.hpp>
2020

2121
namespacenetwork {
2222
namespacehttp {
@@ -30,8 +30,8 @@ namespace network {
3030

3131
public:
3232

33-
typedefmessage_base::string_type string_type;
34-
typedefmessage_base::size_type size_type;
33+
typedefstd::string string_type;
34+
typedefstd::size_t size_type;
3535

3636
/**
3737
* \brief Destructor.
@@ -82,11 +82,11 @@ namespace network {
8282
if (auto scheme = destination.scheme()) {
8383
if ((!boost::equal(*scheme,boost::as_literal("http"))) &&
8484
(!boost::equal(*scheme,boost::as_literal("https")))) {
85-
throwinvalid_scheme(std::string(std::begin(*scheme),std::end(*scheme)));
85+
throwinvalid_url();
8686
}
8787
}
8888
else {
89-
throwinvalid_scheme("<none>");
89+
throwinvalid_url();
9090
}
9191
}
9292

@@ -151,11 +151,11 @@ namespace network {
151151
headers_.clear();
152152
}
153153

154-
voidset_method(string_type method) {
155-
method_ =std::move(method);
154+
voidset_method(network::http::v2::method method) {
155+
method_ = method;
156156
}
157157

158-
string_typemethod()const {
158+
network::http::v2::methodmethod()const {
159159
return method_;
160160
}
161161

@@ -170,21 +170,18 @@ namespace network {
170170
private:
171171

172172
uri destination_;
173-
string_type method_, version_;
173+
network::http::v2::method method_;
174+
string_type version_;
174175
headers_type headers_;
175176
std::shared_ptr<byte_source> byte_source_;
176177

177178
friend std::ostream &operator << (std::ostream &os,const request &req) {
178-
request::string_type path{std::begin(*req.destination_.path()),std::end(*req.destination_.path())};
179-
request::string_type host;
180-
host.append(request::string_type{std::begin(*req.destination_.scheme()),
181-
std::end(*req.destination_.scheme())});
182-
host.append("://");
183-
host.append(request::string_type{std::begin(*req.destination_.authority()),
184-
std::end(*req.destination_.authority())});
185-
186-
os << req.method_ <<"" << path <<" HTTP/" << req.version_ <<"\r\n";
187-
os <<"Host:" << host <<"\r\n";
179+
os << req.method_ <<"" << *req.destination_.path() <<" HTTP/" << req.version_ <<"\r\n";
180+
os <<"Host:";
181+
os << *req.destination_.scheme();
182+
os <<"://";
183+
os << *req.destination_.authority();
184+
os <<"\r\n";
188185
for (auto header : req.headers_) {
189186
os << header.first <<":" << header.second <<"\r\n";
190187
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
#ifndef __NETWORK_HTTP_V2_METHOD_INC__
7+
#define__NETWORK_HTTP_V2_METHOD_INC__
8+
9+
#include<string>
10+
#include<ostream>
11+
12+
namespacenetwork {
13+
namespacehttp {
14+
namespacev2 {
15+
enumclassmethod { GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, CONNECT, MERGE, PATCH, };
16+
17+
inline
18+
std::ostream &operator << (std::ostream &os, method m) {
19+
switch (m) {
20+
case method::GET:
21+
return os <<"GET";
22+
case method::POST:
23+
return os <<"POST";
24+
case method::PUT:
25+
return os <<"PUT";
26+
case method::DELETE:
27+
return os <<"DELETE";
28+
case method::HEAD:
29+
return os <<"HEAD";
30+
case method::OPTIONS:
31+
return os <<"OPTIONS";
32+
case method::TRACE:
33+
return os <<"TRACE";
34+
case method::CONNECT:
35+
return os <<"CONNECT";
36+
case method::MERGE:
37+
return os <<"MERGE";
38+
case method::PATCH:
39+
return os <<"PATCH";
40+
}
41+
return os;
42+
}
43+
}// namespace v2
44+
}// namespace http
45+
}// namespace network
46+
47+
48+
#endif// __NETWORK_HTTP_V2_METHOD_INC__

‎http/test/v2/client/byte_source_test.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66
#include<gtest/gtest.h>
7-
#include<network/http/v2/client/request.hpp>
7+
#include"network/http/v2/client/request.hpp"
88

99

‎http/test/v2/client/client_options_test.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66
#include<gtest/gtest.h>
7-
#include<network/http/v2/client/client_options.hpp>
7+
#include"network/http/v2/client/client_options.hpp"
88

99
TEST(client_options_test, default_options_follow_redirects) {
1010
network::http::v2::client_options opts;

‎http/test/v2/client/client_test.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66
#include<gtest/gtest.h>
7-
#include<network/http/v2/client.hpp>
7+
#include"network/http/v2/client.hpp"
88

99
namespacehttp= network::http::v2;
1010

‎http/test/v2/client/request_options_test.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66
#include<gtest/gtest.h>
7-
#include<network/http/v2/client/request_options.hpp>
7+
#include"network/http/v2/client/request_options.hpp"
88

99
TEST(request_options_test, default_options_resolve_timeout) {
1010
network::http::v2::request_options opts;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp