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

Commit44b9185

Browse files
committed
Test fails with an exception instead of a crash - progress of a kind...
1 parent58d5f94 commit44b9185

File tree

1 file changed

+39
-63
lines changed

1 file changed

+39
-63
lines changed

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

Lines changed: 39 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,6 @@ namespace network {
1919
namespacev2 {
2020
using boost::asio::ip::tcp;
2121

22-
//struct request_helper {
23-
//
24-
// request_helper() {
25-
//
26-
// }
27-
//
28-
// void connect(client::string_type host,
29-
// const boost::system::error_code &ec,
30-
// tcp::resolver::iterator endpoint_iterator);
31-
//
32-
// void write_request(const boost::system::error_code &ec);
33-
//
34-
// void read_response_status(const boost::system::error_code &ec,
35-
// std::size_t bytes_written);
36-
//
37-
// void read_response_headers(const boost::system::error_code &ec,
38-
// std::size_t bytes_read);
39-
//
40-
// client::string_type host_;
41-
// boost::asio::streambuf request_;
42-
// std::promise<response> response_promise_;
43-
// boost::asio::streambuf response_;
44-
//
45-
//};
46-
4722
structclient::impl {
4823

4924
explicitimpl(client_options options);
@@ -105,7 +80,6 @@ namespace network {
10580
// //response_promise_.set_value(v2::response());
10681
// //write_request(ec);
10782
// });
108-
response_promise_.set_value(response());
10983
}
11084

11185
voidclient::impl::write_request(const boost::system::error_code &ec) {
@@ -167,49 +141,51 @@ namespace network {
167141
// set error
168142
}
169143

170-
response_promise_.set_value(response());
171-
144+
// HTTP 1.1
145+
auto it =std::find_if(std::begin(req.headers()),std::end(req.headers()),
146+
[] (const std::pair<uri::string_type, uri::string_type> &header) {
147+
return (boost::iequals(header.first,"host"));
148+
});
149+
if (it ==std::end(req.headers())) {
150+
// set error
151+
response_promise_.set_value(response());
152+
return res;
153+
}
172154

173-
//auto it = std::find_if(std::begin(req.headers()), std::end(req.headers()),
174-
// [] (const std::pair<uri::string_type, uri::string_type> &header) {
175-
// return (boost::iequals(header.first, "host"));
176-
// });
177-
//if (it == std::end(req.headers())) {
178-
// // set error
179-
// response_promise_.set_value(response());
180-
// return res;
181-
//}
182-
//
183-
//uri_builder builder;
184-
//builder
185-
// .authority(it->second)
186-
// ;
187-
//
188-
//auto auth = builder.uri();
189-
//auto host = auth.host()?
190-
// uri::string_type(std::begin(*auth.host()), std::end(*auth.host())) : uri::string_type();
191-
//auto port = auth.port<std::uint16_t>()? *auth.port<std::uint16_t>() : 80;
192-
//
193-
//resolver_.async_resolve(host, port,
194-
// [=](const boost::system::error_code &ec,
195-
// tcp::resolver::iterator endpoint_iterator) {
196-
// if (ec) {
197-
// if (endpoint_iterator == tcp::resolver::iterator()) {
198-
// response_promise_.set_exception(
155+
uri_builder builder;
156+
builder
157+
.authority(it->second)
158+
;
159+
160+
auto auth = builder.uri();
161+
auto host = auth.host()?
162+
uri::string_type(std::begin(*auth.host()),std::end(*auth.host())) :uri::string_type();
163+
auto port = auth.port<std::uint16_t>()? *auth.port<std::uint16_t>() :80;
164+
165+
//resolver_->async_resolve(host, port,
166+
// [=](const boost::system::error_code &ec,
167+
// tcp::resolver::iterator endpoint_iterator) {
168+
// std::cout << "!!!" << std::endl;
169+
// if (ec) {
170+
// if (endpoint_iterator == tcp::resolver::iterator()) {
171+
// response_promise_.set_exception(
199172
// std::make_exception_ptr(
200173
// connection_error(client_error::host_not_found)));
201-
// return;
202-
// }
174+
//return;
175+
//}
203176
//
204-
// response_promise_.set_exception(
205-
// std::make_exception_ptr(
206-
// boost::system::system_error(ec)));
207-
// return;
208-
// }
177+
// std::cout << "!!!" << std::endl;
178+
// //response_promise_.set_exception(
179+
// // std::make_exception_ptr(
180+
// // boost::system::system_error(ec)));
181+
// return;
182+
// }
209183
//
210-
// connect(ec, endpoint_iterator);
211-
// });
184+
//connect(ec, endpoint_iterator);
185+
//});
212186

187+
response_promise_.set_exception(std::make_exception_ptr(
188+
connection_error(client_error::host_not_found)));
213189
return res;
214190
}
215191

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp