Skip to content

Commit 1ac4b50

Browse files
committed
Fixing server request concept, adding appropriate implementations.
1 parent 2489449 commit 1ac4b50

File tree

18 files changed

+344
-87
lines changed

18 files changed

+344
-87
lines changed

boost/network/message/modifiers/clear_headers.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,26 @@
77
// http://www.boost.org/LICENSE_1_0.txt)
88

99
#include <boost/network/support/is_async.hpp>
10+
#include <boost/network/support/is_pod.hpp>
1011
#include <boost/thread/future.hpp>
12+
#include <boost/utility/enable_if.hpp>
13+
#include <boost/mpl/not.hpp>
1114

1215
namespace boost { namespace network {
1316

1417
namespace impl {
1518
template <class Message, class Tag>
16-
inline void clear_headers(Message const & message, Tag const &, mpl::false_ const &) {
19+
inline typename enable_if<mpl::not_<is_pod<Tag> >, void>::type
20+
clear_headers(Message const & message, Tag const &, mpl::false_ const &) {
1721
(typename Message::headers_container_type()).swap(message.headers());
1822
}
1923

24+
template <class Message, class Tag>
25+
inline typename enable_if<is_pod<Tag>, void>::type
26+
clear_headers(Message const & message, Tag const &, mpl::false_ const &) {
27+
(typename Message::headers_container_type()).swap(message.headers);
28+
}
29+
2030
template <class Message, class Tag>
2131
inline void clear_headers(Message const & message, Tag const &, mpl::true_ const &) {
2232
boost::promise<typename Message::headers_container_type> header_promise;

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
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-
2825
#include <boost/cstdint.hpp>
2926

3027
namespace boost { namespace network { namespace http {

boost/network/protocol/http/message.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <boost/network/protocol/http/traits.hpp>
1616
#include <boost/network/protocol/http/message/modifiers/add_header.hpp>
1717
#include <boost/network/protocol/http/message/modifiers/remove_header.hpp>
18-
#include <boost/network/protocol/http/message/modifiers/clear_headers.hpp>
1918
#include <boost/network/message.hpp>
2019
#include <boost/network/tags.hpp>
2120
#include <string>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_MAJOR_VERSION_HPP_20101120
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_MAJOR_VERSION_HPP_20101120
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/protocol/http/support/is_server.hpp>
10+
#include <boost/utility/enable_if.hpp>
11+
#include <boost/cstdint.hpp>
12+
13+
namespace boost { namespace network { namespace http {
14+
15+
template <class Tag>
16+
struct basic_request;
17+
18+
struct major_version_directive {
19+
boost::uint8_t major_version;
20+
explicit major_version_directive(boost::uint8_t major_version)
21+
: major_version(major_version) {}
22+
template <class Tag>
23+
void operator()(basic_request<Tag> & request) const {
24+
request.http_version_major = major_version;
25+
}
26+
};
27+
28+
inline major_version_directive
29+
major_version(boost::uint8_t major_version_) {
30+
return major_version_directive(major_version_);
31+
}
32+
33+
} /* http */
34+
35+
} /* network */
36+
37+
} /* boost */
38+
39+
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_MAJOR_VERSION_HPP_20101120 */
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_METHOD_HPP_20101120
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_METHOD_HPP_20101120
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+
namespace boost { namespace network { namespace http {
10+
11+
BOOST_NETWORK_STRING_DIRECTIVE(method, method_,
12+
message.method(method_),
13+
message.method=method_);
14+
15+
} /* http */
16+
17+
} /* network */
18+
19+
} /* booet */
20+
21+
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_METHOD_HPP_20101120 */
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_MINOR_VERSION_HPP_20101120
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_MINOR_VERSION_HPP_20101120
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/protocol/http/support/is_server.hpp>
10+
#include <boost/utility/enable_if.hpp>
11+
#include <boost/cstdint.hpp>
12+
13+
namespace boost { namespace network { namespace http {
14+
15+
template <class Tag>
16+
struct basic_request;
17+
18+
struct minor_version_directive {
19+
boost::uint8_t minor_version;
20+
explicit minor_version_directive(boost::uint8_t minor_version)
21+
: minor_version(minor_version) {}
22+
template <class Tag>
23+
void operator()(basic_request<Tag> & request) const {
24+
request.http_version_minor = minor_version;
25+
}
26+
};
27+
28+
inline minor_version_directive
29+
minor_version(boost::uint8_t minor_version_) {
30+
return minor_version_directive(minor_version_);
31+
}
32+
33+
} /* http */
34+
35+
} /* network */
36+
37+
} /* boost */
38+
39+
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_MINOR_VERSION_HPP_20101120 */
40+

boost/network/protocol/http/message/directives/status.hpp

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -21,61 +21,57 @@ namespace boost { namespace network { namespace http {
2121
template <class Tag>
2222
struct basic_response;
2323

24-
namespace impl {
25-
26-
struct status_directive {
27-
28-
boost::variant<
29-
boost::uint16_t,
30-
boost::shared_future<boost::uint16_t>
31-
> status_;
32-
33-
status_directive(boost::uint16_t status)
34-
: status_(status) {}
35-
36-
status_directive(boost::shared_future<boost::uint16_t> const & status)
37-
: status_(status) {}
38-
39-
status_directive(status_directive const & other)
40-
: status_(other.status_) {}
41-
42-
template <class Tag>
43-
struct value
44-
: mpl::if_<
45-
is_async<Tag>,
46-
boost::shared_future<boost::uint16_t>,
47-
boost::uint16_t
48-
>
49-
{};
50-
51-
template <class Tag>
52-
struct status_visitor : boost::static_visitor<> {
53-
basic_response<Tag> const & response;
54-
status_visitor(basic_response<Tag> const & response)
55-
: response(response) {}
56-
57-
void operator()(typename value<Tag>::type const & status_) const {
58-
response.status(status_);
59-
}
60-
61-
template <class T>
62-
void operator()(T const &) const {
63-
// FIXME fail here!
64-
}
65-
};
66-
67-
template <class Tag> basic_response<Tag> const & operator() (basic_response<Tag> const & response) const {
68-
apply_visitor(status_visitor<Tag>(response), status_);
69-
return response;
24+
struct status_directive {
25+
26+
boost::variant<
27+
boost::uint16_t,
28+
boost::shared_future<boost::uint16_t>
29+
> status_;
30+
31+
explicit status_directive(boost::uint16_t status)
32+
: status_(status) {}
33+
34+
explicit status_directive(boost::shared_future<boost::uint16_t> const & status)
35+
: status_(status) {}
36+
37+
status_directive(status_directive const & other)
38+
: status_(other.status_) {}
39+
40+
template <class Tag>
41+
struct value
42+
: mpl::if_<
43+
is_async<Tag>,
44+
boost::shared_future<boost::uint16_t>,
45+
boost::uint16_t
46+
>
47+
{};
48+
49+
template <class Tag>
50+
struct status_visitor : boost::static_visitor<> {
51+
basic_response<Tag> const & response;
52+
status_visitor(basic_response<Tag> const & response)
53+
: response(response) {}
54+
55+
void operator()(typename value<Tag>::type const & status_) const {
56+
response.status(status_);
7057
}
7158

59+
template <class T>
60+
void operator()(T const &) const {
61+
// FIXME fail here!
62+
}
7263
};
7364

74-
} // namespace impl
65+
template <class Tag> basic_response<Tag> const & operator() (basic_response<Tag> const & response) const {
66+
apply_visitor(status_visitor<Tag>(response), status_);
67+
return response;
68+
}
69+
70+
};
7571

7672
template <class T>
77-
inline impl::status_directive const status(T const & status_) {
78-
return impl::status_directive(status_);
73+
inline status_directive const status(T const & status_) {
74+
return status_directive(status_);
7975
}
8076

8177
} // namespace http

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace boost { namespace network {
1414
namespace impl {
1515

1616
template <class Message, class KeyType, class ValueType, class Async>
17-
inline void add_header(Message const & message, KeyType const & key, ValueType const & value, http::tags::http_server const &, Async const &) {
17+
inline void add_header(Message const & message, KeyType const & key, ValueType const & value, http::tags::server const &, Async const &) {
1818
typedef typename Message::headers_container_type::value_type value_type;
1919
value_type header_ = { key, value };
2020
message.headers.insert(message.headers.end(), header_);

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

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIERS_MAJOR_VERSION_HPP_20101120
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIERS_MAJOR_VERSION_HPP_20101120
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/protocol/http/support/is_server.hpp>
10+
#include <boost/utility/enable_if.hpp>
11+
#include <boost/cstdint.hpp>
12+
13+
namespace boost { namespace network { namespace http {
14+
15+
template <class Tag>
16+
struct basic_request;
17+
18+
template <class Tag>
19+
inline typename enable_if<is_server<Tag>, void>::type
20+
major_version(basic_request<Tag> & request, boost::uint8_t major_version_) {
21+
request.http_version_major = major_version_;
22+
}
23+
24+
} /* http */
25+
26+
} /* network */
27+
28+
} /* boost */
29+
30+
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIERS_MAJOR_VERSION_HPP_20101120 */

0 commit comments

Comments
 (0)