Skip to content

Commit 534f964

Browse files
committed
Implementing the request concept check along with the supported directives, wrappers, and modifiers.
1 parent 01aa60e commit 534f964

File tree

13 files changed

+496
-21
lines changed

13 files changed

+496
-21
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
// Copyright Dean Michael Berris 2007,2009.
2+
// Copyright Dean Michael Berris 2007,2009,2010.
33
// Copyright Michael Dickey 2008.
44
// Distributed under the Boost Software License, Version 1.0.
55
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -18,6 +18,8 @@
1818
#include <boost/network/protocol/http/header.hpp>
1919
#include <boost/network/traits/vector.hpp>
2020

21+
#include <boost/cstdint.hpp>
22+
2123
namespace boost { namespace network { namespace http {
2224

2325
/** request.hpp
@@ -31,11 +33,12 @@ namespace boost { namespace network { namespace http {
3133
class basic_request : public basic_message<Tag>
3234
{
3335

34-
boost::network::uri::http::uri uri_;
36+
mutable boost::network::uri::http::uri uri_;
3537

3638
public:
3739
typedef Tag tag;
3840
typedef typename string<Tag>::type string_type;
41+
typedef boost::uint16_t port_type;
3942

4043
explicit basic_request(string_type const & uri_)
4144
: uri_(uri_)
@@ -70,7 +73,7 @@ namespace boost { namespace network { namespace http {
7073
return uri_.host();
7174
}
7275

73-
unsigned int port() const {
76+
port_type port() const {
7477
return uri_.port();
7578
}
7679

@@ -90,6 +93,10 @@ namespace boost { namespace network { namespace http {
9093
return uri_.scheme();
9194
}
9295

96+
void uri(string_type const & new_uri) const {
97+
uri_ = new_uri;
98+
}
99+
93100
};
94101

95102
/** This is the implementation of a POD request type
@@ -104,6 +111,7 @@ namespace boost { namespace network { namespace http {
104111
typedef tags::http_server tag;
105112
typedef string<tags::http_server>::type string_type;
106113
typedef vector<tags::http_server>::apply<request_header>::type vector_type;
114+
typedef boost::uint16_t port_type;
107115
string_type method;
108116
string_type uri;
109117
boost::uint8_t http_version_major;
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_URI_HPP_20100620
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_URI_HPP_20100620
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+
class basic_request;
16+
17+
template <class Tag>
18+
struct uri_directive {
19+
20+
typedef typename string<Tag>::type string_type;
21+
22+
mutable string_type uri_;
23+
24+
uri_directive(string_type const & uri)
25+
: uri_(uri) {}
26+
27+
uri_directive(uri_directive const & other)
28+
: uri(other.uri_) {}
29+
30+
template <class T> basic_request<T> const & operator() (basic_request<T> const & request) const {
31+
request.uri(uri_);
32+
return request;
33+
}
34+
35+
};
36+
37+
inline uri_directive<tags::default_> const uri(string<tags::default_>::type const & uri_) {
38+
return uri_directive<tags::default_>(uri_);
39+
}
40+
41+
} // namespace http
42+
43+
} // namespace network
44+
45+
} // namespace boost
46+
47+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DIRECTIVES_URI_HPP_20100620
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_URI_HPP_20100621
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIERS_URI_HPP_20100621
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+
class basic_request;
17+
18+
namespace impl {
19+
20+
template <class Tag, class T>
21+
void uri(basic_request<Tag> & response, T const & value, mpl::false_ const &) {
22+
response << boost::network::http::uri(value);
23+
}
24+
25+
template <class Tag, class T>
26+
void uri(basic_request<Tag> & response, boost::shared_future<T> future, mpl::true_ const &) {
27+
response.uri() = future;
28+
}
29+
30+
} // namespace impl
31+
32+
template <class Tag, class T>
33+
void uri(basic_request<Tag> & response, T const & value) {
34+
impl::uri(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_URI_HPP_20100621
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_ANCHOR_HPP_20100618
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_ANCHOR_HPP_20100618
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/protocol/http/request_concept.hpp>
11+
#include <boost/concept/requires.hpp>
12+
13+
namespace boost { namespace network { namespace http {
14+
15+
template <class Tag>
16+
class basic_request;
17+
18+
namespace impl {
19+
template <class Tag>
20+
struct anchor_wrapper {
21+
basic_request<Tag> const & message_;
22+
anchor_wrapper(basic_request<Tag> const & message)
23+
: message_(message) {}
24+
typedef typename basic_request<Tag>::string_type string_type;
25+
operator string_type() {
26+
return message_.anchor();
27+
}
28+
};
29+
}
30+
31+
template <class Tag> inline
32+
BOOST_CONCEPT_REQUIRES(((Request<basic_request<Tag> >)),
33+
(impl::anchor_wrapper<Tag>))
34+
anchor(basic_request<Tag> const & request) {
35+
return impl::anchor_wrapper<Tag>(request);
36+
}
37+
38+
} // namespace http
39+
40+
} // namespace network
41+
42+
} // nmaespace boost
43+
44+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_ANCHOR_HPP_20100618
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_HOST_HPP_20100618
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_HOST_HPP_20100618
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/protocol/http/request_concept.hpp>
11+
#include <boost/concept/requires.hpp>
12+
13+
namespace boost { namespace network { namespace http {
14+
15+
template <class Tag>
16+
class basic_request;
17+
18+
namespace impl {
19+
20+
template <class Tag>
21+
struct host_wrapper {
22+
basic_request<Tag> const & message_;
23+
24+
host_wrapper(basic_request<Tag> const & message)
25+
: message_(message) {}
26+
27+
typedef typename basic_request<Tag>::string_type string_type;
28+
29+
operator string_type() {
30+
return message_.host();
31+
}
32+
};
33+
34+
}
35+
36+
template <class Tag>
37+
inline
38+
BOOST_CONCEPT_REQUIRES(((Request<basic_request<Tag> >)),
39+
(impl::host_wrapper<Tag>))
40+
host(basic_request<Tag> const & request) {
41+
return impl::host_wrapper<Tag>(request);
42+
}
43+
44+
} // namespace http
45+
46+
} // namespace network
47+
48+
} // namespace boost
49+
50+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_HOST_HPP_20100618
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_PATH_HPP_20100618
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_PATH_HPP_20100618
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/protocol/http/request_concept.hpp>
11+
#include <boost/concept/requires.hpp>
12+
13+
namespace boost { namespace network { namespace http {
14+
15+
template <class Tag>
16+
class basic_request;
17+
18+
namespace impl {
19+
20+
template <class Tag>
21+
struct path_wrapper {
22+
basic_request<Tag> const & message_;
23+
24+
path_wrapper(basic_request<Tag> const & message)
25+
: message_(message) {}
26+
27+
typedef typename basic_request<Tag>::string_type string_type;
28+
29+
operator string_type() {
30+
return message_.path();
31+
}
32+
};
33+
34+
}
35+
36+
template <class Tag>
37+
inline
38+
BOOST_CONCEPT_REQUIRES(((Request<basic_request<Tag> >)),
39+
(impl::path_wrapper<Tag>))
40+
path(basic_request<Tag> const & request) {
41+
return impl::path_wrapper<Tag>(request);
42+
}
43+
44+
} // namespace http
45+
46+
} // namespace network
47+
48+
} // namespace boost
49+
50+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_PATH_HPP_20100618
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_PORT_HPP_20100618
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_PORT_HPP_20100618
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/protocol/http/request_concept.hpp>
11+
#include <boost/concept/requires.hpp>
12+
13+
namespace boost { namespace network { namespace http {
14+
15+
template <class Tag>
16+
class basic_request;
17+
18+
namespace impl {
19+
20+
template <class Tag>
21+
struct port_wrapper {
22+
basic_request<Tag> const & message_;
23+
24+
port_wrapper(basic_request<Tag> const & message)
25+
: message_(message) {}
26+
27+
typedef typename basic_request<Tag>::port_type port_type;
28+
29+
operator port_type() {
30+
return message_.port();
31+
}
32+
};
33+
34+
} // namespace impl
35+
36+
template <class Tag>
37+
inline
38+
BOOST_CONCEPT_REQUIRES(((Request<basic_request<Tag> >)),
39+
(impl::port_wrapper<Tag>))
40+
port(basic_request<Tag> const & request) {
41+
return impl::port_wrapper<Tag>(request);
42+
}
43+
44+
} // namespace http
45+
46+
} // namespace network
47+
48+
} // namespace boost
49+
50+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_PORT_HPP_20100618
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_PROTOCOL_HPP_20100619
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_PROTOCOL_HPP_20100619
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/protocol/http/request_concept.hpp>
11+
#include <boost/concept/requires.hpp>
12+
13+
namespace boost { namespace network { namespace http {
14+
15+
template <class Tag>
16+
class basic_request;
17+
18+
namespace impl {
19+
template <class Tag>
20+
struct protocol_wrapper {
21+
basic_request<Tag> const & message_;
22+
protocol_wrapper(basic_request<Tag> const & message)
23+
: message_(message) {}
24+
typedef typename basic_request<Tag>::string_type string_type;
25+
operator string_type() {
26+
return message_.protocol();
27+
}
28+
};
29+
}
30+
31+
template <class Tag> inline
32+
BOOST_CONCEPT_REQUIRES(((Request<basic_request<Tag> >)),
33+
(impl::protocol_wrapper<Tag>))
34+
protocol(basic_request<Tag> const & request) {
35+
return impl::protocol_wrapper<Tag>(request);
36+
}
37+
38+
} // namespace http
39+
40+
} // namespace network
41+
42+
} // namespace boost
43+
44+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_WRAPPERS_PROTOCOL_HPP_20100619

0 commit comments

Comments
 (0)