@@ -19,31 +19,6 @@ namespace network {
19
19
namespace v2 {
20
20
using boost::asio::ip::tcp;
21
21
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
-
47
22
struct client ::impl {
48
23
49
24
explicit impl (client_options options);
@@ -105,7 +80,6 @@ namespace network {
105
80
// //response_promise_.set_value(v2::response());
106
81
// //write_request(ec);
107
82
// });
108
- response_promise_.set_value (response ());
109
83
}
110
84
111
85
void client::impl::write_request (const boost::system::error_code &ec) {
@@ -167,49 +141,51 @@ namespace network {
167
141
// set error
168
142
}
169
143
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
+ }
172
154
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(
199
172
// std::make_exception_ptr(
200
173
// connection_error(client_error::host_not_found)));
201
- // return;
202
- // }
174
+ // return;
175
+ // }
203
176
//
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
+ // }
209
183
//
210
- // connect(ec, endpoint_iterator);
211
- // });
184
+ // connect(ec, endpoint_iterator);
185
+ // });
212
186
187
+ response_promise_.set_exception (std::make_exception_ptr (
188
+ connection_error (client_error::host_not_found)));
213
189
return res;
214
190
}
215
191
0 commit comments