Skip to content

Commit 6bf16c3

Browse files
committed
Merge branch '0.9-devel' of git://github.com/cpp-netlib/cpp-netlib into 0.9-devel
Conflicts: boost/network/protocol/http/client/connection/async_normal.hpp
2 parents fecb65b + 2f40776 commit 6bf16c3

File tree

100 files changed

+2121
-1222
lines changed

Some content is hidden

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

100 files changed

+2121
-1222
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Testing
88
*.gch
99
libs/mime/test/mime-roundtrip
1010
*.a
11+
_build

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 2.8)
77
project(CPP-NETLIB)
88
set(Boost_USE_STATIC_LIBS ON)
99
set(Boost_USE_MULTI_THREADED ON)
10-
find_package( Boost 1.45.0 REQUIRED unit_test_framework system regex date_time thread filesystem program_options )
10+
find_package( Boost 1.45.0 REQUIRED unit_test_framework system regex date_time thread filesystem program_options chrono )
1111
find_package( OpenSSL )
1212
find_package( Threads )
1313
set(CMAKE_VERBOSE_MAKEFILE true)
@@ -18,6 +18,7 @@ endif()
1818

1919
if (OPENSSL_FOUND)
2020
add_definitions(-DBOOST_NETWORK_ENABLE_HTTPS)
21+
include_directories(${OPENSSL_INCLUDE_DIR})
2122
endif()
2223

2324
if (Boost_FOUND)
@@ -37,4 +38,8 @@ if (Boost_FOUND)
3738
add_subdirectory(libs/network/example)
3839
endif(Boost_FOUND)
3940

41+
if (MSVC)
42+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
43+
endif()
44+
4045
enable_testing()

boost/network/protocol/http/client.hpp

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#include <map>
2525

2626
#include <boost/network/protocol/http/client/facade.hpp>
27-
#include <boost/network/protocol/http/client/parameters.hpp>
2827
#include <boost/network/protocol/http/client/macros.hpp>
28+
#include <boost/network/protocol/http/client/options.hpp>
2929

