Skip to content

Commit e1cee56

Browse files
committed
Making Linearize more Generic
This implementation of linearize turns it into a generic algorithm that works on types that model the Client Request concept. This is important because it means any type that models the Client Request concept can then be linearized into an output iterator.
1 parent 00b27b7 commit e1cee56

File tree

7 files changed

+78
-40
lines changed

7 files changed

+78
-40
lines changed

boost/network/message.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace boost { namespace network {
4444
typedef Tag tag;
4545

4646
typedef typename headers_container<Tag>::type headers_container_type;
47+
typedef typename headers_container_type::value_type header_type;
4748
typedef typename string<Tag>::type string_type;
4849

4950
basic_message()

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <boost/network/protocol/http/message/header/name.hpp>
1111
#include <boost/network/protocol/http/message/header/value.hpp>
1212
#include <boost/network/protocol/http/message/header_concept.hpp>
13+
#include <boost/network/protocol/http/request_concept.hpp>
1314
#include <boost/network/constants.hpp>
1415
#include <boost/concept/requires.hpp>
1516
#include <boost/range/algorithm/copy.hpp>
@@ -43,15 +44,19 @@ namespace boost { namespace network { namespace http {
4344
}
4445
};
4546

46-
template <class Tag, class OutputIterator>
47-
OutputIterator linearize(
48-
basic_request<Tag> const & request,
49-
typename string<Tag>::type const & method,
47+
template <class Request, class OutputIterator>
48+
BOOST_CONCEPT_REQUIRES(
49+
((ClientRequest<Request>)),
50+
(OutputIterator)
51+
) linearize(
52+
Request const & request,
53+
typename Request::string_type const & method,
5054
unsigned version_major,
5155
unsigned version_minor,
5256
OutputIterator oi
5357
)
5458
{
59+
typedef typename Request::tag Tag;
5560
typedef constants<Tag> consts;
5661
typedef typename string<Tag>::type string_type;
5762
static string_type
@@ -103,7 +108,7 @@ namespace boost { namespace network { namespace http {
103108
boost::copy(default_accept_encoding, oi);
104109
boost::copy(crlf, oi);
105110
}
106-
typedef typename headers_range<basic_request<Tag> >::type headers_range;
111+
typedef typename headers_range<Request>::type headers_range;
107112
typedef typename range_iterator<headers_range>::type headers_iterator;
108113
headers_range request_headers = headers(request);
109114
headers_iterator iterator = boost::begin(request_headers),
@@ -125,7 +130,7 @@ namespace boost { namespace network { namespace http {
125130
boost::copy(crlf, oi);
126131
}
127132
boost::copy(crlf, oi);
128-
typename body_range<basic_request<Tag> >::type body_data = body(request).range();
133+
typename body_range<Request>::type body_data = body(request).range();
129134
return boost::copy(body_data, oi);
130135
}
131136

boost/network/protocol/http/message/modifiers/body.hpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <boost/network/protocol/http/tags.hpp>
1010
#include <boost/network/support/is_async.hpp>
11+
#include <boost/network/protocol/http/support/client_or_server.hpp>
1112
#include <boost/thread/future.hpp>
1213
#include <boost/concept/requires.hpp>
1314
#include <boost/network/message/directives.hpp>
@@ -37,26 +38,40 @@ namespace boost { namespace network { namespace http {
3738
request.body = value;
3839
}
3940

41+
template <class Tag, class T>
42+
void body(basic_request<Tag> & request, T const & value, tags::client const &) {
43+
request << ::boost::network::body(value);
44+
}
45+
4046
}
4147

4248
template <class Tag, class T>
43-
inline
44-
BOOST_CONCEPT_REQUIRES(((Response<basic_response<Tag> >)),
45-
(void))
49+
inline void
4650
body(basic_response<Tag> & response, T const & value) {
4751
impl::body(response, value, is_async<Tag>());
4852
}
4953

54+
template <class Tag, class T>
55+
inline void
56+
body_impl(basic_request<Tag> & request, T const & value, tags::server) {
57+
impl::body(request, value, Tag());
58+
}
59+
5060
template <class R>
51-
struct ServerRequest;
61+
struct ClientRequest;
5262

5363
template <class Tag, class T>
54-
inline BOOST_CONCEPT_REQUIRES(((ServerRequest<basic_request<Tag> >)),
55-
(void))
56-
body(basic_request<Tag> & request, T const & value) {
64+
inline void
65+
body_impl(basic_request<Tag> & request, T const & value, tags::client) {
5766
impl::body(request, value, Tag());
5867
}
5968

69+
template <class Tag, class T>
70+
inline void
71+
body(basic_request<Tag> & request, T const & value) {
72+
body_impl(request, value, typename client_or_server<Tag>::type());
73+
}
74+
6075
} // namespace http
6176

6277
namespace impl {

boost/network/protocol/http/message/modifiers/destination.hpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
88

9+
#include <boost/network/protocol/http/support/client_or_server.hpp>
910
#include <boost/network/support/is_async.hpp>
1011
#include <boost/thread/future.hpp>
1112
#include <boost/concept/requires.hpp>
@@ -35,15 +36,15 @@ namespace boost { namespace network { namespace http {
3536
request.destination = value;
3637
}
3738

38-
}
39+
template <class Tag, class T>
40+
void destination(basic_request<Tag> & request, T const & value, tags::client const &) {
41+
request << ::boost::network::destination(value);
42+
}
3943

40-
template <class R>
41-
struct Response;
44+
}
4245

4346
template <class Tag, class T>
44-
inline
45-
BOOST_CONCEPT_REQUIRES(((Response<basic_response<Tag> >)),
46-
(void))
47+
inline void
4748
destination(basic_response<Tag> & response, T const & value) {
4849
impl::destination(response, value, is_async<Tag>());
4950
}
@@ -52,13 +53,23 @@ namespace boost { namespace network { namespace http {
5253
struct ServerRequest;
5354

5455
template <class Tag, class T>
55-
inline
56-
BOOST_CONCEPT_REQUIRES(((ServerRequest<basic_request<Tag> >)),
57-
(void))
58-
destination(basic_request<Tag> & request, T const & value) {
56+
inline void
57+
destination_impl(basic_request<Tag> & request, T const & value, tags::server) {
58+
impl::destination(request, value, Tag());
59+
}
60+
61+
template <class Tag, class T>
62+
inline void
63+
destination_impl(basic_request<Tag> & request, T const & value, tags::client) {
5964
impl::destination(request, value, Tag());
6065
}
6166

67+
template <class Tag, class T>
68+
inline void
69+
destination(basic_request<Tag> & request, T const & value) {
70+
destination_impl(request, value, typename client_or_server<Tag>::type());
71+
}
72+
6273
} // namespace http
6374

6475
namespace impl {

boost/network/protocol/http/message/modifiers/headers.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,13 @@ namespace boost { namespace network { namespace http {
3838
}
3939

4040
template <class Tag, class T>
41-
inline
42-
BOOST_CONCEPT_REQUIRES(((Response<basic_response<Tag> >)),
43-
(void))
41+
inline void
4442
headers(basic_response<Tag> & response, T const & value) {
4543
impl::headers(response, value, is_async<Tag>());
4644
}
4745

4846
template <class Tag, class T>
49-
inline BOOST_CONCEPT_REQUIRES(((ServerRequest<basic_request<Tag> >)),
50-
(void))
47+
inline void
5148
headers(basic_request<Tag> & request, T const & value) {
5249
impl::headers(request, value, Tag());
5350
}

boost/network/protocol/http/message/modifiers/source.hpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// http://www.boost.org/LICENSE_1_0.txt)
88

99
#include <boost/network/support/is_async.hpp>
10+
#include <boost/network/protocol/http/support/client_or_server.hpp>
1011
#include <boost/thread/future.hpp>
1112
#include <boost/concept/requires.hpp>
1213
#include <boost/network/protocol/http/tags.hpp>
@@ -34,28 +35,35 @@ namespace boost { namespace network { namespace http {
3435
request.source = value;
3536
}
3637

37-
}
38+
template <class Tag, class T>
39+
void source(basic_request<Tag> & request, T const & value, tags::client const &) {
40+
request << ::boost::network::source(value);
41+
}
3842

39-
template <class R>
40-
struct Response;
43+
}
4144

4245
template <class Tag, class T>
43-
inline
44-
BOOST_CONCEPT_REQUIRES(((Response<basic_response<Tag> >)),
45-
(void))
46+
inline void
4647
source(basic_response<Tag> & response, T const & value) {
4748
impl::source(response, value, is_async<Tag>());
4849
}
4950

50-
template <class R>
51-
struct ServerRequest;
51+
template <class Tag, class T>
52+
inline void
53+
source_impl(basic_request<Tag> & request, T const & value, tags::server) {
54+
impl::source(request, value, Tag());
55+
}
56+
57+
template <class Tag, class T>
58+
inline void
59+
source_impl(basic_request<Tag> & request, T const & value, tags::client) {
60+
impl::source(request, value, Tag());
61+
}
5262

5363
template <class Tag, class T>
54-
inline
55-
BOOST_CONCEPT_REQUIRES(((ServerRequest<basic_request<Tag> >)),
56-
(void))
64+
inline void
5765
source(basic_request<Tag> & request, T const & value) {
58-
impl::source(request, value, Tag());
66+
source_impl(request, value, typename client_or_server<Tag>::type());
5967
}
6068

6169
} // namespace http

boost/network/protocol/http/request.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <boost/network/protocol/http/message/modifiers/destination.hpp>
3838
#include <boost/network/protocol/http/message/modifiers/headers.hpp>
3939
#include <boost/network/protocol/http/message/modifiers/body.hpp>
40+
#include <boost/network/protocol/http/message/modifiers/clear_headers.hpp>
4041
#include <boost/network/protocol/http/message/wrappers/major_version.hpp>
4142
#include <boost/network/protocol/http/message/wrappers/minor_version.hpp>
4243
#include <boost/network/protocol/http/message/wrappers/source.hpp>

0 commit comments

Comments
 (0)