Skip to content

Commit 1823d93

Browse files
committed
Adding the HTTP Response concept, along with required wrappers and directives to make http::basic_response<> model the new concept.
1 parent 6072032 commit 1823d93

File tree

8 files changed

+383
-10
lines changed

8 files changed

+383
-10
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_STATUS_HPP_20100603
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_STATUS_HPP_20100603
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/tags.hpp>
11+
#include <boost/cstdint.hpp>
12+
13+
namespace boost { namespace network { namespace http {
14+
15+
template <class Tag>
16+
struct basic_response;
17+
18+
template <class Tag>
19+
struct status_directive {
20+
21+
typedef typename string<Tag>::type string_type;
22+
23+
mutable boost::uint16_t status_;
24+
25+
status_directive(boost::uint16_t status)
26+
: status_(status) {}
27+
28+
status_directive(status_directive const & other)
29+
: status_(other.status_) {}
30+
31+
template <class T> basic_response<T> const & operator() (basic_response<T> const & response) const {
32+
response.status() = status_;
33+
return response;
34+
}
35+
36+
};
37+
38+
inline status_directive<tags::default_> const status(boost::uint16_t status_) {
39+
return status_directive<tags::default_>(status_);
40+
}
41+
42+
} // namespace http
43+
44+
} // namespace network
45+
46+
} // namespace boost
47+
48+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_STATUS_HPP_20100603
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_STATUS_MESSAGE_HPP_20100603
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_STATUS_MESSAGE_HPP_20100603
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/tags.hpp>
11+
12+
namespace boost { namespace network { namespace http {
13+
14+
template <class Tag>
15+
struct basic_response;
16+
17+
template <class Tag>
18+
struct status_message_directive {
19+
20+
typedef typename string<Tag>::type string_type;
21+
22+
mutable string_type status_message_;
23+
24+
status_message_directive(string_type const & status_message)
25+
: status_message_(status_message) {}
26+
27+
status_message_directive(status_message_directive const & other)
28+
: status_message(other.status_message_) {}
29+
30+
template <class T> basic_response<T> const & operator() (basic_response<T> const & response) const {
31+
response.status_message() = status_message_;
32+
return response;
33+
}
34+
35+
};
36+
37+
inline status_message_directive<tags::default_> const status_message(string<tags::default_>::type const & status_message_) {
38+
return status_message_directive<tags::default_>(status_message_);
39+
}
40+
41+
} // namespace http
42+
43+
} // namespace network
44+
45+
} // namespace boost
46+
47+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_STATUS_MESSAGE_HPP_20100603
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_VERSION_HPP_20100603
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_VERSION_HPP_20100603
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/tags.hpp>
11+
12+
namespace boost { namespace network { namespace http {
13+
14+
template <class Tag>
15+
struct basic_response;
16+
17+
template <class Tag>
18+
struct version_directive {
19+
20+
typedef typename string<Tag>::type string_type;
21+
22+
mutable string_type version_;
23+
24+
version_directive(string_type const & version)
25+
: version_(version) {}
26+
27+
version_directive(version_directive const & other)
28+
: version_(other.version_) {}
29+
30+
template <class T> basic_response<T> const & operator() (basic_response<T> const & response) const {
31+
response.version() = version_;
32+
return response;
33+
}
34+
35+
};
36+
37+
inline version_directive<tags::default_> const version(string<tags::default_>::type const & version_) {
38+
return version_directive<tags::default_>(version_);
39+
}
40+
41+
} // namespace http
42+
43+
} // namespace network
44+
45+
} // namespace boost
46+
47+
48+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_VERSION_HPP_20100603
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_STATUS_HPP_20100603
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_STATUS_HPP_20100603
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/cstdint.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>
20+
struct status_wrapper {
21+
22+
basic_response<Tag> const & response_;
23+
24+
explicit status_wrapper(basic_response<Tag> const & response)
25+
: response_(response) {}
26+
27+
status_wrapper(status_wrapper const & other)
28+
: response_(other.response_) {}
29+
30+
operator boost::uint16_t () {
31+
return response_.status();
32+
}
33+
34+
};
35+
36+
} // namespace impl
37+
38+
template <class Tag>
39+
inline impl::status_wrapper<Tag> status(basic_response<Tag> const & response) {
40+
return impl::status_wrapper<Tag>(response);
41+
}
42+
43+
} // namespace http
44+
45+
} // namespace network
46+
47+
} // namespace boost
48+
49+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_STATUS_HPP_20100603
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_STATUS_MESSAGE_HPP_20100603
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_STATUS_MESSAGE_HPP_20100603
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+
namespace boost { namespace network { namespace http {
11+
12+
template <class Tag>
13+
struct basic_response;
14+
15+
namespace impl {
16+
17+
template <class Tag>
18+
struct status_message_wrapper {
19+
20+
typedef typename string<Tag>::type string_type;
21+
22+
basic_response<Tag> const & response_;
23+
24+
explicit status_message_wrapper(basic_response<Tag> const & response)
25+
: response_(response) {}
26+
27+
status_message_wrapper(status_message_wrapper const & other)
28+
: response_(other.response_) {}
29+
30+
operator string_type () {
31+
return response_.status_message();
32+
}
33+
34+
};
35+
36+
} // namespace impl
37+
38+
template <class Tag>
39+
inline impl::status_message_wrapper<Tag> status_message(basic_response<Tag> const & response) {
40+
return impl::status_message_wrapper<Tag>(response);
41+
}
42+
43+
} // namespace http
44+
45+
} // namespace network
46+
47+
} // namespace boost
48+
49+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPER_STATUS_MESSAGE_HPP_20100603
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_VERSION_HPP_20100603
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_VERSION_HPP_20100603
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/tags.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>
20+
struct version_wrapper {
21+
22+
typedef typename string<Tag>::type string_type;
23+
24+
basic_response<Tag> const & response_;
25+
26+
explicit version_wrapper(basic_response<Tag> const & response)
27+
: response_(response) {}
28+
29+
version_wrapper(version_wrapper const & other)
30+
: response_(other.response_) {}
31+
32+
operator string_type () {
33+
return response_.version();
34+
}
35+
36+
};
37+
38+
} // namespace impl
39+
40+
template <class Tag>
41+
inline impl::version_wrapper<Tag> version(basic_response<Tag> const & response) {
42+
return impl::version_wrapper<Tag>(response);
43+
}
44+
45+
} // namespace http
46+
47+
} // namespace network
48+
49+
} // namespace boost
50+
51+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_VERSION_HPP_20100603