3030
namespace boost { namespace network { namespace http {
3131

@@ -41,38 +41,18 @@ namespace boost { namespace network { namespace http {
4141
typedef basic_response<Tag> response;
4242
typedef typename string<Tag>::type string_type;
4343
typedef Tag tag_type;
44+
typedef client_options<Tag> options;
4445

45-
// Constructor
46+
// Constructors
4647
// =================================================================
47-
// This is a Boost.Parameter-based constructor forwarder, whose
48-
// implementation is actually forwarded to the base type.
49-
//
50-
// The supported parameters are:
51-
// _follow_redirects : bool -- whether to follow HTTP redirect
52-
// responses (default: false)
53-
// _cache_resolved : bool -- whether to cache the resolved
54-
// endpoints (default: false)
55-
// _io_service : boost::asio::io_service &
56-
// -- supply an io_service to the
57-
// client
58-
// _openssl_certificate : string
59-
// -- the name of the certificate file
60-
// to use
61-
// _openssl_verify_path : string
62-
// -- the name of the directory from
63-
// which the certificate authority
64-
// files can be found
65-
66-
BOOST_PARAMETER_CONSTRUCTOR(
67-
basic_client, (base_facade_type), tag,
68-
(optional
69-
(in_out(io_service), (boost::asio::io_service&))
70-
(follow_redirects, (bool))
71-
(cache_resolved, (bool))
72-
(openssl_certificate, (string_type))
73-
(openssl_verify_path, (string_type))
74-
))
75-
48+
// This constructor takes a single options argument of type
49+
// client_options. See boost/network/protocol/http/client/options.hpp
50+
// for more details.
51+
explicit basic_client(options const & options)
52+
: base_facade_type(options) {}
53+
54+
// This default constructor sets up the default options.
55+
basic_client() : base_facade_type(options()) {}
7656
//
7757
// =================================================================
7858

boost/network/protocol/http/client/async_impl.hpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <boost/asio/io_service.hpp>
1212
#include <boost/asio/strand.hpp>
1313
#include <boost/thread/thread.hpp>
14+
#include <boost/shared_ptr.hpp>
15+
#include <boost/make_shared.hpp>
1416
#include <boost/bind.hpp>
1517

1618
namespace boost { namespace network { namespace http {
@@ -37,9 +39,9 @@ namespace boost { namespace network { namespace http {
3739
function<void(boost::iterator_range<char const *> const &, system::error_code const &)>
3840
body_callback_function_type;
3941

40-
async_client(bool cache_resolved, bool follow_redirect, optional<string_type> const & certificate_filename, optional<string_type> const & verify_path)
42+
async_client(bool cache_resolved, bool follow_redirect, boost::shared_ptr<boost::asio::io_service> service, optional<string_type> const & certificate_filename, optional<string_type> const & verify_path)
4143
: connection_base(cache_resolved, follow_redirect),
42-
service_ptr(new boost::asio::io_service),
44+
service_ptr(service.get() ? service : boost::make_shared<boost::asio::io_service>()),
4345
service_(*service_ptr),
4446
resolver_(service_),
4547
sentinel_(new boost::asio::io_service::work(service_)),
@@ -55,25 +57,13 @@ namespace boost { namespace network { namespace http {
5557
)));
5658
}
5759

58-
async_client(bool cache_resolved, bool follow_redirect, boost::asio::io_service & service, optional<string_type> const & certificate_filename, optional<string_type> const & verify_path)
59-
: connection_base(cache_resolved, follow_redirect),
60-
service_ptr(0),
61-
service_(service),
62-
resolver_(service_),
63-
sentinel_(new boost::asio::io_service::work(service_)),
64-
certificate_filename_(certificate_filename),
65-
verify_path_(verify_path)
66-
{
67-
}
68-
6960
~async_client() throw ()
7061
{
7162
sentinel_.reset();
7263
if (lifetime_thread_.get()) {
7364
lifetime_thread_->join();
7465
lifetime_thread_.reset();
7566
}
76-
delete service_ptr;
7767
}
7868

7969
basic_response<Tag> const request_skeleton(
@@ -88,7 +78,7 @@ namespace boost { namespace network { namespace http {
8878
return connection_->send_request(method, request_, get_body, callback);
8979
}
9080

91-
boost::asio::io_service * service_ptr;
81+
boost::shared_ptr<boost::asio::io_service> service_ptr;
9282
boost::asio::io_service & service_;
9383
resolver_type resolver_;
9484
boost::shared_ptr<boost::asio::io_service::work> sentinel_;

boost/network/protocol/http/client/connection/async_normal.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ namespace boost { namespace network { namespace http { namespace impl {
171171
placeholders::error)));
172172
} else {
173173
set_errors(ec ? ec : boost::asio::error::host_not_found);
174+
boost::iterator_range<const char*> range;
175+
callback(range,ec);
174176
}
175177
}
176178
}
@@ -199,7 +201,16 @@ namespace boost { namespace network { namespace http { namespace impl {
199201
}
200202

201203
void handle_received_data(state_t state, bool get_body, body_callback_function_type callback, boost::system::error_code const & ec, std::size_t bytes_transferred) {
202-
if (!ec || ec == boost::asio::error::eof) {
204+
static long short_read_error = 335544539;
205+
bool is_ssl_short_read_error =
206+
#ifdef BOOST_NETWORK_ENABLE_HTTPS
207+
ec.category() == asio::error::ssl_category &&
208+
ec.value() == short_read_error
209+
#else
210+
false
211+
#endif
212+
;
213+
if (!ec || ec == boost::asio::error::eof || is_ssl_short_read_error) {
203214
logic::tribool parsed_ok;
204215
size_t remainder;
205216
switch(state) {
@@ -321,7 +332,7 @@ namespace boost { namespace network { namespace http { namespace impl {
321332
}
322333
return;
323334
case body:
324-
if (ec == boost::asio::error::eof) {
335+
if (ec == boost::asio::error::eof || is_ssl_short_read_error) {
325336
// Here we're handling the case when the connection has been
326337
// closed from the server side, or at least that the end of file
327338
// has been reached while reading the socket. This signals the end

boost/network/protocol/http/client/facade.hpp

Lines changed: 14 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <boost/network/protocol/http/request.hpp>
1010
#include <boost/network/protocol/http/response.hpp>
1111
#include <boost/network/protocol/http/client/pimpl.hpp>
12-
#include <boost/network/protocol/http/client/parameters.hpp>
12+
#include <boost/network/protocol/http/client/options.hpp>
1313

1414
namespace boost { namespace network { namespace http {
1515

@@ -28,45 +28,20 @@ namespace boost { namespace network { namespace http {
2828
typedef basic_client_impl<Tag,version_major,version_minor> pimpl_type;
2929
typedef function<void(iterator_range<char const *> const &,system::error_code const &)> body_callback_function_type;
3030

31-
template <class ArgPack>
32-
basic_client_facade(ArgPack const & args)
31+
basic_client_facade(client_options<Tag> const &options)
3332
{
34-
init_pimpl(args,
35-
typename mpl::if_<
36-
is_same<
37-
typename parameter::value_type<ArgPack, tag::io_service, void>::type,
38-
void
39-
>,
40-
no_io_service,
41-
has_io_service
42-
>::type());
33+
init_pimpl(options);
4334
}
4435

45-
BOOST_PARAMETER_MEMBER_FUNCTION((response const), head, tag, (required (request,(request const &)))) {
36+
response const head(request const &request) {
4637
return pimpl->request_skeleton(request, "HEAD", false, body_callback_function_type());
4738
}
4839

49-
BOOST_PARAMETER_MEMBER_FUNCTION((response const), get , tag,
50-
(required
51-
(request,(request const &))
52-
)
53-
(optional
54-
(body_handler,(body_callback_function_type),body_callback_function_type())
55-
)
56-
) {
40+
response const get(request const &request, body_callback_function_type body_handler = body_callback_function_type()) {
5741
return pimpl->request_skeleton(request, "GET", true, body_handler);
5842
}
5943

60-
BOOST_PARAMETER_MEMBER_FUNCTION((response const), post, tag,
61-
(required
62-
(request,(request)) // yes sir, we make a copy of the original request.
63-
)
64-
(optional
65-
(body,(string_type const &),string_type())
66-
(content_type,(string_type const &),string_type())
67-
(body_handler,(body_callback_function_type),body_callback_function_type())
68-
)
69-
) {
44+
response const post(request request, string_type const &body = string_type(), string_type const &content_type = string_type(), body_callback_function_type body_handler = body_callback_function_type()) {
7045
if (body != string_type()) {
7146
request << remove_header("Content-Length")
7247
<< header("Content-Length", boost::lexical_cast<string_type>(body.size()))
@@ -88,16 +63,7 @@ namespace boost { namespace network { namespace http {
8863
return pimpl->request_skeleton(request, "POST", true, body_handler);
8964
}
9065

91-
BOOST_PARAMETER_MEMBER_FUNCTION((response const), put , tag,
92-
(required
93-
(request,(request)) // yes sir, we make a copy of the original request.
94-
)
95-
(optional
96-
(body,(string_type const &),string_type())
97-
(content_type,(string_type const &),string_type())
98-
(body_handler,(body_callback_function_type),body_callback_function_type())
99-
)
100-
) {
66+
response const put(request request, string_type const &body = string_type(), string_type const &content_type = string_type(), body_callback_function_type body_handler = body_callback_function_type()) {
10167
if (body != string_type()) {
10268
request << remove_header("Content-Length")
10369
<< header("Content-Length", boost::lexical_cast<string_type>(body.size()))
@@ -119,14 +85,7 @@ namespace boost { namespace network { namespace http {
11985
return pimpl->request_skeleton(request, "PUT", true, body_handler);
12086
}
12187

122-
BOOST_PARAMETER_MEMBER_FUNCTION((response const), delete_, tag,
123-
(required
124-
(request,(request const &))
125-
)
126-
(optional
127-
(body_handler,(body_callback_function_type),body_callback_function_type())
128-
)
129-
) {
88+
response const delete_(request const &request, body_callback_function_type body_handler = body_callback_function_type()) {
13089
return pimpl->request_skeleton(request, "DELETE", true, body_handler);
13190
}
13291

@@ -141,31 +100,15 @@ namespace boost { namespace network { namespace http {
141100

142101
boost::shared_ptr<pimpl_type> pimpl;
143102

144-
template <class ArgPack>
145-
void init_pimpl(ArgPack const & args, no_io_service) {
103+
void init_pimpl(client_options<Tag> const & options) {
146104
pimpl.reset(
147105
new pimpl_type(
148-
args[_cache_resolved|false]
149-
, args[_follow_redirects|false]
150-
, optional<string_type>(args[_openssl_certificate|optional<string_type>()])
151-
, optional<string_type>(args[_openssl_verify_path|optional<string_type>()])
152-
)
153-
);
106+
options.cache_resolved(),
107+
options.follow_redirects(),
108+
options.openssl_certificate(),
109+
options.openssl_verify_path(),
110+
options.io_service()));
154111
}
155-
156-
template <class ArgPack>
157-
void init_pimpl(ArgPack const & args, has_io_service) {
158-
pimpl.reset(
159-
new pimpl_type(
160-
args[_cache_resolved|false]
161-
, args[_follow_redirects|false]
162-
, args[_io_service]
163-
, optional<string_type>(args[_openssl_certificate|optional<string_type>()])
164-
, optional<string_type>(args[_openssl_verify_path|optional<string_type>()])
165-
)
166-
);
167-
}
168-
169112
};
170113

171114
} // namespace http
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_OPTIONS_HPP_20130128
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_OPTIONS_HPP_20130128
3+
4+
// Copyright 2013 Google, Inc.
5+
// Copyright 2013 Dean Michael Berris <dberris@google.com>
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 {
11+
12+
template <class Tag>
13+
struct client_options {
14+
typedef typename string<Tag>::type string_type;
15+
16+
client_options()
17+
: cache_resolved_(false)
18+
, follow_redirects_(false)
19+
, openssl_certificate_()
20+
, openssl_verify_path_()
21+
, io_service_()
22+
{}
23+
24+
client_options(client_options const &other)
25+
: cache_resolved_(other.cache_resolved_)
26+
, follow_redirects_(other.follow_redirects_)
27+
, openssl_certificate_(other.openssl_certificate_)
28+
, openssl_verify_path_(other.openssl_verify_path_)
29+
, io_service_(other.io_service_)
30+
{}
31+
32+
client_options& operator=(client_options other) {
33+
other.swap(*this);
34+
return *this;
35+
}
36+
37+
void swap(client_options& other) {
38+
using std::swap;
39+
swap(cache_resolved_, other.cache_resolved_);
40+
swap(follow_redirects_, other.follow_redirects_);
41+
swap(openssl_certificate_, other.openssl_certificate_);
42+
swap(openssl_verify_path, other.openssl_verify_path_);
43+
swap(io_service_, other.io_service_);
44+
}
45+
46+
client_options& cache_resolved(bool v) { cache_resolved_ = v; return *this; };
47+
client_options& follow_redirects(bool v) { follow_redirects_ = v; return *this; };
48+
client_options& openssl_certificate(string_type const & v) { openssl_certificate_ = v; return *this; }
49+
client_options& openssl_verify_path(string_type const & v) { openssl_verify_path_ = v; return *this; }
50+
client_options& io_service(boost::shared_ptr<boost::asio::io_service> v) { io_service_ = v; return *this; }
51+
52+
bool cache_resolved() const { return cache_resolved_; }
53+
bool follow_redirects() const { return follow_redirects_; }
54+
boost::optional<string_type> openssl_certificate() const { return openssl_certificate_; }
55+
boost::optional<string_type> openssl_verify_path() const { return openssl_verify_path_; }
56+
boost::shared_ptr<boost::asio::io_service> io_service() const { return io_service_; }
57+
58+
private:
59+
bool cache_resolved_;
60+
bool follow_redirects_;
61+
boost::optional<string_type> openssl_certificate_;
62+
boost::optional<string_type> openssl_verify_path_;
63+
boost::shared_ptr<boost::asio::io_service> io_service_;
64+
};
65+
66+
template <class Tag>
67+
inline void swap(client_options<Tag>& a, client_options<Tag>& b) {
68+
a.swap(b);
69+
}
70+
71+
} /* http */
72+
} /* network */
73+
} /* boost */
74+
75+
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_OPTIONS_HPP_20130128 */

0 commit comments

Comments
 (0)