Skip to content

Commit 4e69162

Browse files
committed
Merging a checkpoint from 0.5-devel to master.
2 parents b78fb25 + 01140d2 commit 4e69162

Some content is hidden

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

75 files changed

+2063
-631
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.cmake
2+
*.swp
3+
*.pyc
4+
CMakeCache.txt
5+
CMakeFiles
6+
Makefile
7+
Testing
8+
build
9+
bin
10+

README.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ This is a collection of network related routines/implementations
44
geared towards providing a robust cross-platform networking library.
55
This offers the following implementations:
66

7-
o Common Message Type -- A generic message type which can be used
7+
* Common Message Type -- A generic message type which can be used
88
to encapsulate and store message related information, used by all
99
network implementations as the primary means of data exchange.
10-
o Network protocol message parsers -- A collection of parsers which
10+
* Network protocol message parsers -- A collection of parsers which
1111
generate message objects from strings.
12-
o Adapters and Wrappers -- A collection of Adapters and wrappers aimed
12+
* Adapters and Wrappers -- A collection of Adapters and wrappers aimed
1313
towards making the message type STL friendly.
14-
o Network protocol client and server implementations -- A collection
14+
* Network protocol client and server implementations -- A collection
1515
of network protocol implementations that include embeddable client
1616
and server types.
1717

boost/network/message.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// Copyright Dean Michael Berris 2007.
32
// Distributed under the Boost Software License, Version 1.0.
43
// (See accompanying file LICENSE_1_0.txt or copy at

boost/network/protocol/http/client.hpp

+55-252
Large diffs are not rendered by default.

boost/network/protocol/http/client_fwd.hpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@
77
#ifndef __NETWORK_PROTOCOL_HTTP_CLIENT_20080923_1_HPP__
88
#define __NETWORK_PROTOCOL_HTTP_CLIENT_20080923_1_HPP__
99

10-
#ifndef BOOST_NETLIB_VERSION
11-
#define BOOST_NETLIB_VERSION "0.3"
12-
#endif
13-
10+
#include <boost/network/version.hpp>
1411
#include <boost/network/tags.hpp>
1512

