Skip to content

Commit 891c29f

Browse files
committed
HTTP Connections Building.
After a few changes to the core body and headers wrappers in the message implementation and the request linearization algorithm (to fix a bug that makes the implementation not rely on the concept constraints) the asynchronous HTTP connection implementation now compiles! The bad news here is that the async_normal implementation still needs to be cleaned up as much of the work here involved moving the protocol_handler implementation into the actual connection implementation. There's still a lot to do here to make the code more readable which may mean just more documentation -- which I will be very happy with as soon as things settle down. This commit also limits the accessibility of the response field setting interface that deals with futures and promises. Along with it is the fix for the incremental parser's mis-handling of the edge case where the range passed to the parse_until function is actually empty.
1 parent a573a4c commit 891c29f

File tree

9 files changed

+770
-328
lines changed

9 files changed

+770
-328
lines changed

boost/network/message/wrappers/body.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ namespace boost { namespace network {
1616
namespace impl {
1717

1818
struct body_wrapper {
19-
explicit body_wrapper(message_base & message);
19+
explicit body_wrapper(message_base const & message);
2020
operator std::string () const;
2121
std::size_t size() const;
2222
operator iterator_range<std::string::const_iterator> () const;
2323
std::string::const_iterator begin() const;
2424
std::string::const_iterator end() const;
2525
private:
26-
message_base & message_;
26+
message_base const & message_;
2727
mutable optional<std::string> cache_;
2828
};
2929

@@ -35,7 +35,7 @@ inline std::ostream & operator<<(std::ostream & os, body_wrapper const & body) {
3535
} // namespace impl
3636

3737
inline impl::body_wrapper const
38-
body(message_base & message_) {
38+
body(message_base const & message_) {
3939
return impl::body_wrapper(message_);
4040
}
4141

boost/network/message/wrappers/headers.hpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
namespace boost { namespace network {
1717

18-
namespace impl {
19-
2018
/** headers wrapper for messages.
2119
*
2220
* This exposes an interface similar to a map, indexable
@@ -30,7 +28,7 @@ struct headers_wrapper {
3028
typedef shared_container_iterator<container_type> iterator;
3129
typedef iterator_range<iterator> range_type;
3230

33-
explicit headers_wrapper(message_base & message);
31+
explicit headers_wrapper(message_base const & message);
3432
range_type operator[] (std::string const & key) const;
3533
operator range_type () const;
3634
operator container_type () const;
@@ -40,16 +38,14 @@ struct headers_wrapper {
4038
iterator end() const;
4139
private:
4240
void init_cache_all() const;
43-
message_base & message_;
41+
message_base const & message_;
4442
mutable shared_ptr<container_type> cache_;
4543
};
4644

47-
} // namespace impl
48-
4945
/// Factory method to create the right wrapper object
50-
inline impl::headers_wrapper const
51-
headers(message_base & message_) {
52-
return impl::headers_wrapper(message_);
46+
inline headers_wrapper const
47+
headers(message_base const & message_) {
48+
return headers_wrapper(message_);
5349
}
5450

5551
} // namespace network

boost/network/protocol/http/algorithms/linearize.hpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace boost { namespace network { namespace http {
4949
(OutputIterator)
5050
) linearize(
5151
Request const & request,
52-
typename Request::string_type const & method,
52+
std::string const & method,
5353
unsigned version_major,
5454
unsigned version_minor,
5555
OutputIterator oi
@@ -64,22 +64,31 @@ namespace boost { namespace network { namespace http {
6464
, accept_encoding = consts::accept_encoding()
6565
, default_accept_encoding = consts::default_accept_encoding()
6666
, crlf = consts::crlf()
67-
, host = consts::host()
67+
, host_const = consts::host()
6868
, connection = consts::connection()
6969
, close = consts::close()
7070
;
7171
boost::copy(method, oi);
7272
*oi = consts::space_char();
73-
if (request.path().empty() || request.path()[0] != consts::slash_char())
74-
*oi = consts::slash_char();
75-
boost::copy(request.path(), oi);
76-
if (!request.query().empty()) {
77-
*oi = consts::question_mark_char();
78-
boost::copy(request.query(), oi);
73+
{
74+
std::string path_ = path(request);
75+
if (path_.empty() || path_[0] != consts::slash_char())
76+
*oi = consts::slash_char();
77+
boost::copy(path_, oi);
7978
}
80-
if (!request.anchor().empty()) {
79+
{
80+
std::string query_ = query(request);
81+
if (!query_.empty()) {
82+
*oi = consts::question_mark_char();
83+
boost::copy(query_, oi);
84+
}
85+
}
86+
{
87+
std::string anchor_ = anchor(request);
88+
if (!anchor_.empty()) {
8189
*oi = consts::hash_char();
82-
boost::copy(request.anchor(), oi);
90+
boost::copy(anchor_, oi);
91+
}
8392
}
8493
*oi = consts::space_char();
8594
boost::copy(http_slash, oi);
@@ -89,10 +98,13 @@ namespace boost { namespace network { namespace http {
8998
*oi = consts::dot_char();
9099
boost::copy(version_minor_str, oi);
91100
boost::copy(crlf, oi);
92-
boost::copy(host, oi);
101+
boost::copy(host_const, oi);
93102
*oi = consts::colon_char();
94103
*oi = consts::space_char();
95-
boost::copy(request.host(), oi);
104+
{
105+
std::string host_ = host(request);
106+
boost::copy(host_, oi);
107+
}
96108
boost::optional<boost::uint16_t> port_ = port(request);
97109
if (port_) {
98110
string_type port_str = boost::lexical_cast<string_type>(*port_);
@@ -112,9 +124,9 @@ namespace boost { namespace network { namespace http {
112124
boost::copy(default_accept_encoding, oi);
113125
boost::copy(crlf, oi);
114126
}
115-
typedef boost::iterator_range<std::multimap<std::string, std::string>::const_iterator> headers_range;
127+
typedef headers_wrapper::range_type headers_range;
116128
typedef typename range_iterator<headers_range>::type headers_iterator;
117-
headers_range request_headers = headers(request);
129+
headers_range request_headers = boost::network::headers(request);
118130
headers_iterator iterator = boost::begin(request_headers),
119131
end = boost::end(request_headers);
120132
for (; iterator != end; ++iterator) {
@@ -128,7 +140,7 @@ namespace boost { namespace network { namespace http {
128140
}
129141
boost::copy(crlf, oi);
130142
boost::iterator_range<std::string::const_iterator> body_data =
131-
body(request);
143+
boost::network::body(request);
132144
return boost::copy(body_data, oi);
133145
}
134146

0 commit comments

Comments
 (0)