Skip to content

Commit 5b0dc2a

Browse files
committed
Merge pull request cpp-netlib#41 from deanberris/0.9-devel
0.9.1 Final Touches
2 parents 2047a63 + 233b0f1 commit 5b0dc2a

35 files changed

+840
-335
lines changed

README.rst

+4-9
Original file line numberDiff line numberDiff line change
@@ -167,26 +167,21 @@ repository. It is recommended that forks be made against the upstream repostory
167167
and pull requests be submitted against the upstream repository so that patches
168168
and other implementations can be curated by the original maintainer.
169169

170-
Contact and Commercial Support
171-
------------------------------
170+
Contact and Support
171+
-------------------
172172

173173
In case you have any questions or would like to make feature requests, you can
174174
contact the development team through the `developers mailing list`_
175-
or by filing issues at http://github.com/mikhailberis/cpp-netlib/issues.
175+
or by filing issues at http://github.com/cpp-netlib/cpp-netlib/issues.
176176

177177
.. _`developers mailing list`:
178178
https://lists.sourceforge.net/lists/listinfo/cpp-netlib-devel
179179

180180
You can reach the maintainers of the project through::
181181

182-
Dean Michael Berris
183-
182+
Dean Michael Berris ([email protected])
184183

185184
Glyn Matthews
186185

187186
Mike Dickey
188187

189-
At this time, paid commercial support is available for cpp-netlib being offered
190-
by the maintainers. In case you have any questions, please feel free to contact
191-
any one of the maintainers above or anybody on the developers mailing list.
192-

