Skip to content

Commit 5b11931

Browse files
committed
Fixing response concept, adding the notion of modifiers as an extension point for messages.
1 parent 87a2d55 commit 5b11931

File tree

6 files changed

+146
-3
lines changed

6 files changed

+146
-3
lines changed

boost/network/message/message_concept.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Copyright (c) Glyn Matthews 2010.
2+
// Copyright 2010 (c) Dean Michael Berris.
3+
// Copyright 2010 (c) Sinefunc, Inc.
24
// Distributed under the Boost Software License, Version 1.0.
35
// (See accompanying file LICENSE_1_0.txt or copy at
46
// http://www.boost.org/LICENSE_1_0.txt)
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_MODIFIERS_STATUS_HPP_20100608
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIERS_STATUS_HPP_20100608
3+
4+
// Copyright 2010 (c) Dean Michael Berris
5+
// Copyright 2010 (c) Sinefunc, Inc.
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
10+
#include <boost/network/support/is_async.hpp>
11+
#include <boost/thread/future.hpp>
12+
13+
namespace boost { namespace network { namespace http {
14+
15+
template <class Tag>
16+
struct basic_response;
17+
18+
namespace impl {
19+
20+
template <class Tag, class T>
21+
void status(basic_response<Tag> & response, T const & value, mpl::false_ const &) {
22+
response << boost::network::http::status(value);
23+
}
24+
25+
template <class Tag, class T>
26+
void status(basic_response<Tag> & response, boost::shared_future<T> future, mpl::true_ const &) {
27+
response.status() = future;
28+
}
29+
30+
} // namespace impl
31+
32+
template <class Tag, class T>
33+
void status(basic_response<Tag> & response, T const & value) {
34+
impl::status(response, value, is_async<Tag>());
35+
}
36+
37+
} // namespace http
38+
39+
} // namespace network
40+
41+
} // namespace boost
42+
43+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIERS_STATUS_HPP_20100608
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_MODIFIERS_STATUS_MESSAGE_HPP_20100608
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIERS_STATUS_MESSAGE_HPP_20100608
3+
4+
// Copyright 2010 (c) Dean Michael Berris
5+
// Copyright 2010 (c) Sinefunc, Inc.
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
10+
#include <boost/network/support/is_async.hpp>
11+
#include <boost/thread/future.hpp>
12+
13+
namespace boost { namespace network { namespace http {
14+
15+
template <class Tag>
16+
struct basic_response;
17+
18+
namespace impl {
19+
20+
template <class Tag, class T>
21+
void status_message(basic_response<Tag> & response, T const & value, mpl::false_ const &) {
22+
response << boost::network::http::status_message(value);
23+
}
24+
25+
template <class Tag, class T>
26+
void status_message(basic_response<Tag> & response, boost::shared_future<T> future, mpl::true_ const &) {
27+
response.status_message() = future;
28+
}
29+
30+
} // namespace impl
31+
32+
template <class Tag, class T>
33+
void status_message(basic_response<Tag> & response, T const & value) {
34+
impl::status_message(response, value, is_async<Tag>());
35+
}
36+
37+
} // namespace http
38+
39+
} // namespace network
40+
41+
} // namespace boost
42+
43+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIERS_STATUS_MESSAGE_HPP_20100608
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIERS_VERSION_HPP_20100608
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIERS_VERSION_HPP_20100608
3+
4+
// Copyright 2010 (c) Dean Michael Berris
5+
// Copyright 2010 (c) Sinefunc, Inc.
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
10+
#include <boost/network/support/is_async.hpp>
11+
12+
namespace boost { namespace network { namespace http {
13+
14+
template <class Tag>
15+
struct basic_response;
16+
17+
namespace impl {
18+
19+
template <class Tag, class T>
20+
void version(basic_response<Tag> & response, T const & value, mpl::false_ const &) {
21+
response << boost::network::http::version(value);
22+
}
23+
24+
template <class Tag, class T>
25+
void version(basic_response<Tag> & response, T const & future, mpl::true_ const &) {
26+
response.version(future);
27+
}
28+
29+
} // namespace impl
30+
31+
template <class Tag, class T>
32+
void version(basic_response<Tag> & response, T const & value) {
33+
impl::version(response, value, is_async<Tag>());
34+
}
35+
36+
} // namespace http
37+
38+
} // namespace network
39+
40+
} // namespace boost
41+
42+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIERS_VERSION_HPP_20100608

boost/network/protocol/http/response.hpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,25 @@
1313
#include <boost/cstdint.hpp>
1414
#include <boost/network/protocol/http/response_concept.hpp>
1515

16+
#include <boost/network/protocol/http/message/message_base.hpp>
17+
1618
namespace boost { namespace network { namespace http {
1719

1820
template <class Tag>
19-
struct basic_response : public message_impl<Tag> {
21+
struct basic_response : public message_base<Tag>::type {
22+
23+
typedef typename string<Tag>::type string_type;
24+
2025
private:
21-
typedef message_impl<Tag> base_type;
26+
typedef typename message_base<Tag>::type base_type;
2227

2328
mutable string_type version_;
2429
mutable boost::uint16_t status_;
2530
mutable string_type status_message_;
31+
2632
public:
2733

2834
typedef Tag tag;
29-
typedef typename string<Tag>::type string_type;
3035

3136
basic_response()
3237
: base_type(), version_(), status_(0u), status_message_()
@@ -104,4 +109,8 @@ namespace boost { namespace network { namespace http {
104109
#include <boost/network/protocol/http/message/wrappers/status.hpp>
105110
#include <boost/network/protocol/http/message/wrappers/status_message.hpp>
106111

112+
#include <boost/network/protocol/http/message/modifiers/version.hpp>
113+
#include <boost/network/protocol/http/message/modifiers/status.hpp>
114+
#include <boost/network/protocol/http/message/modifiers/status_message.hpp>
115+
107116
#endif // BOOST_NETWORK_PROTOCOL_HTTP_RESPONSE_HPP

boost/network/protocol/http/response_concept.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ namespace boost { namespace network { namespace http {
2828
<< status_message("OK") // status_message directive
2929
;
3030

31+
version(response, "HTTP/1.0");
32+
status(response, 200u);
33+
status_message(response, "OK");
34+
3135
string_type version_ = version(response);
3236
boost::uint16_t status_ = status(response);
3337
string_type status_message_ = status_message(response);

0 commit comments

Comments
 (0)