Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite962f2e

Browse files
committed
Updated URI tests.
2 parents3d25ece +3bad001 commite962f2e

37 files changed

+1282
-402
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ build
99
_build
1010
bin
1111
*.gch
12+
libs/mime/test/mime-roundtrip
1213

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_ALGORITHMS_LINEARIZE_HPP_20101028
2+
#defineBOOST_NETWORK_PROTOCOL_HTTP_ALGORITHMS_LINEARIZE_HPP_20101028
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/server/header/name.hpp>
10+
#include<boost/network/protocol/http/server/header/value.hpp>
11+
#include<boost/network/protocol/http/server/header/concept.hpp>
12+
#include<boost/network/constants.hpp>
13+
#include<boost/concept_check.hpp>
14+
15+
namespaceboost {namespacenetwork {namespacehttp {
16+
17+
template<classTag,classValueType>
18+
structlinearize {
19+
typedeftypename string<Tag>::type string_type;
20+
21+
template<classArguments>
22+
structresult {
23+
typedef string_type type;
24+
};
25+
26+
BOOST_CONCEPT_REQUIRES(
27+
(Header<ValueType),
28+
(string_type)
29+
)operator()(ValueType & header) {
30+
typedeftypename ostringstream<Tag>::type output_stream;
31+
typedef constants<Tag> consts;
32+
output_stream header_line;
33+
header_line <<name(header)
34+
<<consts::colon() <<consts::space()
35+
<<value(header) <<consts::crlf();
36+
return header_line.str();
37+
}
38+
};
39+
40+
}/* linearize*/
41+
42+
}/* net*/
43+
44+
}/* boost*/
45+
46+
#endif/* BOOST_NETWORK_PROTOCOL_HTTP_ALGORITHMS_LINEARIZE_HPP_20101028*/

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// ~~~~~~~~~~
44
//
55
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6-
// Copyright (c) 2009 Dean Michael Berris (mikhailberis@gmail.com)
6+
// Copyright (c) 2009,2010 Dean Michael Berris (mikhailberis@gmail.com)
77
// Copyright (c) 2009 Tarroo, Inc.
88
//
99
// Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -13,20 +13,23 @@
1313
#ifndef HTTP_SERVER3_HEADER_HPP
1414
#defineHTTP_SERVER3_HEADER_HPP
1515

16-
#include<string>
16+
#include<boost/network/traits/string.hpp>
1717