boost/network/protocol/http/client.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace boost { namespace network { namespace http {
3434
: basic_client_facade<Tag, version_major, version_minor>
3535
{
3636
private:
37-
typedef basic_client_facade<Tag, version_major, version_minor>
37+
typedef basic_client_facade<Tag, version_major, version_minor>
3838
base_facade_type;
3939
public:
4040
typedef basic_request<Tag> request;
@@ -65,8 +65,8 @@ namespace boost { namespace network { namespace http {
6565

6666
BOOST_PARAMETER_CONSTRUCTOR(
6767
basic_client, (base_facade_type), tag,
68-
(optional
69-
(in_out(io_service), (boost::asio::io_service))
68+
(optional
69+
(in_out(io_service), (boost::asio::io_service&))
7070
(follow_redirects, (bool))
7171
(cache_resolved, (bool))
7272
(openssl_certificate, (string_type))

boost/network/protocol/http/client/async_impl.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace boost { namespace network { namespace http {
1818

1919
namespace impl {
2020
template <class Tag, unsigned version_major, unsigned version_minor>
21-
struct async_client :
21+
struct async_client :
2222
connection_policy<Tag,version_major,version_minor>::type
2323
{
2424
typedef
@@ -31,7 +31,7 @@ namespace boost { namespace network { namespace http {
3131
typename string<Tag>::type
3232
string_type;
3333

34-
typedef
34+
typedef
3535
function<void(boost::iterator_range<char const *> const &, system::error_code const &)>
3636
body_callback_function_type;
3737

@@ -75,11 +75,11 @@ namespace boost { namespace network { namespace http {
7575
}
7676

7777
basic_response<Tag> const request_skeleton(
78-
basic_request<Tag> const & request_,
79-
string_type const & method,
78+
basic_request<Tag> const & request_,
79+
string_type const & method,
8080
bool get_body,
8181
body_callback_function_type callback
82-
)
82+
)
8383
{
8484
typename connection_base::connection_ptr connection_;
8585
connection_ = connection_base::get_connection(resolver_, request_, certificate_filename_, verify_path_);

boost/network/protocol/http/client/connection/async_normal.hpp

+45-49
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ namespace boost { namespace network { namespace http { namespace impl {
5151

5252
http_async_connection(
5353
resolver_type & resolver,
54-
resolve_function resolve,
55-
bool follow_redirect
56-
) :
54+
resolve_function resolve,
55+
bool follow_redirect
56+
) :
5757
follow_redirect_(follow_redirect),
5858
resolver_(resolver),
59-
resolve_(resolve),
59+
resolve_(resolve),
6060
request_strand_(resolver.get_io_service())
6161
{}
6262

@@ -68,7 +68,7 @@ namespace boost { namespace network { namespace http { namespace impl {
6868
std::ostreambuf_iterator<typename char_<Tag>::type>(&command_streambuf));
6969
this->method = method;
7070
boost::uint16_t port_ = port(request);
71-
resolve_(resolver_, host(request),
71+
resolve_(resolver_, host(request),
7272
port_,
7373
request_strand_.wrap(
7474
boost::bind(
@@ -83,6 +83,17 @@ namespace boost { namespace network { namespace http { namespace impl {
8383

8484
http_async_connection(http_async_connection const &); // = delete
8585

86+
void set_errors(boost::system::error_code const & ec) {
87+
boost::system::system_error error(ec);
88+
this->version_promise.set_exception(boost::copy_exception(error));
89+
this->status_promise.set_exception(boost::copy_exception(error));
90+
this->status_message_promise.set_exception(boost::copy_exception(error));
91+
this->headers_promise.set_exception(boost::copy_exception(error));
92+
this->source_promise.set_exception(boost::copy_exception(error));
93+
this->destination_promise.set_exception(boost::copy_exception(error));
94+
this->body_promise.set_exception(boost::copy_exception(error));
95+
}
96+
8697
void handle_resolved(boost::uint16_t port, bool get_body, body_callback_function_type callback, boost::system::error_code const & ec, resolver_iterator_pair endpoint_range) {
8798
resolver_iterator iter = boost::begin(endpoint_range);
8899
if (!ec && !boost::empty(endpoint_range)) {
@@ -103,14 +114,7 @@ namespace boost { namespace network { namespace http { namespace impl {
103114
boost::asio::placeholders::error
104115
)));
105116
} else {
106-
boost::system::system_error error(ec ? ec : boost::asio::error::host_not_found);
107-
this->version_promise.set_exception(boost::copy_exception(error));
108-
this->status_promise.set_exception(boost::copy_exception(error));
109-
this->status_message_promise.set_exception(boost::copy_exception(error));
110-
this->headers_promise.set_exception(boost::copy_exception(error));
111-
this->source_promise.set_exception(boost::copy_exception(error));
112-
this->destination_promise.set_exception(boost::copy_exception(error));
113-
this->body_promise.set_exception(boost::copy_exception(error));
117+
set_errors(ec ? ec : boost::asio::error::host_not_found);
114118
}
115119
}
116120

@@ -123,7 +127,7 @@ namespace boost { namespace network { namespace http { namespace impl {
123127
boost::bind(
124128
&http_async_connection<Tag,version_major,version_minor>::handle_sent_request,
125129
http_async_connection<Tag,version_major,version_minor>::shared_from_this(),
126-
get_body, callback,
130+
get_body, callback,
127131
boost::asio::placeholders::error,
128132
boost::asio::placeholders::bytes_transferred
129133
)));
@@ -146,16 +150,7 @@ namespace boost { namespace network { namespace http { namespace impl {
146150
boost::asio::placeholders::error
147151
)));
148152
} else {
149-
boost::system::system_error error(
150-
ec ? ec : boost::asio::error::host_not_found
151-
);
152-
this->version_promise.set_exception(boost::copy_exception(error));
153-
this->status_promise.set_exception(boost::copy_exception(error));
154-
this->status_message_promise.set_exception(boost::copy_exception(error));
155-
this->headers_promise.set_exception(boost::copy_exception(error));
156-
this->source_promise.set_exception(boost::copy_exception(error));
157-
this->destination_promise.set_exception(boost::copy_exception(error));
158-
this->body_promise.set_exception(boost::copy_exception(error));
153+
set_errors(ec ? ec : boost::asio::error::host_not_found);
159154
}
160155
}
161156
}
@@ -173,36 +168,34 @@ namespace boost { namespace network { namespace http { namespace impl {
173168
&http_async_connection<Tag,version_major,version_minor>::handle_received_data,
174169
http_async_connection<Tag,version_major,version_minor>::shared_from_this(),
175170
version, get_body, callback,
176-
boost::asio::placeholders::error,
171+
boost::asio::placeholders::error,
177172
boost::asio::placeholders::bytes_transferred)));
178173
} else {
179-
boost::system::system_error error(ec);
180-
this->version_promise.set_exception(boost::copy_exception(error));
181-
this->status_promise.set_exception(boost::copy_exception(error));
182-
this->status_message_promise.set_exception(boost::copy_exception(error));
183-
this->headers_promise.set_exception(boost::copy_exception(error));
184-
this->source_promise.set_exception(boost::copy_exception(error));
185-
this->destination_promise.set_exception(boost::copy_exception(error));
186-
this->body_promise.set_exception(boost::copy_exception(error));
174+
set_errors(ec);
187175
}
188176
}
189177

190178
void handle_received_data(state_t state, bool get_body, body_callback_function_type callback, boost::system::error_code const & ec, std::size_t bytes_transferred) {
191179
if (!ec || ec == boost::asio::error::eof) {
180+
// Sanity check
181+
if (ec == boost::asio::error::eof && state < headers) {
182+
return;
183+
}
192184
logic::tribool parsed_ok;
193185
size_t remainder;
194186
switch(state) {
195187
case version:
196-
parsed_ok =
188+
parsed_ok =
197189
this->parse_version(*socket_,
198190
request_strand_.wrap(
199191
boost::bind(
200192
&http_async_connection<Tag,version_major,version_minor>::handle_received_data,
201193
http_async_connection<Tag,version_major,version_minor>::shared_from_this(),
202-
status, get_body, callback,
194+
version, get_body, callback,
203195
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred
204196
)
205-
)
197+
),
198+
bytes_transferred
206199
);
207200
if (parsed_ok != true) return;
208201
case status:
@@ -212,10 +205,11 @@ namespace boost { namespace network { namespace http { namespace impl {
212205
boost::bind(
213206
&http_async_connection<Tag,version_major,version_minor>::handle_received_data,
214207
http_async_connection<Tag,version_major,version_minor>::shared_from_this(),
215-
status_message, get_body, callback,
208+
status, get_body, callback,
216209
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred
217210
)
218-
)
211+
),
212+
bytes_transferred
219213
);
220214
if (parsed_ok != true) return;
221215
case status_message:
@@ -225,10 +219,11 @@ namespace boost { namespace network { namespace http { namespace impl {
225219
boost::bind(
226220
&http_async_connection<Tag,version_major,version_minor>::handle_received_data,
227221
http_async_connection<Tag,version_major,version_minor>::shared_from_this(),
228-
headers, get_body, callback,
222+
status_message, get_body, callback,
229223
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred
230224
)
231-
)
225+
),
226+
bytes_transferred
232227
);
233228
if (parsed_ok != true) return;
234229
case headers:
@@ -241,7 +236,8 @@ namespace boost { namespace network { namespace http { namespace impl {
241236
headers, get_body, callback,
242237
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred
243238
)
244-
)
239+
),
240+
bytes_transferred
245241
);
246242
if (parsed_ok != true) return;
247243
if (!get_body) {
@@ -253,8 +249,9 @@ namespace boost { namespace network { namespace http { namespace impl {
253249
std::advance(begin, remainder);
254250
typename protocol_base::buffer_type::const_iterator end = begin;
255251
std::advance(end, this->part.size() - remainder);
252+
this->body_promise.set_value("");
256253
callback(make_iterator_range(begin, end), ec);
257-
socket_->async_read_some(
254+
socket_->async_read_some(
258255
boost::asio::mutable_buffers_1(this->part.c_array(), this->part.size()),
259256
request_strand_.wrap(
260257
boost::bind(
@@ -264,7 +261,6 @@ namespace boost { namespace network { namespace http { namespace impl {
264261
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)
265262
)
266263
);
267-
this->body_promise.set_value("");
268264
} else {
269265
this->parse_body(
270266
*socket_,
@@ -278,7 +274,7 @@ namespace boost { namespace network { namespace http { namespace impl {
278274
),
279275
remainder);
280276
}
281-
break;
277+
return;
282278
case body:
283279
if (ec == boost::asio::error::eof) {
284280
if (callback) {
@@ -304,7 +300,7 @@ namespace boost { namespace network { namespace http { namespace impl {
304300
typename protocol_base::buffer_type::const_iterator begin = this->part.begin(), end = begin;
305301
std::advance(end, bytes_transferred);
306302
callback(make_iterator_range(begin, end), ec);
307-
socket_->async_read_some(
303+
socket_->async_read_some(
308304
boost::asio::mutable_buffers_1(this->part.c_array(), this->part.size()),
309305
request_strand_.wrap(
310306
boost::bind(
@@ -328,7 +324,7 @@ namespace boost { namespace network { namespace http { namespace impl {
328324
bytes_transferred);
329325
}
330326
}
331-
break;
327+
return;
332328
default:
333329
BOOST_ASSERT(false && "Bug, report this to the developers!");
334330
}
@@ -337,13 +333,13 @@ namespace boost { namespace network { namespace http { namespace impl {
337333
this->source_promise.set_exception(boost::copy_exception(error));
338334
this->destination_promise.set_exception(boost::copy_exception(error));
339335
switch (state) {
340-
case version:
336+
case version:
341337
this->version_promise.set_exception(boost::copy_exception(error));
342-
case status:
338+
case status:
343339
this->status_promise.set_exception(boost::copy_exception(error));
344340
case status_message:
345341
this->status_message_promise.set_exception(boost::copy_exception(error));
346-
case headers:
342+
case headers:
347343
this->headers_promise.set_exception(boost::copy_exception(error));
348344
case body:
349345
this->body_promise.set_exception(boost::copy_exception(error));

0 commit comments

Comments
 (0)