boost/network/protocol/http/response.hpp

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@
1010
#include <boost/network/protocol/http/message.hpp>
1111
#include <boost/network/message.hpp>
1212

13+
#include <boost/cstdint.hpp>
14+
#include <boost/network/protocol/http/response_concept.hpp>
15+
1316
namespace boost { namespace network { namespace http {
1417

1518
template <class Tag>
1619
struct basic_response : public message_impl<Tag> {
1720
private:
1821
typedef message_impl<Tag> base_type;
19-
typedef typename string<Tag>::type string_type;
2022

21-
string_type version_;
22-
unsigned int status_;
23-
string_type status_message_;
23+
mutable string_type version_;
24+
mutable boost::uint16_t status_;
25+
mutable string_type status_message_;
2426
public:
2527

2628
typedef Tag tag;
29+
typedef typename string<Tag>::type string_type;
2730

2831
basic_response()
2932
: base_type(), version_(), status_(0u), status_message_()
@@ -33,15 +36,15 @@ namespace boost { namespace network { namespace http {
3336
: base_type(other), version_(other.version_), status_(other.status_), status_message_(other.status_message_)
3437
{ };
3538

36-
string_type & version() {
39+
string_type & version() const {
3740
return version_;
3841
};
3942

40-
unsigned int & status() {
43+
boost::uint16_t & status() const {
4144
return status_;
4245
};
4346

44-
string_type & status_message() {
47+
string_type & status_message() const {
4548
return status_message_;
4649
};
4750

@@ -61,9 +64,11 @@ namespace boost { namespace network { namespace http {
6164
};
6265

6366
template <class Tag>
64-
inline void swap(basic_response<Tag> & lhs, basic_response<Tag> & rhs) {
65-
lhs.swap(rhs);
66-
}
67+
inline void swap(basic_response<Tag> & lhs, basic_response<Tag> & rhs) {
68+
lhs.swap(rhs);
69+
}
70+
71+
BOOST_CONCEPT_ASSERT((Response<basic_response<tags::http_default_8bit_udp_resolve> >));
6772

6873
} // namespace http
6974

@@ -73,4 +78,30 @@ namespace boost { namespace network { namespace http {
7378

7479
#include <boost/network/protocol/http/impl/response.ipp>
7580

81+
namespace boost { namespace network { namespace http {
82+
83+
template <class Tag, class Directive>
84+
basic_response<Tag> & operator<<(
85+
basic_response<Tag> & message,
86+
Directive const & directive
87+
)
88+
{
89+
directive(message);
90+
return message;
91+
}
92+
93+
} // namespace http
94+
95+
} // namespace network
96+
97+
} // namespace boost
98+
99+
#include <boost/network/protocol/http/message/directives/status_message.hpp>
100+
#include <boost/network/protocol/http/message/directives/version.hpp>
101+
#include <boost/network/protocol/http/message/directives/status.hpp>
102+
103+
#include <boost/network/protocol/http/message/wrappers/version.hpp>
104+
#include <boost/network/protocol/http/message/wrappers/status.hpp>
105+
#include <boost/network/protocol/http/message/wrappers/status_message.hpp>
106+
76107
#endif // BOOST_NETWORK_PROTOCOL_HTTP_RESPONSE_HPP

0 commit comments

Comments
 (0)