1613
namespace boost { namespace network { namespace http {
1714

1815
//! Forward declaration of basic_client template.
19-
template <class tag, unsigned version_major, unsigned version_minor>
16+
template <class Tag, unsigned version_major, unsigned version_minor>
2017
class basic_client;
2118

22-
typedef basic_client<tags::http, 1, 0> client;
19+
typedef basic_client<tags::http_default_8bit_tcp_resolve, 1, 0> client;
2320

2421
} // namespace http
2522

boost/network/protocol/http/connection.hpp

+42-51
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,19 @@
44
// the Boost Software License, Version 1.0. (See acccompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
66
//
7-
// =====================================================================================
8-
//
9-
// Filename: connection.hpp
10-
//
11-
// Description: Connection handler for the HTTP requests.
12-
//
13-
// Version: 1.1
14-
// Created: Sunday, 15 November, 2009 07:46:40 PHT
15-
//
16-
// Author: Dean Michael Berris (dmb), [email protected]
17-
//
18-
// =====================================================================================
19-
//
207

218
#ifndef BOOST_NETWORK_HTTP_CONNECTION_HPP_
229
#define BOOST_NETWORK_HTTP_CONNECTION_HPP_
2310

11+
#ifndef BOOST_HTTP_SERVER_BUFFER_SIZE
12+
#define BOOST_HTTP_SERVER_BUFFER_SIZE 1024
13+
#endif
14+
2415
#include <boost/enable_shared_from_this.hpp>
2516
#include <boost/network/protocol/http/request_parser.hpp>
2617
#include <boost/network/protocol/http/request.hpp>
2718
#include <boost/network/protocol/http/header.hpp>
28-
#include <boost/network/protocol/http/reply.hpp>
19+
#include <boost/network/protocol/http/response.hpp>
2920
#include <boost/asio.hpp>
3021
#include <boost/array.hpp>
3122
#include <boost/lexical_cast.hpp>
@@ -45,8 +36,8 @@ namespace boost { namespace network { namespace http {
4536
using boost::bind;
4637
using boost::to_lower_copy;
4738

48-
template <class Handler>
49-
struct connection : boost::enable_shared_from_this<connection<Handler> > {
39+
template <class Tag, class Handler>
40+
struct connection : boost::enable_shared_from_this<connection<Tag,Handler> > {
5041

5142
connection(io_service & service, Handler & handler)
5243
: service_(service)
@@ -75,8 +66,8 @@ namespace boost { namespace network { namespace http {
7566
boost::asio::buffer(buffer_),
7667
wrapper_.wrap(
7768
bind(
78-
&connection<Handler>::handle_read_headers,
79-
connection<Handler>::shared_from_this(),
69+
&connection<Tag,Handler>::handle_read_headers,
70+
connection<Tag,Handler>::shared_from_this(),
8071
boost::asio::placeholders::error,
8172
boost::asio::placeholders::bytes_transferred
8273
)
@@ -107,14 +98,14 @@ namespace boost { namespace network { namespace http {
10798
is_content_length()
10899
);
109100
if (it == request_.headers.end()) {
110-
reply_= reply::stock_reply(reply::bad_request);
101+
response_= basic_response<Tag>::stock_reply(basic_response<Tag>::bad_request);
111102
boost::asio::async_write(
112103
socket_,
113-
reply_.to_buffers(),
104+
response_.to_buffers(),
114105
wrapper_.wrap(
115106
bind(
116-
&connection<Handler>::handle_write,
117-
connection<Handler>::shared_from_this(),
107+
&connection<Tag,Handler>::handle_write,
108+
connection<Tag,Handler>::shared_from_this(),
118109
boost::asio::placeholders::error
119110
)
120111
)
@@ -127,14 +118,14 @@ namespace boost { namespace network { namespace http {
127118
try {
128119
content_length = boost::lexical_cast<size_t>(it->value);
129120
} catch (...) {
130-
reply_= reply::stock_reply(reply::bad_request);
121+
response_= basic_response<Tag>::stock_reply(basic_response<Tag>::bad_request);
131122
boost::asio::async_write(
132123
socket_,
133-
reply_.to_buffers(),
124+
response_.to_buffers(),
134125
wrapper_.wrap(
135126
bind(
136-
&connection<Handler>::handle_write,
137-
connection<Handler>::shared_from_this(),
127+
&connection<Tag,Handler>::handle_write,
128+
connection<Tag,Handler>::shared_from_this(),
138129
boost::asio::placeholders::error
139130
)
140131
)
@@ -149,8 +140,8 @@ namespace boost { namespace network { namespace http {
149140
boost::asio::transfer_at_least(content_length),
150141
wrapper_.wrap(
151142
bind(
152-
&connection<Handler>::handle_read_body_contents,
153-
connection<Handler>::shared_from_this(),
143+
&connection<Tag,Handler>::handle_read_body_contents,
144+
connection<Tag,Handler>::shared_from_this(),
154145
boost::asio::placeholders::error,
155146
content_length,
156147
boost::asio::placeholders::bytes_transferred
@@ -160,41 +151,41 @@ namespace boost { namespace network { namespace http {
160151
return;
161152
}
162153

163-
handler_(request_, reply_);
154+
handler_(request_, response_);
164155
boost::asio::async_write(
165156
socket_,
166-
reply_.to_buffers(),
157+
response_.to_buffers(),
167158
wrapper_.wrap(
168159
bind(
169-
&connection<Handler>::handle_write,
170-
connection<Handler>::shared_from_this(),
160+
&connection<Tag,Handler>::handle_write,
161+
connection<Tag,Handler>::shared_from_this(),
171162
boost::asio::placeholders::error
172163
)
173164
)
174165
);
175166
} else {
176-
handler_(request_, reply_);
167+
handler_(request_, response_);
177168
boost::asio::async_write(
178169
socket_,
179-
reply_.to_buffers(),
170+
response_.to_buffers(),
180171
wrapper_.wrap(
181172
bind(
182-
&connection<Handler>::handle_write,
183-
connection<Handler>::shared_from_this(),
173+
&connection<Tag,Handler>::handle_write,
174+
connection<Tag,Handler>::shared_from_this(),
184175
boost::asio::placeholders::error
185176
)
186177
)
187178
);
188179
}
189180
} else if (!done) {
190-
reply_= reply::stock_reply(reply::bad_request);
181+
response_= basic_response<Tag>::stock_reply(basic_response<Tag>::bad_request);
191182
boost::asio::async_write(
192183
socket_,
193-
reply_.to_buffers(),
184+
response_.to_buffers(),
194185
wrapper_.wrap(
195186
bind(
196-
&connection<Handler>::handle_write,
197-
connection<Handler>::shared_from_this(),
187+
&connection<Tag,Handler>::handle_write,
188+
connection<Tag,Handler>::shared_from_this(),
198189
boost::asio::placeholders::error
199190
)
200191
)
@@ -204,8 +195,8 @@ namespace boost { namespace network { namespace http {
204195
boost::asio::buffer(buffer_),
205196
wrapper_.wrap(
206197
bind(
207-
&connection<Handler>::handle_read_headers,
208-
connection<Handler>::shared_from_this(),
198+
&connection<Tag,Handler>::handle_read_headers,
199+
connection<Tag,Handler>::shared_from_this(),
209200
boost::asio::placeholders::error,
210201
boost::asio::placeholders::bytes_transferred
211202
)
@@ -221,14 +212,14 @@ namespace boost { namespace network { namespace http {
221212
size_t difference = bytes_to_read - bytes_transferred;
222213
request_.body.append(buffer_.begin(), buffer_.end());
223214
if (difference == 0) {
224-
handler_(request_, reply_);
215+
handler_(request_, response_);
225216
boost::asio::async_write(
226217
socket_,
227-
reply_.to_buffers(),
218+
response_.to_buffers(),
228219
wrapper_.wrap(
229220
bind(
230-
&connection<Handler>::handle_write,
231-
connection<Handler>::shared_from_this(),
221+
&connection<Tag,Handler>::handle_write,
222+
connection<Tag,Handler>::shared_from_this(),
232223
boost::asio::placeholders::error
233224
)
234225
)
@@ -238,8 +229,8 @@ namespace boost { namespace network { namespace http {
238229
boost::asio::buffer(buffer_),
239230
wrapper_.wrap(
240231
bind(
241-
&connection<Handler>::handle_read_body_contents,
242-
connection<Handler>::shared_from_this(),
232+
&connection<Tag,Handler>::handle_read_body_contents,
233+
connection<Tag,Handler>::shared_from_this(),
243234
boost::asio::placeholders::error,
244235
difference,
245236
boost::asio::placeholders::bytes_transferred
@@ -262,10 +253,10 @@ namespace boost { namespace network { namespace http {
262253
Handler & handler_;
263254
tcp::socket socket_;
264255
io_service::strand wrapper_;
265-
array<char,4096> buffer_;
256+
array<char,BOOST_HTTP_SERVER_BUFFER_SIZE> buffer_;
266257
request_parser parser_;
267-
request_pod request_;
268-
reply reply_;
258+
basic_request<Tag> request_;
259+
basic_response<Tag> response_;
269260
};
270261

271262

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_DETAIL_CONNECTION_HELPER_20091217
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_DETAIL_CONNECTION_HELPER_20091217
3+
4+
// Copyright Dean Michael Berris 2009.
5+
// Distributed under the Boost Software License, Version 1.0.
6+
// (See accompanying file LICENSE_1_0.txt or copy at
7+
// http://www.boost.org/LICENSE_1_0.txt)
8+
9+
#include <boost/network/version.hpp>
10+
#include <boost/foreach.hpp>
11+
#include <boost/network/protocol/http/traits/connection_keepalive.hpp>
12+
13+
namespace boost { namespace network { namespace http { namespace detail {
14+
15+
template <class Tag, unsigned version_major, unsigned version_minor>
16+
struct connection_helper {
17+
protected:
18+
19+
typedef typename string<Tag>::type string_type;
20+
21+
void create_request(boost::asio::streambuf & request_buffer, string_type const & method, basic_request<Tag> request_) const {
22+
// TODO make this use Boost.Karma instead of an ad-hoc implementation
23+
std::ostream request_stream(&request_buffer);
24+
25+
request_stream
26+
<< method << " ";
27+
28+
if (request_.path().empty() || request_.path()[0] != '/')
29+
request_stream << '/';
30+
31+
request_stream
32+
<< request_.path()
33+
;
34+
35+
if (!request_.query().empty())
36+
request_stream
37+
<< '?'
38+
<< request_.query()
39+
;
40+
41+
if (!request_.anchor().empty())
42+
request_stream
43+
<< '#'
44+
<< request_.anchor()
45+
;
46+
47+
request_stream << " HTTP/" << version_major << '.' << version_minor << "\r\n"
48+
<< "Host: " << request_.host() << "\r\n"
49+
<< "Accept: */*\r\n";
50+
51+
if (version_major == 1 && version_minor == 1)
52+
request_stream
53+
<< "Accept-Encoding: identity;q=1.0, *;q=0\r\n"; // only accept identity encoding
54+
55+
typename headers_range<http::basic_request<Tag> >::type range = headers(request_);
56+
BOOST_FOREACH(typename headers_range<http::basic_request<Tag> >::type::value_type const & header, range) {
57+
request_stream << header.first << ": " << header.second << "\r\n";
58+
};
59+
60+
range = headers(request_)["user-agent"];
61+
if (empty(range)) request_stream << "User-Agent: cpp-netlib/" << BOOST_NETLIB_VERSION << "\r\n";
62+
63+
if (!connection_keepalive<Tag>::value) {
64+
request_stream
65+
<< "Connection: close\r\n";
66+
}
67+
request_stream
68+
<< "\r\n";
69+
70+
string_type body_ = body(request_);
71+
if (!body_.empty())
72+
request_stream << body_;
73+
}
74+
75+
};
76+
77+
} // namespace detail
78+
79+
} // namespace http
80+
81+
} // namespace network
82+
83+
} // namespace boost
84+
85+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_DETAIL_CONNECTION_HELPER_20091217
86+

boost/network/protocol/http/errors.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace boost { namespace network { namespace http { namespace errors {
1414

15-
template <class Tag=tags::http>
15+
template <class Tag=tags::http_default_8bit_tcp_resolve>
1616
struct connection_timeout_exception :
1717
std::runtime_error
1818
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_IMPL_CLIENT_IPP
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_IMPL_CLIENT_IPP
3+
4+
namespace boost { namespace network { namespace http {
5+
6+
7+
} // namespace http
8+
9+
} // namespace network
10+
11+
} // namespace boost
12+
13+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_IMPL_CLIENT_IPP
14+

0 commit comments

Comments
 (0)