Skip to content

Commit 2489449

Browse files
committed
WIP: Isolating ServerRequest Concept.
1 parent a418cf4 commit 2489449

File tree

10 files changed

+205
-21
lines changed

10 files changed

+205
-21
lines changed

boost/network/protocol/http/impl/request.hpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include <boost/network/support/is_async.hpp>
2323
#include <boost/network/protocol/http/support/sync_only.hpp>
2424

25+
#include <boost/network/protocol/http/message/wrappers/method.hpp>
26+
#include <boost/network/protocol/http/message/modifiers/method.hpp>
27+
2528
#include <boost/cstdint.hpp>
2629

2730
namespace boost { namespace network { namespace http {
@@ -115,9 +118,12 @@ namespace boost { namespace network { namespace http {
115118
* basic_request template above to be
116119
* primarily and be solely a POD for performance
117120
* reasons.
121+
*
122+
* Reality check: This is not a POD because it contains a non-POD
123+
* member, the headers vector. :(
118124
*/
119125
template <class Tag>
120-
struct pod_request_base {
126+
struct not_quite_pod_request_base {
121127
typedef Tag tag;
122128
typedef typename string<Tag>::type string_type;
123129
typedef typename vector<tags::http_server>::
@@ -133,7 +139,7 @@ namespace boost { namespace network { namespace http {
133139
mutable vector_type headers;
134140
mutable string_type body;
135141

136-
void swap(pod_request_base & r) const {
142+
void swap(not_quite_pod_request_base & r) const {
137143
using std::swap;
138144
swap(method, r.method);
139145
swap(source, r.source);
@@ -146,10 +152,20 @@ namespace boost { namespace network { namespace http {
146152
};
147153

148154
template <>
149-
struct basic_request<tags::http_async_server> : pod_request_base<tags::http_async_server> {};
155+
struct basic_request<tags::http_async_server>
156+
: not_quite_pod_request_base<tags::http_async_server>
157+
{};
150158

151159
template <>
152-
struct basic_request<tags::http_server> : pod_request_base<tags::http_server> {};
160+
struct basic_request<tags::http_server>
161+
: not_quite_pod_request_base<tags::http_server>
162+
{};
163+
164+
template <class R>
165+
struct ServerRequest;
166+
167+
BOOST_CONCEPT_ASSERT((ServerRequest<basic_request<tags::http_async_server> >));
168+
BOOST_CONCEPT_ASSERT((ServerRequest<basic_request<tags::http_server> >));
153169

154170
template <class Tag>
155171
inline void swap(basic_request<Tag> & lhs, basic_request<Tag> & rhs) {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ namespace boost { namespace network { namespace http {
1717
template <class Tag>
1818
struct basic_response;
1919

20+
template <class Tag>
21+
struct basic_request;
22+
2023
namespace impl {
2124

2225
template <class Tag, class T>
@@ -29,6 +32,11 @@ namespace boost { namespace network { namespace http {
2932
response.body(future);
3033
}
3134

35+
template <class Tag, class T>
36+
void body(basic_request<Tag> & request, T const & value, tags::server const &) {
37+
request.body = value;
38+
}
39+
3240
}
3341

3442
template <class Tag, class T>
@@ -39,6 +47,16 @@ namespace boost { namespace network { namespace http {
3947
impl::body(response, value, is_async<Tag>());
4048
}
4149

50+
template <class R>
51+
struct ServerRequest;
52+
53+
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) {
57+
impl::body(request, value, Tag());
58+
}
59+
4260
} // namespace http
4361

4462
namespace impl {

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ namespace boost { namespace network { namespace http {
1515
template <class Tag>
1616
struct basic_response;
1717

18+
template <class Tag>
19+
struct basic_request;
20+
1821
namespace impl {
1922

2023
template <class Tag, class T>
@@ -27,6 +30,11 @@ namespace boost { namespace network { namespace http {
2730
response.destination(future);
2831
}
2932

33+
template <class Tag, class T>
34+
void destination(basic_request<Tag> & request, T const & value, tags::server const &) {
35+
request.destination = value;
36+
}
37+
3038
}
3139

3240
template <class R>
@@ -40,6 +48,17 @@ namespace boost { namespace network { namespace http {
4048
impl::destination(response, value, is_async<Tag>());
4149
}
4250

51+
template <class R>
52+
struct ServerRequest;
53+
54+
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) {
59+
impl::destination(request, value, Tag());
60+
}
61+
4362
} // namespace http
4463

4564
namespace impl {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ namespace boost { namespace network { namespace http {
1515
template <class Tag>
1616
struct basic_response;
1717

18+
template <class Tag>
19+
struct basic_request;
20+
1821
namespace impl {
1922

2023
template <class Tag, class T>
@@ -27,6 +30,11 @@ namespace boost { namespace network { namespace http {
2730
response.headers(future);
2831
}
2932

33+
template <class Tag, class T>
34+
void headers(basic_request<Tag> & request, T const & value, tags::server const &) {
35+
request.headers = value;
36+
}
37+
3038
}
3139

3240
template <class Tag, class T>
@@ -37,6 +45,13 @@ namespace boost { namespace network { namespace http {
3745
impl::headers(response, value, is_async<Tag>());
3846
}
3947

48+
template <class Tag, class T>
49+
inline BOOST_CONCEPT_REQUIRES(((ServerRequest<basic_request<Tag> >)),
50+
(void))
51+
headers(basic_request<Tag> & request, T const & value) {
52+
impl::headers(request, value, Tag());
53+
}
54+
4055
} // namespace http
4156

4257
} // namespace network
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIERS_METHOD_HPP_20101118
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIERS_METHOD_HPP_20101118
3+
4+
// Copyright 2010 Dean Michael Berris.
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/traits/string.hpp>
10+
#include <boost/utility/enable_if.hpp>
11+
12+
namespace boost { namespace network { namespace http {
13+
14+
template <class Tag>
15+
struct basic_request;
16+
17+
template <class Tag>
18+
inline typename enable_if<is_server<Tag>, void>::type
19+
method(basic_request<Tag> & request, typename string<Tag>::type const & method_) {
20+
request.method = method_;
21+
}
22+
23+
} /* http */
24+
25+
} /* network */
26+
27+
} /* boost */
28+
29+
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIERS_METHOD_HPP_20101118 */

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ namespace boost { namespace network { namespace http {
2929
response.source(future);
3030
}
3131

32+
template <class Tag, class T>
33+
void source(basic_request<Tag> & request, T const & value, tags::server const &) {
34+
request.source = value;
35+
}
36+
3237
}
3338

3439
template <class R>
@@ -42,6 +47,17 @@ namespace boost { namespace network { namespace http {
4247
impl::source(response, value, is_async<Tag>());
4348
}
4449

50+
template <class R>
51+
struct ServerRequest;
52+
53+
template <class Tag, class T>
54+
inline
55+
BOOST_CONCEPT_REQUIRES(((ServerRequest<basic_request<Tag> >)),
56+
(void))
57+
source(basic_request<Tag> & request, T const & value) {
58+
impl::source(request, value, Tag());
59+
}
60+
4561
} // namespace http
4662

4763
namespace impl {

boost/network/protocol/http/message/wrappers/helper.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
name (basic_request<Tag> const & message) { \
6666
return name##_wrapper<basic_request<Tag> >(message); \
6767
}
68+
6869
#endif /* BOOST_NETWORK_DEFINE_HTTP_WRAPPER */
6970

7071
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_HELPER_20101013 */
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_METHOD_HPP_20101118
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_METHOD_HPP_20101118
3+
4+
// Copyright 2010 Dean Michael Berris.
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/utility/enable_if.hpp>
10+
#include <boost/network/protocol/http/support/is_server.hpp>
11+
12+
namespace boost { namespace network { namespace http {
13+
14+
template <class Tag>
15+
struct basic_request;
16+
17+
template <class Tag>
18+
struct method_wrapper {
19+
explicit method_wrapper(basic_request<Tag> const & message)
20+
: message_(message) {}
21+
22+
basic_request<Tag> const & message_;
23+
24+
typedef typename basic_request<Tag>::string_type string_type;
25+
26+
operator string_type() {
27+
return message_.method;
28+
}
29+
};
30+
31+
template <class Tag>
32+
inline typename enable_if<is_server<Tag>, typename string<Tag>::type >::type
33+
method(basic_request<Tag> const & message) {
34+
return method_wrapper<Tag>(message);
35+
}
36+
37+
} /* http */
38+
39+
} /* network */
40+
41+
} /* boost */
42+
43+
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_METHOD_HPP_20101118 */

boost/network/protocol/http/request_concept.hpp

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,62 @@
1616
namespace boost { namespace network { namespace http {
1717

1818
template <class R>
19-
struct PodServerRequest
20-
: boost::network::Message<R>
19+
struct ServerRequest
2120
{
2221
typedef typename R::string_type string_type;
22+
typedef typename R::tag tag;
23+
typedef typename R::headers_container_type headers_container_type;
24+
25+
BOOST_CONCEPT_USAGE(ServerRequest) {
26+
string_type source_, method_, destination_;
27+
boost::uint8_t major_version_, minor_version_;
28+
headers_container_type headers_;
29+
string_type body_;
30+
31+
source_ = source(request);
32+
method_ = method(request);
33+
destination_ = destination(request);
34+
major_version_ = major_version(request);
35+
minor_version_ = minor_version(request);
36+
headers_ = headers(request);
37+
body_ = body(request);
38+
39+
source(request, source_);
40+
method(request, method_);
41+
destination(request, destination_);
42+
major_version(request, major_version_);
43+
minor_version(request, minor_version_);
44+
headers(request, headers_);
45+
body(request, body_);
46+
47+
string_type name, value;
48+
49+
request << ::boost::network::source(source_)
50+
<< ::boost::network::destination(destination_)
51+
<< ::boost::network::http::method(method_)
52+
<< ::boost::network::http::major_version(major_version_)
53+
<< ::boost::network::http::minor_version(minor_version_)
54+
<< ::boost::network::header(name, value)
55+
<< ::boost::network::remove_header(name)
56+
<< ::boost::network::http::body(body_);
57+
58+
(void)source_;(void)method_;(void)destination_;
59+
(void)major_version_;(void)minor_version_;(void)headers_;
60+
(void)body_;(void)name;(void)value;
61+
}
2362

2463
private:
2564
R request;
2665
};
2766

2867
template <class R>
29-
struct NormalClientRequest
68+
struct ClientRequest
3069
: boost::network::Message<R>
3170
{
3271
typedef typename R::string_type string_type;
3372
typedef typename R::port_type port_type;
3473

35-
BOOST_CONCEPT_USAGE(NormalClientRequest) {
74+
BOOST_CONCEPT_USAGE(ClientRequest) {
3675
string_type tmp;
3776
R request_(tmp);
3877
swap(request, request_); // swappable via ADL
@@ -60,18 +99,6 @@ namespace boost { namespace network { namespace http {
6099
R request;
61100
};
62101

63-
template <class R>
64-
struct Request :
65-
mpl::if_<
66-
is_base_of<
67-
tags::pod,
68-
typename R::tag
69-
>,
70-
boost::network::Message<R>,
71-
NormalClientRequest<R>
72-
>::type
73-
{};
74-
75102
} // namespace http
76103

77104
} // namespace network

boost/network/protocol/http/traits.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
// Convenience header for including different traits implementations.
1414
#include <boost/network/protocol/http/traits/message_traits.hpp>
15-
#include <boost/network/protocol/http/traits/parser_traits.hpp>
15+
//#include <boost/network/protocol/http/traits/parser_traits.hpp>
1616
#include <boost/network/protocol/http/traits/connection_keepalive.hpp>
1717

1818
#endif // BOOST_NETWORK_PROTOCOL_HTTP_TRAITS_HPP

0 commit comments

Comments
 (0)