1818
namespaceboost {namespacenetwork {namespacehttp {
1919

20-
structrequest_header
21-
{
22-
std::string name;
23-
std::string value;
24-
};
25-
26-
inlinevoidswap(request_header & l, request_header & r) {
27-
swap(l.name, r.name);
28-
swap(l.value, r.value);
29-
}
20+
template<classTag>
21+
structrequest_header
22+
{
23+
typedeftypename string<Tag>::type string_type;
24+
string_type name;
25+
std::string value;
26+
};
27+
28+
template<classTag>
29+
inlinevoidswap(request_header<Tag> & l, request_header<Tag> & r) {
30+
swap(l.name, r.name);
31+
swap(l.value, r.value);
32+
}
3033

3134
}// namespace http
3235

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

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,22 @@ namespace boost { namespace network { namespace http {
4343
public:
4444
typedeftypename sync_only<Tag>::type tag;
4545
typedeftypename string<tag>::type string_type;
46-
typedef boost::uint16_t port_type;
46+
// typedef boost::uint16_t port_type;
47+
typedef string_type port_type;
4748

4849
explicitbasic_request(string_typeconst & uri_)
49-
: uri_(uri_)
50+
: uri_(uri_)
5051
{ }
5152

5253
voiduri(string_typeconst & new_uri) {
5354
uri_ = new_uri;
5455
}
5556

56-
basic_request()
57+
basic_request()
5758
: base_type()
5859
{ }
5960

60-
basic_request(basic_requestconst & other)
61+
basic_request(basic_requestconst & other)
6162
: base_type(other), uri_(other.uri_)
6263
{ }
6364

@@ -79,6 +80,7 @@ namespace boost { namespace network { namespace http {
7980
}
8081

8182
port_typeport()const {
83+
// string_type port() const {
8284
return uri_.port();
8385
}
8486

@@ -115,11 +117,13 @@ namespace boost { namespace network { namespace http {
115117
* primarily and be solely a POD for performance
116118
* reasons.
117119
*/
118-
template<>
119-
structbasic_request<tags::http_server> {
120-
typedef tags::http_server tag;
121-
typedef string<tags::http_server>::type string_type;
122-
typedef vector<tags::http_server>::apply<request_header>::type vector_type;
120+
template<classTag>
121+
structpod_request_base {
122+
typedef Tag tag;
123+
typedeftypename string<Tag>::type string_type;
124+
typedeftypename vector<tags::http_server>::
125+
templateapply<request_header<Tag> >::type
126+
vector_type;
123127
typedef vector_type headers_container_type;
124128
typedef boost::uint16_t port_type;
125129
mutable string_type source;
@@ -130,7 +134,7 @@ namespace boost { namespace network { namespace http {
130134
mutable vector_type headers;
131135
mutable string_type body;
132136

133-
voidswap(basic_request & r)const {
137+
voidswap(pod_request_base & r)const {
134138
using std::swap;
135139
swap(method, r.method);
136140
swap(source, r.source);
@@ -142,6 +146,12 @@ namespace boost { namespace network { namespace http {
142146
}
143147
};
144148

149+
template<>
150+
structbasic_request<tags::http_async_server> : pod_request_base<tags::http_async_server> {};
151+
152+
template<>
153+
structbasic_request<tags::http_server> : pod_request_base<tags::http_server> {};
154+
145155
template<classTag>
146156
inlinevoidswap(basic_request<Tag> & lhs, basic_request<Tag> & rhs) {
147157
lhs.swap(rhs);
@@ -152,7 +162,12 @@ namespace boost { namespace network { namespace http {
152162
/** Specialize the traits for the http_server tag.*/
153163
template<>
154164
structheaders_container<http::tags::http_server> :
155-
vector<http::tags::http_server>::apply<http::request_header>
165+
vector<http::tags::http_server>::apply<http::request_header<http::tags::http_server> >
166+
{};
167+
168+
template<>
169+
structheaders_container<http::tags::http_async_server> :
170+
vector<http::tags::http_async_server>::apply<http::request_header<http::tags::http_async_server> >
156171
{};
157172

158173
namespacehttp {namespaceimpl {
@@ -179,6 +194,28 @@ namespace boost { namespace network { namespace http {
179194
}
180195
};
181196

197+
template<>
198+
structrequest_headers_wrapper<tags::http_async_server> {
199+
basic_request<tags::http_async_server>const & request_;
200+
request_headers_wrapper(basic_request<tags::http_async_server>const & request_)
201+
: request_(request_) {}
202+
typedef headers_container<tags::http_async_server>::type headers_container_type;
203+
operatorheaders_container_type () {
204+
return request_.headers;
205+
}
206+
};
207+
208+
template<>
209+
structbody_wrapper<basic_request<tags::http_async_server> > {
210+
typedef string<tags::http_async_server>::type string_type;
211+
basic_request<tags::http_async_server>const & request_;
212+
body_wrapper(basic_request<tags::http_async_server>const & request_)
213+
: request_(request_) {}
214+
operatorstring_type () {
215+
return request_.body;
216+
}
217+
};
218+
182219
}// namespace impl
183220

184221
}// namespace http

‎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());
210+
req.headers.push_back(request_header<Tag>());
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>::type headers_vector;
54+
typedef vector<tags::http_server>::apply<request_header<tags::http_server>>::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& h = headers[i];
72+
request_header<tags::http_server>& 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/server.hpp‎

Lines changed: 32 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,77 +5,38 @@
55
// Distributed under the Boost Software License, Version 1.0.
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
8-
//
98

109
#ifndef BOOST_NETWORK_HTTP_SERVER_HPP_
1110
#defineBOOST_NETWORK_HTTP_SERVER_HPP_
1211

13-
#include<boost/shared_ptr.hpp>
14-
#include<boost/bind.hpp>
15-
#include<boost/asio/ip/tcp.hpp>
1612
#include<boost/network/protocol/http/response.hpp>
1713
#include<boost/network/protocol/http/request.hpp>
18-
#include<boost/network/protocol/http/connection.hpp>
19-
#include<boost/network/traits/string.hpp>
14+
#include<boost/network/protocol/http/server/sync_server.hpp>
15+
#include<boost/network/protocol/http/server/async_server.hpp>
2016

2117
namespaceboost {namespacenetwork {namespacehttp {
2218

2319
template<classTag,classHandler>
24-
structbasic_server {
25-
typedeftypename string<Tag>::type string_type;
26-
typedef basic_request<Tag> request;
27-
typedef basic_response<Tag> response;
20+
structserver_base :
21+
mpl::if_<
22+
is_async<Tag>
23+
, async_server_base<Tag, Handler>
24+
,typename mpl::if_<
25+
is_sync<Tag>
26+
, sync_server_base<Tag, Handler>
27+
, unsupported_tag<Tag>
28+
>::type
29+
>
30+
{};
2831

29-
basic_server(string_typeconst & address,
30-
string_typeconst & port,
31-
Handler & handler)
32-
: handler_(handler)
33-
, service_()
34-
, acceptor_(service_)
35-
, new_connection(new connection<Tag,Handler>(service_, handler))
36-
{
37-
using boost::asio::ip::tcp;
38-
tcp::resolverresolver(service_);
39-
tcp::resolver::queryquery(address, port);
40-
tcp::endpoint endpoint = *resolver.resolve(query);
41-
acceptor_.open(endpoint.protocol());
42-
acceptor_.bind(endpoint);
43-
acceptor_.listen();
44-
acceptor_.async_accept(new_connection->socket(),
45-
boost::bind(&basic_server<Tag,Handler>::handle_accept,
46-
this, boost::asio::placeholders::error));
47-
}
48-
49-
voidrun() {
50-
service_.run();
51-
}
52-
53-
voidstop() {
54-
// TODO Graceful stop here?
55-
service_.stop();
56-
}
57-
58-
private:
59-
60-
Handler & handler_;
61-
boost::asio::io_service service_;
62-
boost::asio::ip::tcp::acceptor acceptor_;
63-
boost::shared_ptr<connection<Tag,Handler> > new_connection;
64-
65-
voidhandle_accept(boost::system::error_codeconst & ec) {
66-
if (!ec) {
67-
new_connection->start();
68-
new_connection.reset(new connection<Tag,Handler>(service_, handler_));
69-
acceptor_.async_accept(new_connection->socket(),
70-
boost::bind(&basic_server<Tag,Handler>::handle_accept,
71-
this, boost::asio::placeholders::error));
72-
}
73-
}
74-
};
32+
template<classTag,classHandler>
33+
structbasic_server : server_base<Tag, Handler>::type
34+
{};
7535

7636
template<classHandler>
77-
structserver : basic_server<tags::http_server, Handler> {
78-
typedef basic_server<tags::http_server, Handler> server_base;
37+
structserver : server_base<tags::http_server, Handler>::type {
38+
typedeftypename server_base<tags::http_server, Handler>::type
39+
server_base;
7940

8041
server(typename server_base::string_typeconst & address,
8142
typename server_base::string_typeconst & port,
@@ -84,6 +45,19 @@ namespace boost { namespace network { namespace http {
8445

8546
};
8647

48+
template<classHandler>
49+
structasync_server : server_base<tags::http_async_server, Handler>::type
50+
{
51+
typedeftypename server_base<tags::http_async_server, Handler>::type
52+
server_base;
53+
54+
async_server(typename server_base::string_typeconst & address,
55+
typename server_base::string_typeconst & port,
56+
Handler & handler,
57+
utils::thread_pool & thread_pool)
58+
: server_base(address, port, handler, thread_pool) {}
59+
};
60+
8761
}// namespace http
8862

8963
}// namespace network

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp