Skip to content

Commit 974cd12

Browse files
committed
Merging from 0.5-devel for eventual beta testing and release.
2 parents 6c3d96b + 08c04cc commit 974cd12

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+788
-388
lines changed

boost/network/include/http/client.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef BOOST_NETWORK_INCLUDE_HTTP_CLIENT_HPP_
2+
#define BOOST_NETWORK_INCLUDE_HTTP_CLIENT_HPP_
3+
4+
// Copyright 2009 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+
// This is the modular include file for using the HTTP Client
10+
11+
#include <boost/network/protocol/http/client.hpp>
12+
13+
#endif // BOOST_NETWORK_INCLUDE_HTTP_CLIENT_HPP_
14+

boost/network/include/message.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef BOOST_NETWORK_INCLUDE_MESSAGE_HPP_
2+
#define BOOST_NETWORK_INCLUDE_MESSAGE_HPP_
3+
4+
// Copyright 2009 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+
// This is the modular include file for using the basic message type
10+
11+
#include <boost/network/message.hpp>
12+
13+
#endif // BOOST_NETWORK_INCLUDE_MESSAGE_HPP_
14+

boost/network/message.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ namespace boost { namespace network {
9393
};
9494

9595
template <class Tag>
96-
void swap(basic_message<Tag> & left, basic_message<Tag> & right) {
96+
inline void swap(basic_message<Tag> & left, basic_message<Tag> & right) {
9797
// swap for ADL
9898
left.swap(right);
9999
}

boost/network/protocol/http/connection.hpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ namespace boost { namespace network { namespace http {
4545
, socket_(service_)
4646
, wrapper_(service_)
4747
{
48-
try {
49-
socket_.set_option(tcp::no_delay(true)); // Don't delay writing
50-
} catch (system::system_error & e) {
51-
handler_.log(e.what());
52-
}
5348
}
5449

5550
tcp::socket & socket() {
@@ -62,6 +57,9 @@ namespace boost { namespace network { namespace http {
6257
// and then pass that request object to the
6358
// handler_ instance.
6459
//
60+
boost::system::error_code option_error;
61+
socket_.set_option(tcp::no_delay(true), option_error);
62+
if (option_error) handler_.log(system::system_error(option_error).what());
6563
socket_.async_read_some(
6664
boost::asio::buffer(buffer_),
6765
wrapper_.wrap(
@@ -87,7 +85,8 @@ namespace boost { namespace network { namespace http {
8785
void handle_read_headers(system::error_code const &ec, size_t bytes_transferred) {
8886
if (!ec) {
8987
tribool done;
90-
tie(done,tuples::ignore) = parser_.parse_headers(request_, buffer_.data(), buffer_.data() + bytes_transferred);
88+
array<char, BOOST_HTTP_SERVER_BUFFER_SIZE>::iterator new_start;
89+
tie(done,new_start) = parser_.parse_headers(request_, buffer_.data(), buffer_.data() + bytes_transferred);
9190
if (done) {
9291
if (request_.method[0] == 'P') {
9392
// look for the content-length header
@@ -134,21 +133,25 @@ namespace boost { namespace network { namespace http {
134133
}
135134

136135
if (content_length != 0) {
137-
async_read(
138-
socket_,
139-
boost::asio::buffer(buffer_),
140-
boost::asio::transfer_at_least(content_length),
141-
wrapper_.wrap(
142-
bind(
143-
&connection<Tag,Handler>::handle_read_body_contents,
144-
connection<Tag,Handler>::shared_from_this(),
145-
boost::asio::placeholders::error,
146-
content_length,
147-
boost::asio::placeholders::bytes_transferred
136+
if (new_start != (buffer_.begin() + bytes_transferred)) {
137+
request_.body.append(new_start, buffer_.begin() + bytes_transferred);
138+
content_length -= std::distance(new_start, buffer_.begin() + bytes_transferred);
139+
}
140+
if (content_length > 0) {
141+
socket_.async_read_some(
142+
boost::asio::buffer(buffer_),
143+
wrapper_.wrap(
144+
bind(
145+
&connection<Tag,Handler>::handle_read_body_contents,
146+
connection<Tag,Handler>::shared_from_this(),
147+
boost::asio::placeholders::error,
148+
content_length,
149+
boost::asio::placeholders::bytes_transferred
150+
)
148151
)
149-
)
150-
);
151-
return;
152+
);
153+
return;
154+
}
152155
}
153156

154157
handler_(request_, response_);
@@ -210,7 +213,10 @@ namespace boost { namespace network { namespace http {
210213
void handle_read_body_contents(boost::system::error_code const & ec, size_t bytes_to_read, size_t bytes_transferred) {
211214
if (!ec) {
212215
size_t difference = bytes_to_read - bytes_transferred;
213-
request_.body.append(buffer_.begin(), buffer_.end());
216+
array<char,BOOST_HTTP_SERVER_BUFFER_SIZE>::iterator start = buffer_.begin(),
217+
past_end = start;
218+
std::advance(past_end, std::min(bytes_to_read,bytes_transferred));
219+
request_.body.append(buffer_.begin(), past_end);
214220
if (difference == 0) {
215221
handler_(request_, response_);
216222
boost::asio::async_write(
@@ -246,6 +252,7 @@ namespace boost { namespace network { namespace http {
246252
if (!ec) {
247253
boost::system::error_code ignored_ec;
248254
socket_.shutdown(tcp::socket::shutdown_both, ignored_ec);
255+
socket_.close(ignored_ec);
249256
}
250257
}
251258

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ namespace boost { namespace network { namespace http {
7979
case '>': case '#': case '%': case '{': case '}': case '|':
8080
case '\\': case '^': case '~': case '[': case ']': case '`':
8181
// the character needs to be encoded
82-
sprintf(encode_buf+1, "%2X", str[pos]);
82+
sprintf(encode_buf+1, "%02X", str[pos]);
8383
result += encode_buf;
8484
break;
8585
}

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ namespace boost { namespace network { namespace http {
3434
boost::network::uri::http::uri uri_;
3535

3636
public:
37+
typedef Tag tag;
3738
typedef typename string<Tag>::type string_type;
3839

3940
explicit basic_request(string_type const & uri_)
@@ -91,11 +92,6 @@ namespace boost { namespace network { namespace http {
9192

9293
};
9394

94-
template <class Tag>
95-
inline void swap(basic_request<Tag> & lhs, basic_request<Tag> & rhs) {
96-
lhs.swap(rhs);
97-
}
98-
9995
/** This is the implementation of a POD request type
10096
* that is specificially used by the HTTP server
10197
* implementation. This fully specializes the
@@ -104,8 +100,8 @@ namespace boost { namespace network { namespace http {
104100
* reasons.
105101
*/
106102
template <>
107-
class basic_request<tags::http_server> {
108-
public:
103+
struct basic_request<tags::http_server> {
104+
typedef tags::http_server tag;
109105
typedef string<tags::http_server>::type string_type;
110106
typedef vector<tags::http_server>::apply<request_header>::type vector_type;
111107
string_type method;
@@ -114,23 +110,28 @@ namespace boost { namespace network { namespace http {
114110
boost::uint8_t http_version_minor;
115111
vector_type headers;
116112
string_type body;
117-
};
118113

119-
template <>
120-
inline void swap<tags::http_server>(basic_request<tags::http_server> & l, basic_request<tags::http_server> & r) {
121-
using std::swap;
122-
swap(l.method, r.method);
123-
swap(l.uri, r.uri);
124-
swap(l.http_version_major, r.http_version_major);
125-
swap(l.http_version_minor, r.http_version_minor);
126-
swap(l.headers, r.headers);
127-
swap(l.body, r.body);
114+
void swap(basic_request & r) {
115+
using std::swap;
116+
swap(method, r.method);
117+
swap(uri, r.uri);
118+
swap(http_version_major, r.http_version_major);
119+
swap(http_version_minor, r.http_version_minor);
120+
swap(headers, r.headers);
121+
swap(body, r.body);
122+
}
128123
};
129124

125+
template <class Tag>
126+
inline void swap(basic_request<Tag> & lhs, basic_request<Tag> & rhs) {
127+
lhs.swap(rhs);
128+
}
129+
130130
} // namespace http
131131

132132
} // namespace network
133133

134134
} // namespace boost
135135

136136
#endif // __NETWORK_PROTOCOL_HTTP_REQUEST_IMPL_20070908_1_HPP__
137+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy