Skip to content

Commit 12dfac0

Browse files
committed
Work in progress, FIXME: break this down.
1 parent 0944773 commit 12dfac0

File tree

10 files changed

+364
-14
lines changed

10 files changed

+364
-14
lines changed

boost/network/protocol/http/client.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ namespace boost { namespace network { namespace http {
8080
}
8181

8282
response const head (request const & request_) {
83-
return sync_request_skeleton(request_, "HEAD", false);
83+
return request_skeleton(request_, "HEAD", false);
8484
};
8585

8686
response const get (request const & request_) {
87-
return sync_request_skeleton(request_, "GET", true);
87+
return request_skeleton(request_, "GET", true);
8888
};
8989

9090
response const post (request const & request_) {
91-
return sync_request_skeleton(request_, "POST", true);
91+
return request_skeleton(request_, "POST", true);
9292
};
9393

9494
response const post (request request_, string_type const & content_type, string_type const & body_) {
@@ -103,7 +103,7 @@ namespace boost { namespace network { namespace http {
103103
};
104104

105105
response const put (request const & request_) {
106-
return sync_request_skeleton(request_, "PUT", true);
106+
return request_skeleton(request_, "PUT", true);
107107
};
108108

109109
response const put (request const & request_, string_type const & body_) {
@@ -118,7 +118,7 @@ namespace boost { namespace network { namespace http {
118118
};
119119

120120
response const delete_ (request const & request_) {
121-
return sync_request_skeleton(request_, "DELETE", true);
121+
return request_skeleton(request_, "DELETE", true);
122122
};
123123

124124
private:
@@ -127,7 +127,7 @@ namespace boost { namespace network { namespace http {
127127
boost::asio::io_service service_;
128128
typename connection_base::resolver_type resolver_;
129129

130-
basic_response<Tag> const sync_request_skeleton(basic_request<Tag> const & request_, string_type method, bool get_body) {
130+
basic_response<Tag> const request_skeleton(basic_request<Tag> const & request_, string_type method, bool get_body) {
131131
typename connection_base::connection_ptr connection_;
132132
connection_ = connection_base::get_connection(resolver_, request_);
133133
return connection_->send_request(method, request_, get_body);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_IMPL_ASYNC_CONNECTION_BASE_20100529
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_IMPL_ASYNC_CONNECTION_BASE_20100529
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/response.hpp>
11+
#include <boost/network/protocol/http/impl/http_async_connection.hpp>
12+
#include <boost/network/protocol/http/impl/https_async_connection.hpp>
13+
14+
namespace boost { namespace network { namespace http { namespace impl {
15+
16+
template <class Tag, unsigned version_major, unsigned version_minor>
17+
struct async_connection_base {
18+
typedef typename resolver_policy<Tag>::type resolver_base;
19+
typedef typename resolver_base::resolver_type resolver_type;
20+
typedef typename string<Tag>::type string_type;
21+
typedef basic_request<Tag> request;
22+
typedef basic_response<Tag> response;
23+
24+
static async_connection_base<Tag,version_major,version_minor> * new_connection(resolver_type & resolver, bool https) {
25+
if (https) {
26+
return dynamic_cast<async_connection_base<Tag,version_major,version_minor>*>(new https_async_connection<Tag,version_major,version_minor>(resolver));
27+
}
28+
return dynamic_cast<async_connection_base<Tag,version_major,version_minor>*>(new http_async_connection<Tag,version_major,version_minor>(resolver));
29+
}
30+
31+
virtual response start(string_type const & hostname, string_type const & port, request const & request) = 0;
32+
33+
};
34+
35+
} // namespace impl
36+
37+
} // namespace http
38+
39+
} // namespace network
40+
41+
} // namespace boost
42+
43+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_IMPL_ASYNC_CONNECTION_BASE_20100529
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_IMPL_HTTP_ASYNC_CONNECTION_HPP_20100601
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_IMPL_HTTP_ASYNC_CONNECTION_HPP_20100601
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/thread/future.hpp>
11+
#include <boost/cstdint.hpp>
12+
13+
namespace boost { namespace network { namespace http { namespace impl {
14+
15+
template <class Tag, unsigned version_major, unsigned version_minor>
16+
struct async_connection_base;
17+
18+
template <class Tag, unsigned version_major, unsigned version_minor>
19+
struct http_async_connection
20+
: async_connection_base<Tag,version_major,version_minor> {
21+
typedef async_connection_base<Tag,version_major,version_minor> base;
22+
typedef typename base::resolver_type resolver_type;
23+
typedef typename base::response response;
24+
typedef typename base::string_type string_type;
25+
typedef typename base::request request;
26+
27+
http_async_connection(resolver_type & resolver)
28+
: resolver_(resolver) {}
29+
30+
virtual response start(string_type const & hostname, string_type const & port, request const & request) {
31+
response temp;
32+
source(temp, source_promise.get_future());
33+
destination(temp, destination_promise.get_future());
34+
headers(temp, headers_promise.get_future());
35+
body(temp, body_promise.get_future());
36+
version(temp, version_promise.get_future());
37+
status(temp, status_promise.get_future());
38+
status_message(temp, status_message_promise.get_future());
39+
resolver_.async_resolve(); //FIXME -- wire the correct parameters
40+
return temp;
41+
}
42+
43+
private:
44+
void handle_resolved(boost::system::error_code & ec) {
45+
if (!ec) {
46+
async_connect(); //FIXME -- wire the correct parameters
47+
}
48+
}
49+
50+
void handle_connected() {
51+
if (!ec) {
52+
async_send(); //FIXME -- wire the correct parameters
53+
}
54+
}
55+
56+
void handle_sent_request() {
57+
if (!ec) {
58+
async_read(); //FIXME -- wire the correct parameters
59+
}
60+
}
61+
62+
void handle_received_status() {
63+
if (!ec) {
64+
async_read(); //FIXME -- wire the correct parameters
65+
}
66+
}
67+
68+
void handle_received_headers() {
69+
if (!ec) {
70+
async_read(); //FIXME -- wire the correct parameters
71+
}
72+
}
73+
74+
void handle_recieved_body() {
75+
if (!ec) {
76+
async_read(); //FIXME -- wire the correct parameters
77+
}
78+
}
79+
80+
resolver_type & resolver_;
81+
boost::promise<string_type> version_promise;
82+
boost::promise<boost::uint16_t> status_promise;
83+
boost::promise<string_type> status_message_promise;
84+
boost::promise<typename headers_container<Tag>::type> headers_promise;
85+
boost::promise<string_type> source_promise;
86+
boost::promise<string_type> destination_promise;
87+
boost::promise<string_type> body_promise;
88+
};
89+
90+
} // namespace impl
91+
92+
} // namespace http
93+
94+
} // namespace network
95+
96+
} // namespace boost
97+
98+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_IMPL_HTTP_ASYNC_CONNECTION_HPP_20100601
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_IMPL_HTTPS_ASYNC_CONNECTION_HPP_20100601
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_IMPL_HTTPS_ASYNC_CONNECTION_HPP_20100601
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 { namespace impl {
11+
12+
template <class Tag, unsigned version_major, unsigned version_minor>
13+
struct async_connection_base;
14+
15+
template <class Tag, unsigned version_major, unsigned version_minor>
16+
struct https_async_connection
17+
: async_connection_base<Tag,version_major,version_minor>,
18+
boost::enable_shared_from_this<https_async_connection<Tag,version_major,version_minor> >
19+
{
20+
typedef async_connection_base<Tag,version_major,version_minor> base;
21+
typedef typename base::resolver_type resolver_type;
22+
typedef typename base::string_type string_type;
23+
typedef typename base::response response;
24+
typedef typename base::request request;
25+
26+
https_async_connection(resolver_type & resolver)
27+
: resolver_(resolver) {}
28+
29+
virtual response start(string_type const & hostname, string_type const & port, request const & request) {
30+
response temp;
31+
32+
return temp;
33+
}
34+
35+
private:
36+
void handle_resolved();
37+
void handle_connected();
38+
void handle_sent_request();
39+
void handle_received_status();
40+
void handle_received_headers();
41+
void handle_received_body();
42+
43+
resolver_type & resolver_;
44+
};
45+
46+
} // namespace impl
47+
48+
} // namespace http
49+
50+
} // namespace network
51+
52+
} // namespace boost
53+
54+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_IMPL_HTTPS_ASYNC_CONNECTION_HPP_20100601
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#ifndef BOOST_NETWORK_POLICY_ASYNC_CONNECTION_HPP_20100529
2+
#define BOOST_NETWORK_POLICY_ASYNC_CONNECTION_HPP_20100529
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/version.hpp>
11+
#include <boost/shared_ptr.hpp>
12+
#include <boost/lexical_cast.hpp>
13+
#include <boost/cstdint.hpp>
14+
#include <boost/network/protocol/http/traits/resolver_policy.hpp>
15+
#include <boost/network/protocol/http/detail/connection_helper.hpp>
16+
#include <boost/network/protocol/http/impl/async_connection_base.hpp>
17+
#include <boost/tuple/tuple.hpp>
18+
#include <boost/function.hpp>
19+
#include <boost/bind.hpp>
20+
#include <boost/algorithm/string/predicate.hpp>
21+
22+
namespace boost { namespace network { namespace http {
23+
24+
template <class Tag, unsigned version_major, unsigned version_minor>
25+
struct async_connection_policy : resolver_policy<Tag>::type {
26+
protected:
27+
28+
typedef typename string<Tag>::type string_type;
29+
typedef typename resolver_policy<Tag>::type resolver_base;
30+
typedef typename resolver_base::resolver_type resolver_type;
31+
typedef function<typename resolver_base::resolver_iterator_pair(resolver_type &, string_type const &, string_type const &)> resolver_function_type;
32+
33+
struct connection_impl {
34+
connection_impl(resolver_type & resolver, bool follow_redirect, string_type const & hostname, string_type const & port, resolver_function_type resolve, bool https)
35+
: pimpl()
36+
, follow_redirect_(follow_redirect)
37+
{
38+
pimpl.reset(impl::async_connection_base<Tag,version_major,version_minor>::new_connection(resolver, resolve, https));
39+
}
40+
41+
basic_response<Tag> send_request(string_type const & method, basic_request<Tag> const & request_, bool get_body) {
42+
return pimpl->start(host(request_), lexical_cast<string_type>(port(request_)), follow_redirect_);
43+
}
44+
45+
private:
46+
47+
shared_ptr<http::impl::async_connection_base<Tag, version_major, version_minor> > pimpl;
48+
bool follow_redirect_;
49+
50+
};
51+
52+
typedef boost::shared_ptr<connection_impl> connection_ptr;
53+
connection_ptr get_connection(resolver_type & resolver, basic_request<Tag> const & request_) {
54+
connection_ptr connection_(
55+
new connection_impl(
56+
resolver
57+
, follow_redirect_
58+
, host(request)
59+
, lexical_cast<string_type>(port(request))
60+
, boost::bind(
61+
&async_connection_policy<Tag, version_major, version_minor>::resolve,
62+
this,
63+
_1, _2, _3
64+
)
65+
, boost::iequals(protocol(request_), string_type("https"))
66+
)
67+
);
68+
return connection_;
69+
}
70+
71+
void cleanup() { }
72+
73+
async_connection_policy(bool cache_resolved, bool follow_redirect)
74+
: resolver_base(cache_resolved), follow_redirect_(follow_redirect) {}
75+
76+
bool follow_redirect_;
77+
};
78+
79+
} // namespace http
80+
81+
} // namespace network
82+
83+
} // namespace boost
84+
85+
#endif // BOOST_NETWORK_POLICY_ASYNC_CONNECTION_HPP_
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_REQUEST_CONCEPT_HPP_20100603
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_REQUEST_CONCEPT_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/concept_check.hpp>
11+
#include <boost/network/message/message_concept.hpp>
12+
#include <boost/cstdint.hpp>
13+
14+
namespace boost { namespace network { namespace http {
15+
16+
template <class R>
17+
struct Request
18+
: boost::network::Message<R>
19+
{
20+
typedef typename R::string_type string_type;
21+
typedef typename R::port_type port_type;
22+
23+
BOOST_CONECEPT_USAGE(Request) {
24+
R request_(string_type());
25+
swap(request_, request_); // swappable via ADL
26+
27+
string_type host_ = host(request);
28+
port_type port = port(request);
29+
string_type path = path(request);
30+
31+
request << host(string_type())
32+
<< port(port_type())
33+
<< path(string_type())
34+
;
35+
36+
host(request, string_type());
37+
port(request, port_type());
38+
path(request, string_type());
39+
}
40+
41+
private:
42+
R request;
43+
};
44+
45+
} // namespace http
46+
47+
} // namespace network
48+
49+
} // namespace boost
50+
51+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_REQUEST_CONCEPT_HPP_20100603

0 commit comments

Comments
 (0)