Skip to content

Commit 76afcf4

Browse files
committed
Moving Server-Specific Parsers to Static Lib
In line with the changes introduced to move the Boost.Spirit requiring code out to static libraries, the parsers used by the HTTP server implementation particularly the parsing of headers and the version have been moved out into a static library. This requires that all servers be linked against the static lib going forward.
1 parent 72d6d02 commit 76afcf4

File tree

15 files changed

+173
-84
lines changed

15 files changed

+173
-84
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ namespace boost { namespace network {
2929
/** Specialize the traits for the http_server tag. */
3030
template <>
3131
struct headers_container<http::tags::http_server> :
32-
vector<http::tags::http_server>::apply<http::request_header<http::tags::http_server> >
32+
vector<http::tags::http_server>::apply<typename http::request_header<http::tags::http_server>::type>
3333
{};
3434

3535
template <>
3636
struct headers_container<http::tags::http_async_server> :
37-
vector<http::tags::http_async_server>::apply<http::request_header<http::tags::http_async_server> >
37+
vector<http::tags::http_async_server>::apply<typename http::request_header<http::tags::http_async_server>::type>
3838
{};
3939

4040
namespace http {
@@ -136,7 +136,7 @@ namespace http {
136136
struct not_quite_pod_request_base {
137137
typedef Tag tag;
138138
typedef typename string<Tag>::type string_type;
139-
typedef request_header<Tag> header_type;
139+
typedef typename request_header<Tag>::type header_type;
140140
typedef typename vector<Tag>::
141141
template apply<header_type>::type
142142
vector_type;

boost/network/protocol/http/impl/request_parser.ipp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ boost::tribool basic_request_parser<Tag>::consume(basic_request<Tag> & req, char
207207
}
208208
else
209209
{
210-
req.headers.push_back(request_header<Tag>());
210+
req.headers.push_back(typename request_header<Tag>::type());
211211
req.headers.back().name.push_back(input);
212212
state_ = header_name;
213213
return boost::indeterminate;

boost/network/protocol/http/impl/response.ipp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace boost { namespace network { namespace http {
5151
} status;
5252

5353
/// The headers to be included in the reply.
54-
typedef vector<tags::http_server>::apply<request_header<tags::http_server> >::type headers_vector;
54+
typedef vector<tags::http_server>::apply<typename request_header<tags::http_server>::type>::type headers_vector;
5555
headers_vector headers;
5656

5757
/// The content to be sent in the reply.
@@ -69,7 +69,7 @@ namespace boost { namespace network { namespace http {
6969
std::vector<const_buffer> buffers;
7070
buffers.push_back(to_buffer(status));
7171
for (std::size_t i = 0; i < headers.size(); ++i) {
72-
request_header<tags::http_server> & h = headers[i];
72+
typename request_header<tags::http_server>::type & h = headers[i];
7373
buffers.push_back(buffer(h.name));
7474
buffers.push_back(buffer(name_value_separator));
7575
buffers.push_back(buffer(h.value));

boost/network/protocol/http/message/header.hpp

Lines changed: 76 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,110 @@
1414
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_HEADER_HPP_20101122
1515

1616
#include <boost/network/traits/string.hpp>
17-
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
1817
#include <boost/fusion/include/adapt_struct.hpp>
1918
#include <boost/assign/list_of.hpp>
19+
#include <boost/network/support/is_default_wstring.hpp>
20+
#include <boost/network/support/is_default_wstring.hpp>
2021

2122
namespace boost { namespace network { namespace http {
2223

2324
template <class Tag>
24-
struct request_header
25-
{
26-
typedef Tag tag;
27-
typedef typename string<Tag>::type string_type;
28-
string_type name, value;
25+
struct unsupported_tag;
26+
27+
struct request_header_narrow {
28+
typedef std::string string_type;
29+
std::string name, value;
30+
};
31+
32+
struct request_header_wide {
33+
typedef std::wstring string_type;
34+
std::wstring name, value;
2935
};
3036

3137
template <class Tag>
32-
inline void swap(request_header<Tag> & l, request_header<Tag> & r) {
38+
struct request_header
39+
: mpl::if_<
40+
is_default_string<Tag>,
41+
request_header_narrow,
42+
typename mpl::if_<
43+
is_default_wstring<Tag>,
44+
request_header_wide,
45+
unsupported_tag<Tag>
46+
>::type
47+
>
48+
{};
49+
50+
inline void swap(request_header_narrow & l, request_header_narrow & r) {
3351
swap(l.name, r.name);
3452
swap(l.value, r.value);
3553
}
3654

37-
template <class Tag>
38-
struct response_header {
39-
typedef Tag tag;
40-
typedef typename string<Tag>::type string_type;
41-
string_type name, value;
55+
inline void swap(request_header_wide & l, request_header_wide & r) {
56+
swap(l.name, r.name);
57+
swap(l.value, r.value);
58+
}
59+
60+
struct response_header_narrow {
61+
typedef std::string string_type;
62+
std::string name, value;
63+
};
64+
65+
struct response_header_wide {
66+
typedef std::wstring string_type;
67+
std::wstring name, value;
4268
};
4369

4470
template <class Tag>
45-
void swap(response_header<Tag> & l, response_header<Tag> & r) {
71+
struct response_header
72+
: mpl::if_<
73+
is_default_string<Tag>,
74+
response_header_narrow,
75+
typename mpl::if_<
76+
is_default_wstring<Tag>,
77+
response_header_wide,
78+
unsupported_tag<Tag>
79+
>::type
80+
>
81+
{};
82+
83+
inline void swap(response_header_narrow & l, response_header_narrow & r) {
4684
std::swap(l.name, r.name);
4785
std::swap(l.value, r.value);
4886
}
4987

88+
inline void swap(response_header_wide & l, response_header_wide & r) {
89+
std::swap(l.name, r.name);
90+
std::swap(l.value, r.value);
91+
}
92+
5093
} // namespace http
5194

5295
} // namespace network
5396

5497
} // namespace boost
5598

56-
BOOST_FUSION_ADAPT_TPL_STRUCT(
57-
(Tag),
58-
(boost::network::http::request_header)(Tag),
59-
(typename boost::network::string<Tag>::type, name)
60-
(typename boost::network::string<Tag>::type, value)
99+
BOOST_FUSION_ADAPT_STRUCT(
100+
boost::network::http::request_header_narrow,
101+
(std::string, name)
102+
(std::string, value)
103+
)
104+
105+
BOOST_FUSION_ADAPT_STRUCT(
106+
boost::network::http::request_header_wide,
107+
(std::wstring, name)
108+
(std::wstring, value)
109+
)
110+
111+
BOOST_FUSION_ADAPT_STRUCT(
112+
boost::network::http::response_header_narrow,
113+
(std::string, name)
114+
(std::string, value)
61115
)
62116

63-
BOOST_FUSION_ADAPT_TPL_STRUCT(
64-
(Tag),
65-
(boost::network::http::response_header) (Tag),
66-
(typename boost::network::string<Tag>::type, name)
67-
(typename boost::network::string<Tag>::type, value)
117+
BOOST_FUSION_ADAPT_STRUCT(
118+
boost::network::http::response_header_wide,
119+
(std::wstring, name)
120+
(std::wstring, value)
68121
)
69122

70123
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_HEADER_HPP_20101122

boost/network/protocol/http/message/header/name.hpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,38 @@
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
88

9+
#include <boost/network/protocol/http/message/header.hpp>
910
#include <utility>
1011

1112
namespace boost { namespace network { namespace http {
1213

13-
template <class Tag>
14-
struct response_header;
15-
16-
template <class Tag>
17-
struct request_header;
18-
1914
template <class T1, class T2>
2015
T1 &
2116
name(std::pair<T1,T2> const & p) {
2217
return p.first;
2318
}
2419

25-
template <class Tag>
26-
typename string<Tag>::type const &
27-
name(response_header<Tag> const & h) {
20+
inline std::string const &
21+
name(request_header_narrow const & h) {
2822
return h.name;
2923
}
3024

31-
template <class Tag>
32-
typename string<Tag>::type const &
33-
name(request_header<Tag> const & h) {
25+
inline std::wstring const &
26+
name(request_header_wide const &h) {
3427
return h.name;
3528
}
29+
3630

31+
inline std::string const &
32+
name(response_header_narrow const & h) {
33+
return h.name;
34+
}
35+
36+
inline std::wstring const &
37+
name(response_header_wide const &h) {
38+
return h.name;
39+
}
40+
3741
} /* http */
3842

3943
} /* network */

boost/network/protocol/http/message/header/value.hpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,33 @@
1010

1111
namespace boost { namespace network { namespace http {
1212

13-
template <class Tag>
14-
struct response_header;
15-
16-
template <class Tag>
17-
struct request_header;
13+
struct request_header_narrow;
14+
struct request_header_wide;
15+
struct response_header_narrow;
16+
struct response_header_wide;
1817

1918
template <class T1, class T2>
2019
T1 & value(std::pair<T1,T2> const & p) {
2120
return p.second;
2221
}
2322

24-
template <class Tag>
25-
typename string<Tag>::type const &
26-
value(response_header<Tag> const & h) {
23+
inline request_header_narrow::string_type const &
24+
value(request_header_narrow const & h) {
25+
return h.value;
26+
}
27+
28+
inline request_header_wide::string_type const &
29+
value(request_header_wide const & h) {
30+
return h.value;
31+
}
32+
33+
inline response_header_narrow::string_type const &
34+
value(response_header_narrow const & h) {
2735
return h.value;
2836
}
2937

30-
template <class Tag>
31-
typename string<Tag>::type const &
32-
value(request_header<Tag> const & h) {
38+
inline response_header_wide::string_type const &
39+
value(response_header_wide const & h) {
3340
return h.value;
3441
}
3542

boost/network/protocol/http/message/header_concept.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ namespace boost { namespace network { namespace http {
1616
, Assignable<H>
1717
, CopyConstructible<H>
1818
{
19-
typedef typename H::tag tag;
2019

2120
BOOST_CONCEPT_USAGE(Header) {
22-
typedef typename string<tag>::type string_type;
21+
typedef typename H::string_type string_type;
2322
string_type name_ = name(header);
2423
string_type value_ = value(header);
2524
H h1, h2;

boost/network/protocol/http/server/async_connection.hpp

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <boost/make_shared.hpp>
2121
#include <boost/network/protocol/http/server/request_parser.hpp>
2222
#include <boost/range/iterator_range.hpp>
23-
#include <boost/spirit/include/qi.hpp>
2423
#include <boost/optional.hpp>
2524
#include <boost/utility/typed_in_place_factory.hpp>
2625
#include <boost/thread/locks.hpp>
@@ -42,6 +41,9 @@
4241

4342
namespace boost { namespace network { namespace http {
4443

44+
extern void parse_version(std::string const & partial_parsed, fusion::tuple<uint8_t,uint8_t> & version_pair);
45+
extern void parse_headers(std::string const & input, std::vector<request_header_narrow> & container);
46+
4547
template <class Tag, class Handler>
4648
struct async_connection : boost::enable_shared_from_this<async_connection<Tag,Handler> > {
4749

@@ -374,17 +376,8 @@ namespace boost { namespace network { namespace http {
374376
break;
375377
} else if (parsed_ok == true) {
376378
fusion::tuple<uint8_t, uint8_t> version_pair;
377-
using namespace boost::spirit::qi;
378379
partial_parsed.append(boost::begin(result_range), boost::end(result_range));
379-
parse(
380-
partial_parsed.begin(), partial_parsed.end(),
381-
(
382-
lit("HTTP/")
383-
>> ushort_
384-
>> '.'
385-
>> ushort_
386-
)
387-
, version_pair);
380+
parse_version(partial_parsed, version_pair);
388381
request_.http_version_major = fusion::get<0>(version_pair);
389382
request_.http_version_minor = fusion::get<1>(version_pair);
390383
new_start = boost::end(result_range);
@@ -472,20 +465,6 @@ namespace boost { namespace network { namespace http {
472465
}
473466
}
474467

475-
void parse_headers(string_type & input, typename request::headers_container_type & container) {
476-
using namespace boost::spirit::qi;
477-
parse(
478-
input.begin(), input.end(),
479-
*(
480-
+(alnum|(punct-':'))
481-
>> lit(": ")
482-
>> +(alnum|space|punct)
483-
>> lit("\r\n")
484-
)
485-
, container
486-
);
487-
}
488-
489468
void do_nothing() {}
490469

491470
template <class Range>

boost/network/protocol/http/server/async_server.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace boost { namespace network { namespace http {
1616
typedef basic_request<Tag> request;
1717
typedef basic_response<Tag> response;
1818
typedef typename string<Tag>::type string_type;
19-
typedef boost::network::http::response_header<Tag> response_header;
19+
typedef typename boost::network::http::response_header<Tag>::type response_header;
2020
typedef async_connection<Tag,Handler> connection;
2121
typedef shared_ptr<connection> connection_ptr;
2222

boost/network/protocol/http/server/sync_connection.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ namespace boost { namespace network { namespace http {
8585
if (done) {
8686
if (request_.method[0] == 'P') {
8787
// look for the content-length header
88-
typename std::vector<request_header<Tag> >::iterator it =
88+
typename std::vector<typename request_header<Tag>::type >::iterator it =
8989
std::find_if(
9090
request_.headers.begin(),
9191
request_.headers.end(),

0 commit comments

Comments
 (0)