Skip to content

Commit a5feaa6

Browse files
committed
Merge remote-tracking branch 'deanberris/0.9-devel' into 0.9-devel
2 parents c834e47 + f3f2f79 commit a5feaa6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+383
-121
lines changed

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ if (OPENSSL_FOUND)
2121
include_directories(${OPENSSL_INCLUDE_DIR})
2222
endif()
2323

24+
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
25+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
26+
endif()
27+
2428
if (Boost_FOUND)
2529
if (MSVC)
2630
add_definitions(-D_SCL_SECURE_NO_WARNINGS)

boost/network/protocol/http/algorithms/linearize.hpp

+76-35
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
88

9+
#include <algorithm>
10+
#include <bitset>
911
#include <boost/network/traits/string.hpp>
1012
#include <boost/network/protocol/http/message/header/name.hpp>
1113
#include <boost/network/protocol/http/message/header/value.hpp>
@@ -15,6 +17,7 @@
1517
#include <boost/concept/requires.hpp>
1618
#include <boost/optional.hpp>
1719
#include <boost/range/algorithm/copy.hpp>
20+
#include <boost/algorithm/string/compare.hpp>
1821

1922
namespace boost { namespace network { namespace http {
2023

@@ -92,48 +95,86 @@ namespace boost { namespace network { namespace http {
9295
*oi = consts::dot_char();
9396
boost::copy(version_minor_str, oi);
9497
boost::copy(crlf, oi);
95-
boost::copy(host, oi);
96-
*oi = consts::colon_char();
97-
*oi = consts::space_char();
98-
boost::copy(request.host(), oi);
99-
boost::optional<boost::uint16_t> port_ = port(request);
100-
if (port_) {
101-
string_type port_str = boost::lexical_cast<string_type>(*port_);
102-
*oi = consts::colon_char();
103-
boost::copy(port_str, oi);
104-
}
105-
boost::copy(crlf, oi);
106-
boost::copy(accept, oi);
107-
*oi = consts::colon_char();
108-
*oi = consts::space_char();
109-
boost::copy(accept_mime, oi);
110-
boost::copy(crlf, oi);
111-
if (version_major == 1u && version_minor == 1u) {
112-
boost::copy(accept_encoding, oi);
113-
*oi = consts::colon_char();
114-
*oi = consts::space_char();
115-
boost::copy(default_accept_encoding, oi);
116-
boost::copy(crlf, oi);
117-
}
98+
99+
// We need to determine whether we've seen any of the following headers
100+
// before setting the defaults. We use a bitset to keep track of the
101+
// defaulted headers.
102+
enum { ACCEPT, ACCEPT_ENCODING, HOST, MAX };
103+
std::bitset<MAX> found_headers;
104+
static char const* defaulted_headers[][2] = {
105+
{consts::accept(),
106+
consts::accept() + std::strlen(consts::accept())},
107+
{consts::accept_encoding(),
108+
consts::accept_encoding() + std::strlen(consts::accept_encoding())},
109+
{consts::host(), consts::host() + std::strlen(consts::host())}
110+
};
111+
118112
typedef typename headers_range<Request>::type headers_range;
119113
typedef typename range_value<headers_range>::type headers_value;
120-
BOOST_FOREACH(const headers_value &header, headers(request))
121-
{
122-
string_type header_name = name(header),
123-
header_value = value(header);
124-
boost::copy(header_name, oi);
125-
*oi = consts::colon_char();
126-
*oi = consts::space_char();
127-
boost::copy(header_value, oi);
128-
boost::copy(crlf, oi);
114+
BOOST_FOREACH(const headers_value & header, headers(request)) {
115+
string_type header_name = name(header), header_value = value(header);
116+
// Here we check that we have not seen an override to the defaulted
117+
// headers.
118+
for (int header_index = 0; header_index < MAX; ++header_index)
119+
if (std::distance(header_name.begin(), header_name.end()) ==
120+
std::distance(defaulted_headers[header_index][0],
121+
defaulted_headers[header_index][1]) &&
122+
std::equal(header_name.begin(),
123+
header_name.end(),
124+
defaulted_headers[header_index][0],
125+
algorithm::is_iequal()))
126+
found_headers.set(header_index, true);
127+
128+
// We ignore empty headers.
129+
if (header_value.empty()) continue;
130+
boost::copy(header_name, oi);
131+
*oi = consts::colon_char();
132+
*oi = consts::space_char();
133+
boost::copy(header_value, oi);
134+
boost::copy(crlf, oi);
135+
136+
}
137+
138+
if (!found_headers[HOST]) {
139+
boost::copy(host, oi);
140+
*oi = consts::colon_char();
141+
*oi = consts::space_char();
142+
boost::copy(request.host(), oi);
143+
boost::optional<boost::uint16_t> port_ = port(request);
144+
if (port_) {
145+
string_type port_str = boost::lexical_cast<string_type>(*port_);
146+
*oi = consts::colon_char();
147+
boost::copy(port_str, oi);
148+
}
149+
boost::copy(crlf, oi);
150+
}
151+
152+
if (!found_headers[ACCEPT]) {
153+
boost::copy(accept, oi);
154+
*oi = consts::colon_char();
155+
*oi = consts::space_char();
156+
boost::copy(accept_mime, oi);
157+
boost::copy(crlf, oi);
158+
}
159+
160+
if (version_major == 1u &&
161+
version_minor == 1u &&
162+
!found_headers[ACCEPT_ENCODING]) {
163+
boost::copy(accept_encoding, oi);
164+
*oi = consts::colon_char();
165+
*oi = consts::space_char();
166+
boost::copy(default_accept_encoding, oi);
167+
boost::copy(crlf, oi);
129168
}
169+
130170
if (!connection_keepalive<Tag>::value) {
131-
boost::copy(connection, oi);
132-
*oi = consts::colon_char();
133-
*oi = consts::space_char();
171+
boost::copy(connection, oi);
172+
*oi = consts::colon_char();
173+
*oi = consts::space_char();
134174
boost::copy(close, oi);
135175
boost::copy(crlf, oi);
136176
}
177+
137178
boost::copy(crlf, oi);
138179
typename body_range<Request>::type body_data = body(request).range();
139180
return boost::copy(body_data, oi);

boost/network/protocol/http/server/async_server.hpp

+14-13
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,21 @@ namespace boost { namespace network { namespace http {
9090
scoped_mutex_lock stopping_lock(stopping_mutex_);
9191
if (stopping) return; // we dont want to add another handler instance, and we dont want to know about errors for a socket we dont need anymore
9292
}
93-
if (!ec) {
94-
socket_options_base::socket_options(new_connection->socket());
95-
new_connection->start();
96-
new_connection.reset(
97-
new connection(service_, handler, *thread_pool));
98-
acceptor.async_accept(
99-
new_connection->socket(),
100-
boost::bind(
101-
&async_server_base<Tag,Handler>::handle_accept,
102-
this,
103-
boost::asio::placeholders::error));
104-
} else {
105-
BOOST_NETWORK_MESSAGE("Error accepting connection, reason: " << ec);
93+
94+
if (ec) {
95+
BOOST_NETWORK_MESSAGE("Error accepting connection, reason: "
96+
<< ec);
10697
}
98+
99+
socket_options_base::socket_options(new_connection->socket());
100+
new_connection->start();
101+
new_connection.reset(
102+
new connection(service_, handler, *thread_pool));
103+
acceptor.async_accept(
104+
new_connection->socket(),
105+
boost::bind(&async_server_base<Tag, Handler>::handle_accept,
106+
this,
107+
boost::asio::placeholders::error));
107108
}
108109

109110
void start_listening() {

boost/network/protocol/http/server/sync_server.hpp

+16-13
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,18 @@ namespace boost { namespace network { namespace http {
6868
boost::mutex listening_mutex_;
6969
bool listening_;
7070

71-
void handle_accept(boost::system::error_code const & ec) {
72-
if (!ec) {
73-
socket_options_base::socket_options(new_connection->socket());
74-
new_connection->start();
75-
new_connection.reset(new sync_connection<Tag,Handler>(service_, handler_));
76-
acceptor_.async_accept(new_connection->socket(),
77-
boost::bind(&sync_server_base<Tag,Handler>::handle_accept,
78-
this, boost::asio::placeholders::error));
79-
}
71+
void handle_accept(boost::system::error_code const& ec) {
72+
if (ec) {
73+
}
74+
socket_options_base::socket_options(new_connection->socket());
75+
new_connection->start();
76+
new_connection.reset(
77+
new sync_connection<Tag, Handler>(service_, handler_));
78+
acceptor_.async_accept(
79+
new_connection->socket(),
80+
boost::bind(&sync_server_base<Tag, Handler>::handle_accept,
81+
this,
82+
boost::asio::placeholders::error));
8083
}
8184

8285
void start_listening() {
@@ -87,24 +90,24 @@ namespace boost { namespace network { namespace http {
8790
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query, error);
8891
if (error) {
8992
BOOST_NETWORK_MESSAGE("Error resolving address: " << address_ << ':' << port_);
90-
return;
93+
boost::throw_exception(std::runtime_error("Error resolving address."));
9194
}
9295
tcp::endpoint endpoint = *endpoint_iterator;
9396
acceptor_.open(endpoint.protocol(), error);
9497
if (error) {
9598
BOOST_NETWORK_MESSAGE("Error opening socket: " << address_ << ':' << port_ << " -- reason: '" << error << '\'');
96-
return;
99+
boost::throw_exception(std::runtime_error("Error opening socket."));
97100
}
98101
socket_options_base::acceptor_options(acceptor_);
99102
acceptor_.bind(endpoint, error);
100103
if (error) {
101104
BOOST_NETWORK_MESSAGE("Error binding to socket: " << address_ << ':' << port_ << " -- reason: '" << error << '\'');
102-
return;
105+
boost::throw_exception(std::runtime_error("Error binding to socket."));
103106
}
104107
acceptor_.listen(tcp::socket::max_connections, error);
105108
if (error) {
106109
BOOST_NETWORK_MESSAGE("Error listening on socket: " << address_ << ':' << port_ << " -- reason: '" << error << '\'');
107-
return;
110+
boost::throw_exception(std::runtime_error("Error listening on socket."));
108111
}
109112
new_connection.reset(new sync_connection<Tag,Handler>(service_, handler_));
110113
acceptor_.async_accept(new_connection->socket(),

boost/network/support/is_udp.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ namespace boost { namespace network {
2424

2525
} // namespace boost
2626

27-
#endif // BOOST_NETWORK_SUPPORT_IS_UDP_HPP_20100622
27+
#endif // BOOST_NETWORK_SUPPORT_IS_UDP_HPP_20100622
28+

boost/network/version.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#define BOOST_NETLIB_VERSION_MAJOR 0
1313
#define BOOST_NETLIB_VERSION_MINOR 10
14-
#define BOOST_NETLIB_VERSION_INCREMENT 0
14+
#define BOOST_NETLIB_VERSION_INCREMENT 1
1515

1616
#ifndef BOOST_NETLIB_VERSION
1717
# define BOOST_NETLIB_VERSION \
-274 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
-7 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

libs/network/doc/html/_sources/in_depth/http.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ overload of the ``basic_client``:
3333

3434

3535
The default typedef for the HTTP client that is provided uses the
36-
``http_default_8bit_udp_resolve`` tag, and implements HTTP 1.0. The exact
36+
``http_async_8bit_udp_resolve`` tag, and implements HTTP 1.1. The exact
3737
typedef is in the ``boost::network::http`` namespace as the following:
3838

3939
.. code-block:: c++
4040

4141
namespace boost { namespace network { namespace http {
4242

43-
typedef basic_client<tags::http_default_8bit_udp_resolve, 1, 0>
43+
typedef basic_client<tags::http_async_8bit_udp_resolve, 1, 1>
4444
client;
4545

4646
}}}

libs/network/doc/html/_sources/index.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
.. :Authors: Glyn Matthews <[email protected]>
55
.. Dean Michael Berris <[email protected]>
6-
.. :Date: Jun 26, 2013
7-
.. :Version: 0.10.0
6+
.. :Date: Jul 4, 2013
7+
.. :Version: 0.10.1
88
.. :Description: Complete user documentation, with examples, for the :mod:`cpp-netlib`.
99
.. :Copyright: Copyright Glyn Matthews, Dean Michael Berris 2008-2013.
1010
.. Copyrigh 2013 Google, Inc.

libs/network/doc/html/_sources/reference/http_client.txt

+20
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,26 @@ happens on a different thread.
105105
dedicated to that request. The client does not re-cycle connections and uses
106106
a one-request-one-connection model.
107107

108+
When an asynchronous client object is destroyed, it waits for all pending
109+
asynchronous operations to finish. Errors encountered during operations on
110+
retrieving data from the response objects cause exceptions to be thrown --
111+
therefore it is best that if a client object is constructed, it should outlive
112+
the response object or be outside the try-catch block handling the errors from
113+
operations on responses. In code, usage should look like the following:
114+
115+
.. code-block:: c++
116+
117+
http::client client;
118+
try {
119+
http::client::response response = client.get("http://www.example.com/");
120+
std::cout << body(response);
121+
} catch (std::exception& e) {
122+
// deal with exceptions here
123+
}
124+
125+
A common mistake is to declare the client inside the try block which invokes
126+
undefined behavior when errors arise from the handling of response objects.
127+
108128
Member Functions
109129
----------------
110130

libs/network/doc/html/_sources/reference/http_response.txt

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ HTTP Response objects. This section details the `Response Concept`_ requirements
77
the implemented and required Directives_, Modifiers_, and Wrappers_ that work
88
with the HTTP Response objects.
99

10+
.. note:: The HTTP server response object is a POD type, which doesn't support
11+
any of the following details. There are only a few fields available in the
12+
HTTP server response type, which can be seen in
13+
``boost/network/protocol/http/impl/response.ipp``.
14+
1015
Response Concept
1116
----------------
1217

libs/network/doc/html/_sources/whats_new.txt

+20
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@
77
:mod:`cpp-netlib` 0.10
88
----------------------
99

10+
v0.10.1
11+
~~~~~~~
12+
* Documentation updates (`#182`_, `#265`_, `#194`_, `#233`_, `#255`_)
13+
* Fix issue with async server inadvertently stopping from listening when
14+
accepting a connection fails. (`#172`_)
15+
* Allow overriding and ultimately removing defaulted headers from HTTP
16+
requests. (`#263`_)
17+
* Add `-Wall` to the base rule for GCC builds. (`#264`_)
18+
* Make the server implementation throw on startup errors. (`#166`_)
19+
20+
.. _`#182`: https://github.com/cpp-netlib/cpp-netlib/issues/182
21+
.. _`#265`: https://github.com/cpp-netlib/cpp-netlib/issues/265
22+
.. _`#194`: https://github.com/cpp-netlib/cpp-netlib/issues/194
23+
.. _`#172`: https://github.com/cpp-netlib/cpp-netlib/issues/172
24+
.. _`#263`: https://github.com/cpp-netlib/cpp-netlib/issues/263
25+
.. _`#233`: https://github.com/cpp-netlib/cpp-netlib/issues/233
26+
.. _`#264`: https://github.com/cpp-netlib/cpp-netlib/issues/264
27+
.. _`#255`: https://github.com/cpp-netlib/cpp-netlib/issues/255
28+
.. _`#166`: https://github.com/cpp-netlib/cpp-netlib/issues/166
29+
1030
v0.10.0
1131
~~~~~~~
1232
* Added support for more HTTP status codes (206, 408, 412, 416, 507).

libs/network/doc/html/contents.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ <h3>Navigation</h3>
5959
<li class="toctree-l1"><a class="reference internal" href="index.html#want-to-learn-more">Want to learn more?</a></li>
6060
<li class="toctree-l1"><a class="reference internal" href="whats_new.html">What&#8217;s New</a><ul>
6161
<li class="toctree-l2"><a class="reference internal" href="whats_new.html#cpp-netlib-0-10"><tt class="docutils literal"><span class="pre">cpp-netlib</span></tt> 0.10</a><ul>
62+
<li class="toctree-l3"><a class="reference internal" href="whats_new.html#v0-10-1">v0.10.1</a></li>
6263
<li class="toctree-l3"><a class="reference internal" href="whats_new.html#v0-10-0">v0.10.0</a></li>
6364
</ul>
6465
</li>
@@ -270,7 +271,7 @@ <h3>Navigation</h3>
270271
</div>
271272
<div class="footer">
272273
&copy; Copyright 2008-2013, Glyn Matthews, Dean Michael Berris; 2013 Google, Inc..
273-
Last updated on Jun 28, 2013.
274+
Last updated on Jul 04, 2013.
274275
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b1.
275276
</div>
276277
</body>

libs/network/doc/html/examples.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ <h3>Navigation</h3>
131131
</div>
132132
<div class="footer">
133133
&copy; Copyright 2008-2013, Glyn Matthews, Dean Michael Berris; 2013 Google, Inc..
134-
Last updated on Jun 28, 2013.
134+
Last updated on Jul 04, 2013.
135135
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b1.
136136
</div>
137137
</body>

libs/network/doc/html/examples/http/atom_reader.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ <h3>Navigation</h3>
175175
</div>
176176
<div class="footer">
177177
&copy; Copyright 2008-2013, Glyn Matthews, Dean Michael Berris; 2013 Google, Inc..
178-
Last updated on Jun 28, 2013.
178+
Last updated on Jul 04, 2013.
179179
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b1.
180180
</div>
181181
</body>

libs/network/doc/html/examples/http/hello_world_client.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ <h3>Navigation</h3>
192192
</div>
193193
<div class="footer">
194194
&copy; Copyright 2008-2013, Glyn Matthews, Dean Michael Berris; 2013 Google, Inc..
195-
Last updated on Jun 28, 2013.
195+
Last updated on Jul 04, 2013.
196196
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b1.
197197
</div>
198198
</body>

0 commit comments

Comments
 (0)