diff --git a/.gitmodules b/.gitmodules index 10d3b546d..8ef51b574 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,6 +10,3 @@ [submodule "deps/cxxopts"] path = deps/cxxopts url = https://github.com/jarro2783/cxxopts.git -[submodule "deps/asio"] - path = deps/asio - url = https://github.com/chriskohlhoff/asio.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 7912ac0a5..a8c30da83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ option( CPP-NETLIB_BUILD_TESTS "Build the cpp-netlib project tests." ON) # option( CPP-NETLIB_BUILD_EXPERIMENTS "Build the cpp-netlib project experiments." ON) option( CPP-NETLIB_BUILD_EXAMPLES "Build the cpp-netlib project examples." ON) option( CPP-NETLIB_ENABLE_HTTPS "Build cpp-netlib with support for https if OpenSSL is found." ON) +option( CPP-NETLIB_STATIC_OPENSSL "Build cpp-netlib using static OpenSSL" OFF) +option( CPP-NETLIB_STATIC_BOOST "Build cpp-netlib using static Boost" OFF) include(GNUInstallDirs) @@ -37,8 +39,10 @@ else() set(BUILD_SHARED_LIBS OFF) endif() -# Always use Boost's shared libraries. -set(Boost_USE_STATIC_LIBS OFF) +# Use Boost's static libraries +if (CPP-NETLIB_STATIC_BOOST) + set(Boost_USE_STATIC_LIBS ON) +endif() # We need this for all tests to use the dynamic version. add_definitions(-DBOOST_TEST_DYN_LINK) @@ -46,17 +50,36 @@ add_definitions(-DBOOST_TEST_DYN_LINK) # Always use multi-threaded Boost libraries. set(Boost_USE_MULTI_THREADED ON) -find_package(Boost 1.57.0 REQUIRED) +find_package(Boost 1.58.0 REQUIRED COMPONENTS system thread) if (CPP-NETLIB_ENABLE_HTTPS) - find_package( OpenSSL ) + if (APPLE) + # If we're on OS X check for Homebrew's copy of OpenSSL instead of Apple's + if (NOT OpenSSL_DIR) + find_program(HOMEBREW brew) + if (HOMEBREW STREQUAL "HOMEBREW-NOTFOUND") + message(WARNING "Homebrew not found: not using Homebrew's OpenSSL") + if (NOT OPENSSL_ROOT_DIR) + message(WARNING "Use -DOPENSSL_ROOT_DIR for non-Apple OpenSSL") + endif() + else() + execute_process(COMMAND brew --prefix openssl + OUTPUT_VARIABLE OPENSSL_ROOT_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + endif() + endif() + endif() + if (CPP-NETLIB_STATIC_OPENSSL) + set(CMAKE_FIND_LIBRARY_SUFFIXES .a) + endif() + find_package(OpenSSL) endif() find_package( Threads ) set(CMAKE_VERBOSE_MAKEFILE true) set(CPPNETLIB_VERSION_MAJOR 0) # MUST bump this whenever we make ABI-incompatible changes -set(CPPNETLIB_VERSION_MINOR 12) +set(CPPNETLIB_VERSION_MINOR 13) set(CPPNETLIB_VERSION_PATCH 0) set(CPPNETLIB_VERSION_STRING ${CPPNETLIB_VERSION_MAJOR}.${CPPNETLIB_VERSION_MINOR}.${CPPNETLIB_VERSION_PATCH}) @@ -84,6 +107,11 @@ elseif (${CMAKE_CXX_COMPILER_ID} MATCHES Clang) endif() +if (MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") + set(gtest_force_shared_crt true) +endif() + if (Boost_FOUND) if (MSVC) add_definitions(-D_SCL_SECURE_NO_WARNINGS) @@ -92,10 +120,7 @@ if (Boost_FOUND) add_definitions(-D_WIN32_WINNT=0x0501) endif(WIN32) include_directories(${Boost_INCLUDE_DIRS}) - - # Asio - add_definitions(-DASIO_HEADER_ONLY) - include_directories(deps/asio/asio/include) + link_directories(${Boost_LIBRARY_DIRS}) enable_testing() add_subdirectory(libs/network/src) @@ -103,23 +128,15 @@ if (Boost_FOUND) add_subdirectory(deps/googletest) add_subdirectory(libs/network/test) endif (CPP-NETLIB_BUILD_TESTS) - # if (CPP-NETLIB_BUILD_EXPERIMENTS) - # add_subdirectory(libs/network/experiment) - # endif (CPP-NETLIB_BUILD_EXPERIMENTS) - # if (NOT MSVC AND CPP-NETLIB_BUILD_TESTS) - # add_subdirectory(libs/mime/test) - # endif(NOT MSVC AND CPP-NETLIB_BUILD_TESTS) if (CPP-NETLIB_BUILD_EXAMPLES) add_subdirectory(libs/network/example) endif (CPP-NETLIB_BUILD_EXAMPLES) endif(Boost_FOUND) -if (MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") -endif() - enable_testing() +set(CPP-NETLIB_LIBRARIES ${Boost_LIBRARIES} CACHE INTERNAL "Dependent libraries for header-only use") + install(DIRECTORY boost DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) ### diff --git a/Doxyfile b/Doxyfile index 008562384..1d948995a 100644 --- a/Doxyfile +++ b/Doxyfile @@ -389,7 +389,7 @@ INLINE_SIMPLE_STRUCTS = NO # types are typedef'ed and only the typedef is referenced, never the tag name. # The default value is: NO. -TYPEDEF_HIDES_STRUCT = NO +TYPEDEF_HIDES_STRUCT = YES # The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This # cache is used to resolve symbols given their name and scope. Since this can be @@ -416,7 +416,7 @@ LOOKUP_CACHE_SIZE = 0 # normally produced when WARNINGS is set to YES. # The default value is: NO. -EXTRACT_ALL = NO +EXTRACT_ALL = YES # If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will # be included in the documentation. diff --git a/README.rst b/README.rst index 5b8185fb2..0fc25b82f 100644 --- a/README.rst +++ b/README.rst @@ -90,7 +90,7 @@ Running Tests If you want to run the tests that come with cpp-netlib, there are a few things you will need. These are: - * A compiler (GCC 4.x, Clang 3.6, MSVC 2008) + * A compiler (GCC 5.x, Clang 3.7, MSVC 2015) * A build tool (CMake_ is required) * OpenSSL headers (optional) @@ -101,13 +101,13 @@ you will need. These are: Hacking on cpp-netlib --------------------- -cpp-netlib uses git_ for tracking work, and is hosted on GitHub_. +cpp-netlib uses git_ for tracking work, and is hosted on GitHub_. cpp-netlib is hosted on GitHub_ following the GitHub recommended practice of forking the repository and submitting pull requests to the source repository. You can read more about the forking_ process and submitting `pull requests`_ if you're not familiar with either process yet. cpp-netib follows the GitHub pull request model for accepting patches. You can read more about the process at -http://cpp-netlib.org/process.html#pull-requests. +http://cpp-netlib.org/process.html#pull-requests. .. _git: http://git-scm.com/ .. _GitHub: http://github.com/ diff --git a/boost/network/message/directives/detail/string_directive.hpp b/boost/network/message/directives/detail/string_directive.hpp index db07eceb4..3c1e652db 100644 --- a/boost/network/message/directives/detail/string_directive.hpp +++ b/boost/network/message/directives/detail/string_directive.hpp @@ -34,8 +34,8 @@ #define BOOST_NETWORK_STRING_DIRECTIVE(name, value, body, pod_body) \ template \ struct name##_directive { \ - ValueType const&((value)); \ - explicit name##_directive(ValueType const& value_) : value(value_) {} \ + ValueType const& value; \ + explicit name##_directive(ValueType const& v) : value(v) {} \ name##_directive(name##_directive const& other) : value(other.value) {} \ template class Message> \ typename enable_if, void>::type operator()( \ diff --git a/boost/network/message/directives/detail/string_value.hpp b/boost/network/message/directives/detail/string_value.hpp index 53bea1546..8a3fa7d26 100644 --- a/boost/network/message/directives/detail/string_value.hpp +++ b/boost/network/message/directives/detail/string_value.hpp @@ -6,10 +6,10 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include #include #include #include +#include #include #include #include @@ -20,7 +20,7 @@ namespace detail { template struct string_value - : mpl::if_, std::shared_future::type>, + : mpl::if_, boost::shared_future::type>, typename mpl::if_< mpl::or_, is_same, is_same >, diff --git a/boost/network/message/modifiers/clear_headers.hpp b/boost/network/message/modifiers/clear_headers.hpp index 1f54af0d9..ef758073f 100644 --- a/boost/network/message/modifiers/clear_headers.hpp +++ b/boost/network/message/modifiers/clear_headers.hpp @@ -6,11 +6,11 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include #include #include #include #include +#include #include namespace boost { @@ -34,8 +34,8 @@ template inline typename enable_if >, is_async >, void>::type clear_headers(Message const &message, Tag const &) { - std::promise header_promise; - std::shared_future headers_future( + boost::promise header_promise; + boost::shared_future headers_future( header_promise.get_future()); message.headers(headers_future); header_promise.set_value(typename Message::headers_container_type()); diff --git a/boost/network/message/traits/body.hpp b/boost/network/message/traits/body.hpp index 495fe2d9b..cd0c56b1f 100644 --- a/boost/network/message/traits/body.hpp +++ b/boost/network/message/traits/body.hpp @@ -8,12 +8,12 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include #include #include #include #include #include +#include #include namespace boost { @@ -27,7 +27,7 @@ template struct body : mpl::if_< is_async, - std::shared_future::type>, + boost::shared_future::type>, typename mpl::if_< mpl::or_, is_same #include #include #include #include #include +#include #include namespace boost { @@ -26,7 +26,7 @@ struct unsupported_tag; template struct destination : mpl::if_, - std::shared_future::type>, + boost::shared_future::type>, typename mpl::if_< mpl::or_, is_same #include #include #include @@ -15,6 +14,7 @@ #include #include #include +#include namespace boost { namespace network { @@ -28,7 +28,7 @@ template struct header_key : mpl::if_< is_async, - std::shared_future::type>, + boost::shared_future::type>, typename mpl::if_< mpl::or_, is_same, @@ -40,7 +40,7 @@ template struct header_value : mpl::if_< is_async, - std::shared_future::type>, + boost::shared_future::type>, typename mpl::if_< mpl::or_, is_same, diff --git a/boost/network/message/traits/source.hpp b/boost/network/message/traits/source.hpp index ad037a4a6..17f9b188e 100644 --- a/boost/network/message/traits/source.hpp +++ b/boost/network/message/traits/source.hpp @@ -6,12 +6,12 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include #include #include #include #include #include +#include #include namespace boost { @@ -24,7 +24,7 @@ struct unsupported_tag; template struct source : mpl::if_, - std::shared_future::type>, + boost::shared_future::type>, typename mpl::if_< mpl::or_, is_same #include -#include #include namespace boost { diff --git a/boost/network/protocol/http/client/async_impl.hpp b/boost/network/protocol/http/client/async_impl.hpp index bb4eab191..8e6dda6b1 100644 --- a/boost/network/protocol/http/client/async_impl.hpp +++ b/boost/network/protocol/http/client/async_impl.hpp @@ -11,8 +11,9 @@ #include #include #include -#include -#include +#include +#include +#include #include namespace boost { @@ -31,27 +32,34 @@ struct async_client typedef typename resolver::type resolver_type; typedef typename string::type string_type; - typedef std::function const&, - std::error_code const&)> + typedef + typename std::array::type, + BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE>:: + const_iterator const_iterator; + typedef iterator_range char_const_range; + + typedef std::function body_callback_function_type; typedef std::function body_generator_function_type; async_client(bool cache_resolved, bool follow_redirect, - bool always_verify_peer, int timeout, - std::shared_ptr service, + bool always_verify_peer, int timeout, bool remove_chunk_markers, + std::shared_ptr service, optional certificate_filename, optional verify_path, optional certificate_file, optional private_key_file, optional ciphers, optional sni_hostname, long ssl_options) - : connection_base(cache_resolved, follow_redirect, timeout), + : connection_base(cache_resolved, follow_redirect, timeout, + remove_chunk_markers), service_ptr(service.get() ? service - : std::make_shared()), + : std::make_shared()), service_(*service_ptr), resolver_(service_), - sentinel_(new asio::io_service::work(service_)), + sentinel_(new boost::asio::io_service::work(service_)), certificate_filename_(std::move(certificate_filename)), verify_path_(std::move(verify_path)), certificate_file_(std::move(certificate_file)), @@ -61,7 +69,7 @@ struct async_client ssl_options_(ssl_options), always_verify_peer_(always_verify_peer) { connection_base::resolver_strand_.reset( - new asio::io_service::strand(service_)); + new boost::asio::io_service::strand(service_)); if (!service) lifetime_thread_.reset(new std::thread([this]() { service_.run(); })); } @@ -71,7 +79,9 @@ struct async_client void wait_complete() { sentinel_.reset(); if (lifetime_thread_.get()) { - lifetime_thread_->join(); + if (lifetime_thread_->joinable() && lifetime_thread_->get_id() != std::this_thread::get_id()) { + lifetime_thread_->join(); + } lifetime_thread_.reset(); } } @@ -89,10 +99,10 @@ struct async_client generator); } - std::shared_ptr service_ptr; - asio::io_service& service_; + std::shared_ptr service_ptr; + boost::asio::io_service& service_; resolver_type resolver_; - std::shared_ptr sentinel_; + std::shared_ptr sentinel_; std::shared_ptr lifetime_thread_; optional certificate_filename_; optional verify_path_; diff --git a/boost/network/protocol/http/client/connection/async_base.hpp b/boost/network/protocol/http/client/connection/async_base.hpp index 586202412..ec1737828 100644 --- a/boost/network/protocol/http/client/connection/async_base.hpp +++ b/boost/network/protocol/http/client/connection/async_base.hpp @@ -9,11 +9,13 @@ // http://www.boost.org/LICENSE_1_0.txt) #include +#include #include #include #include #include #include +#include namespace boost { namespace network { @@ -29,8 +31,12 @@ struct async_connection_base { typedef typename string::type string_type; typedef basic_request request; typedef basic_response response; - typedef iterator_range char_const_range; - typedef std::function + typedef + typename std::array::type, + BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE>:: + const_iterator const_iterator; + typedef iterator_range char_const_range; + typedef std::function body_callback_function_type; typedef std::function body_generator_function_type; typedef std::shared_ptr connection_ptr; @@ -41,6 +47,7 @@ struct async_connection_base { static connection_ptr new_connection( resolve_function resolve, resolver_type &resolver, bool follow_redirect, bool always_verify_peer, bool https, int timeout, + bool remove_chunk_markers, optional certificate_filename = optional(), optional const &verify_path = optional(), optional certificate_file = optional(), @@ -56,7 +63,8 @@ struct async_connection_base { certificate_filename, verify_path, certificate_file, private_key_file, ciphers, sni_hostname, ssl_options); auto temp = std::make_shared( - resolver, resolve, follow_redirect, timeout, std::move(delegate)); + resolver, resolve, follow_redirect, timeout, remove_chunk_markers, + std::move(delegate)); BOOST_ASSERT(temp != nullptr); return temp; } diff --git a/boost/network/protocol/http/client/connection/async_normal.hpp b/boost/network/protocol/http/client/connection/async_normal.hpp index 1604a727e..adae8edf0 100644 --- a/boost/network/protocol/http/client/connection/async_normal.hpp +++ b/boost/network/protocol/http/client/connection/async_normal.hpp @@ -12,10 +12,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include @@ -30,6 +30,7 @@ #include #include #include +#include #include namespace boost { @@ -37,10 +38,85 @@ namespace network { namespace http { namespace impl { +template +struct chunk_encoding_parser { + typedef typename buffer_type::const_iterator const_iterator; + typedef boost::iterator_range char_const_range; + + chunk_encoding_parser() : state(state_t::header), chunk_size(0) {} + + enum class state_t { header, header_end, data, data_end }; + + state_t state; + size_t chunk_size; + buffer_type buffer; + + template + void update_chunk_size(boost::iterator_range const &range) { + if (range.empty()) return; + std::stringstream ss; + ss << std::hex << range; + size_t size; + ss >> size; + // New digits are appended as LSBs + chunk_size = (chunk_size << (range.size() * 4)) | size; + } + + template + char_const_range operator()(boost::iterator_range const &range) { + auto iter = boost::begin(range); + auto begin = iter; + auto pos = boost::begin(buffer); + + while (iter != boost::end(range)) switch (state) { + case state_t::header: + iter = std::find(iter, boost::end(range), '\r'); + update_chunk_size(boost::make_iterator_range(begin, iter)); + if (iter != boost::end(range)) { + state = state_t::header_end; + ++iter; + } + break; + + case state_t::header_end: + BOOST_ASSERT(*iter == '\n'); + ++iter; + state = state_t::data; + break; + + case state_t::data: + if (chunk_size == 0) { + BOOST_ASSERT(*iter == '\r'); + ++iter; + state = state_t::data_end; + } else { + auto len = std::min(chunk_size, + (size_t)std::distance(iter, boost::end(range))); + begin = iter; + iter = std::next(iter, len); + pos = std::copy(begin, iter, pos); + chunk_size -= len; + } + break; + + case state_t::data_end: + BOOST_ASSERT(*iter == '\n'); + ++iter; + begin = iter; + state = state_t::header; + break; + + default: + BOOST_ASSERT(false && "Bug, report this to the developers!"); + } + return boost::make_iterator_range(boost::begin(buffer), pos); + } +}; + template struct async_connection_base; -namespace placeholders = asio::placeholders; +namespace placeholders = boost::asio::placeholders; template struct http_async_connection @@ -61,6 +137,7 @@ struct http_async_connection typedef typename base::string_type string_type; typedef typename base::request request; typedef typename base::resolver_base::resolve_function resolve_function; + typedef typename base::char_const_range char_const_range; typedef typename base::body_callback_function_type body_callback_function_type; typedef @@ -69,11 +146,14 @@ struct http_async_connection typedef typename delegate_factory::type delegate_factory_type; typedef typename delegate_factory_type::connection_delegate_ptr connection_delegate_ptr; + typedef chunk_encoding_parser chunk_encoding_parser_type; http_async_connection(resolver_type& resolver, resolve_function resolve, bool follow_redirect, int timeout, + bool remove_chunk_markers, connection_delegate_ptr delegate) : timeout_(timeout), + remove_chunk_markers_(remove_chunk_markers), timer_(resolver.get_io_service()), is_timedout_(false), follow_redirect_(follow_redirect), @@ -100,17 +180,19 @@ struct http_async_connection string_type host_ = host(request); std::uint16_t source_port = request.source_port(); + auto sni_hostname = request.sni_hostname(); + auto self = this->shared_from_this(); resolve_(resolver_, host_, port_, request_strand_.wrap( - [=] (std::error_code const &ec, + [=] (boost::system::error_code const &ec, resolver_iterator_pair endpoint_range) { - self->handle_resolved(host_, port_, source_port, get_body, + self->handle_resolved(host_, port_, source_port, sni_hostname, get_body, callback, generator, ec, endpoint_range); })); if (timeout_ > 0) { - timer_.expires_from_now(boost::posix_time::seconds(timeout_)); - timer_.async_wait(request_strand_.wrap([=] (std::error_code const &ec) { + timer_.expires_from_now(std::chrono::seconds(timeout_)); + timer_.async_wait(request_strand_.wrap([=] (boost::system::error_code const &ec) { self->handle_timeout(ec); })); } @@ -118,63 +200,63 @@ struct http_async_connection } private: - void set_errors(std::error_code const& ec) { - std::system_error error(ec); - this->version_promise.set_exception(std::make_exception_ptr(error)); - this->status_promise.set_exception(std::make_exception_ptr(error)); - this->status_message_promise.set_exception(std::make_exception_ptr(error)); - this->headers_promise.set_exception(std::make_exception_ptr(error)); - this->source_promise.set_exception(std::make_exception_ptr(error)); - this->destination_promise.set_exception(std::make_exception_ptr(error)); - this->body_promise.set_exception(std::make_exception_ptr(error)); + void set_errors(boost::system::error_code const& ec, body_callback_function_type callback) { + boost::system::system_error error(ec); + this->version_promise.set_exception(error); + this->status_promise.set_exception(error); + this->status_message_promise.set_exception(error); + this->headers_promise.set_exception(error); + this->source_promise.set_exception(error); + this->destination_promise.set_exception(error); + this->body_promise.set_exception(error); + if ( callback ) + callback( char_const_range(), ec ); this->timer_.cancel(); } - void handle_timeout(std::error_code const& ec) { + void handle_timeout(boost::system::error_code const& ec) { if (!ec) delegate_->disconnect(); is_timedout_ = true; } void handle_resolved(string_type host, std::uint16_t port, - std::uint16_t source_port, bool get_body, + std::uint16_t source_port, optional sni_hostname, bool get_body, body_callback_function_type callback, body_generator_function_type generator, - std::error_code const& ec, + boost::system::error_code const& ec, resolver_iterator_pair endpoint_range) { if (!ec && !boost::empty(endpoint_range)) { // Here we deal with the case that there was an error encountered and // that there's still more endpoints to try connecting to. resolver_iterator iter = boost::begin(endpoint_range); - asio::ip::tcp::endpoint endpoint(iter->endpoint().address(), port); + boost::asio::ip::tcp::endpoint endpoint(iter->endpoint().address(), port); auto self = this->shared_from_this(); delegate_->connect( - endpoint, host, source_port, - request_strand_.wrap([=] (std::error_code const &ec) { + endpoint, host, source_port, sni_hostname, + request_strand_.wrap([=] (boost::system::error_code const &ec) { auto iter_copy = iter; - self->handle_connected(host, port, source_port, get_body, callback, + self->handle_connected(host, port, source_port, sni_hostname, get_body, callback, generator, std::make_pair(++iter_copy, resolver_iterator()), ec); })); } else { - set_errors(ec ? ec : asio::error::host_not_found); - boost::iterator_range range; - if (callback) callback(range, ec); + set_errors((ec ? ec : boost::asio::error::host_not_found), callback); } } void handle_connected(string_type host, std::uint16_t port, - std::uint16_t source_port, bool get_body, + std::uint16_t source_port, optional sni_hostname, bool get_body, body_callback_function_type callback, body_generator_function_type generator, resolver_iterator_pair endpoint_range, - std::error_code const& ec) { + boost::system::error_code const& ec) { if (is_timedout_) { - set_errors(asio::error::timed_out); + set_errors(boost::asio::error::timed_out, callback); } else if (!ec) { BOOST_ASSERT(delegate_.get() != 0); auto self = this->shared_from_this(); delegate_->write( command_streambuf, - request_strand_.wrap([=] (std::error_code const &ec, + request_strand_.wrap([=] (boost::system::error_code const &ec, std::size_t bytes_transferred) { self->handle_sent_request(get_body, callback, generator, ec, bytes_transferred); @@ -182,20 +264,18 @@ struct http_async_connection } else { if (!boost::empty(endpoint_range)) { resolver_iterator iter = boost::begin(endpoint_range); - asio::ip::tcp::endpoint endpoint(iter->endpoint().address(), port); + boost::asio::ip::tcp::endpoint endpoint(iter->endpoint().address(), port); auto self = this->shared_from_this(); delegate_->connect( - endpoint, host, source_port, - request_strand_.wrap([=] (std::error_code const &ec) { + endpoint, host, source_port, sni_hostname, + request_strand_.wrap([=] (boost::system::error_code const &ec) { auto iter_copy = iter; - self->handle_connected(host, port, source_port, get_body, callback, + self->handle_connected(host, port, source_port, sni_hostname, get_body, callback, generator, std::make_pair(++iter_copy, resolver_iterator()), ec); })); } else { - set_errors(ec ? ec : asio::error::host_not_found); - boost::iterator_range range; - if (callback) callback(range, ec); + set_errors((ec ? ec : boost::asio::error::host_not_found), callback); } } } @@ -204,8 +284,8 @@ struct http_async_connection void handle_sent_request(bool get_body, body_callback_function_type callback, body_generator_function_type generator, - std::error_code const& ec, - std::size_t bytes_transferred) { + boost::system::error_code const& ec, + std::size_t /*bytes_transferred*/) { // TODO(unassigned): use-case? if (!is_timedout_ && !ec) { if (generator) { // Here we write some more data that the generator provides, before we @@ -220,7 +300,7 @@ struct http_async_connection auto self = this->shared_from_this(); delegate_->write( command_streambuf, - request_strand_.wrap([=] (std::error_code const &ec, + request_strand_.wrap([=] (boost::system::error_code const &ec, std::size_t bytes_transferred) { self->handle_sent_request(get_body, callback, generator, ec, bytes_transferred); @@ -231,41 +311,41 @@ struct http_async_connection auto self = this->shared_from_this(); delegate_->read_some( - asio::mutable_buffers_1(this->part.data(), + boost::asio::mutable_buffers_1(this->part.data(), this->part.size()), - request_strand_.wrap([=] (std::error_code const &ec, + request_strand_.wrap([=] (boost::system::error_code const &ec, std::size_t bytes_transferred) { self->handle_received_data(version, get_body, callback, ec, bytes_transferred); })); } else { - set_errors(is_timedout_ ? asio::error::timed_out : ec); + set_errors((is_timedout_ ? boost::asio::error::timed_out : ec), callback); } } void handle_received_data(state_t state, bool get_body, body_callback_function_type callback, - std::error_code const& ec, + boost::system::error_code const& ec, std::size_t bytes_transferred) { static const long short_read_error = 335544539; bool is_ssl_short_read_error = #ifdef BOOST_NETWORK_ENABLE_HTTPS - ec.category() == asio::error::ssl_category && + ec.category() == boost::asio::error::ssl_category && ec.value() == short_read_error; #else false && short_read_error; #endif if (!is_timedout_ && - (!ec || ec == asio::error::eof || is_ssl_short_read_error)) { + (!ec || ec == boost::asio::error::eof || is_ssl_short_read_error)) { logic::tribool parsed_ok; size_t remainder; auto self = this->shared_from_this(); switch (state) { case version: - if (ec == asio::error::eof) return; + if (ec == boost::asio::error::eof) return; parsed_ok = this->parse_version( delegate_, - request_strand_.wrap([=] (std::error_code const &ec, + request_strand_.wrap([=] (boost::system::error_code const &ec, std::size_t bytes_transferred) { self->handle_received_data(version, get_body, callback, ec, bytes_transferred); @@ -274,11 +354,12 @@ struct http_async_connection if (!parsed_ok || indeterminate(parsed_ok)) { return; } + // fall-through case status: - if (ec == asio::error::eof) return; + if (ec == boost::asio::error::eof) return; parsed_ok = this->parse_status( delegate_, - request_strand_.wrap([=] (std::error_code const &ec, + request_strand_.wrap([=] (boost::system::error_code const &ec, std::size_t bytes_transferred) { self->handle_received_data(status, get_body, callback, ec, bytes_transferred); @@ -287,10 +368,11 @@ struct http_async_connection if (!parsed_ok || indeterminate(parsed_ok)) { return; } + // fall-through case status_message: - if (ec == asio::error::eof) return; + if (ec == boost::asio::error::eof) return; parsed_ok = this->parse_status_message( - delegate_, request_strand_.wrap([=] (std::error_code const &, + delegate_, request_strand_.wrap([=] (boost::system::error_code const &, std::size_t bytes_transferred) { self->handle_received_data(status_message, get_body, callback, ec, bytes_transferred); @@ -299,15 +381,16 @@ struct http_async_connection if (!parsed_ok || indeterminate(parsed_ok)) { return; } + // fall-through case headers: - if (ec == asio::error::eof) return; + if (ec == boost::asio::error::eof) return; // In the following, remainder is the number of bytes that remain in // the buffer. We need this in the body processing to make sure that // the data remaining in the buffer is dealt with before another call // to get more data for the body is scheduled. std::tie(parsed_ok, remainder) = this->parse_headers( delegate_, - request_strand_.wrap([=] (std::error_code const &ec, + request_strand_.wrap([=] (boost::system::error_code const &ec, std::size_t bytes_transferred) { self->handle_received_data(headers, get_body, callback, ec, bytes_transferred); @@ -322,6 +405,8 @@ struct http_async_connection // We short-circuit here because the user does not want to get the // body (in the case of a HEAD request). this->body_promise.set_value(""); + if ( callback ) + callback( char_const_range(), boost::asio::error::eof ); this->destination_promise.set_value(""); this->source_promise.set_value(""); // this->part.assign('\0'); @@ -348,13 +433,16 @@ struct http_async_connection // The invocation of the callback is synchronous to allow us to // wait before scheduling another read. - callback(make_iterator_range(begin, end), ec); - + if (this->is_chunk_encoding && remove_chunk_markers_) { + callback(parse_chunk_encoding(make_iterator_range(begin, end)), ec); + } else { + callback(make_iterator_range(begin, end), ec); + } auto self = this->shared_from_this(); delegate_->read_some( - asio::mutable_buffers_1(this->part.data(), + boost::asio::mutable_buffers_1(this->part.data(), this->part.size()), - request_strand_.wrap([=] (std::error_code const &ec, + request_strand_.wrap([=] (boost::system::error_code const &ec, std::size_t bytes_transferred) { self->handle_received_data(body, get_body, callback, ec, bytes_transferred); @@ -365,7 +453,7 @@ struct http_async_connection auto self = this->shared_from_this(); this->parse_body( delegate_, - request_strand_.wrap([=] (std::error_code const &ec, + request_strand_.wrap([=] (boost::system::error_code const &ec, std::size_t bytes_transferred) { self->handle_received_data(body, get_body, callback, ec, bytes_transferred); @@ -374,7 +462,7 @@ struct http_async_connection } return; case body: - if (ec == asio::error::eof || is_ssl_short_read_error) { + if (ec == boost::asio::error::eof || is_ssl_short_read_error) { // Here we're handling the case when the connection has been closed // from the server side, or at least that the end of file has been // reached while reading the socket. This signals the end of the @@ -388,14 +476,32 @@ struct http_async_connection // We call the callback function synchronously passing the error // condition (in this case, end of file) so that it can handle it // appropriately. - callback(make_iterator_range(begin, end), ec); + if (this->is_chunk_encoding && remove_chunk_markers_) { + callback(parse_chunk_encoding(make_iterator_range(begin, end)), ec); + } else { + callback(make_iterator_range(begin, end), ec); + } } else { string_type body_string; - std::swap(body_string, this->partial_parsed); - body_string.append(this->part.begin(), bytes_transferred); - if (this->is_chunk_encoding) { - this->body_promise.set_value(parse_chunk_encoding(body_string)); + if (this->is_chunk_encoding && remove_chunk_markers_) { + const auto parse_buffer_size = parse_chunk_encoding.buffer.size(); + for (size_t i = 0; i < this->partial_parsed.size(); i += parse_buffer_size) { + auto range = parse_chunk_encoding(boost::make_iterator_range( + this->partial_parsed.cbegin() + i, + this->partial_parsed.cbegin() + + std::min(i + parse_buffer_size, this->partial_parsed.size()))); + body_string.append(boost::begin(range), boost::end(range)); + } + this->partial_parsed.clear(); + auto range = parse_chunk_encoding(boost::make_iterator_range( + this->part.begin(), + this->part.begin() + bytes_transferred)); + body_string.append(boost::begin(range), boost::end(range)); + this->body_promise.set_value(body_string); } else { + std::swap(body_string, this->partial_parsed); + body_string.append(this->part.begin(), + this->part.begin() + bytes_transferred); this->body_promise.set_value(body_string); } } @@ -417,12 +523,16 @@ struct http_async_connection this->part.begin(); typename protocol_base::buffer_type::const_iterator end = begin; std::advance(end, bytes_transferred); - callback(make_iterator_range(begin, end), ec); + if (this->is_chunk_encoding && remove_chunk_markers_) { + callback(parse_chunk_encoding(make_iterator_range(begin, end)), ec); + } else { + callback(make_iterator_range(begin, end), ec); + } auto self = this->shared_from_this(); delegate_->read_some( - asio::mutable_buffers_1(this->part.data(), + boost::asio::mutable_buffers_1(this->part.data(), this->part.size()), - request_strand_.wrap([=] (std::error_code const &ec, + request_strand_.wrap([=] (boost::system::error_code const &ec, std::size_t bytes_transferred) { self->handle_received_data(body, get_body, callback, ec, bytes_transferred); @@ -433,7 +543,7 @@ struct http_async_connection // have data that's still in the buffer. this->parse_body( delegate_, - request_strand_.wrap([=] (std::error_code const &ec, + request_strand_.wrap([=] (boost::system::error_code const &ec, std::size_t bytes_transferred) { self->handle_received_data(body, get_body, callback, ec, bytes_transferred); @@ -446,75 +556,52 @@ struct http_async_connection BOOST_ASSERT(false && "Bug, report this to the developers!"); } } else { - std::system_error error(is_timedout_ ? asio::error::timed_out - : ec); - this->source_promise.set_exception(std::make_exception_ptr(error)); - this->destination_promise.set_exception(std::make_exception_ptr(error)); + boost::system::error_code report_code = is_timedout_ ? boost::asio::error::timed_out : ec; + boost::system::system_error error(report_code); + this->source_promise.set_exception(error); + this->destination_promise.set_exception(error); switch (state) { case version: - this->version_promise.set_exception(std::make_exception_ptr(error)); + this->version_promise.set_exception(error); + // fall-through case status: - this->status_promise.set_exception(std::make_exception_ptr(error)); + this->status_promise.set_exception(error); + // fall-through case status_message: - this->status_message_promise.set_exception( - std::make_exception_ptr(error)); + this->status_message_promise.set_exception(error); + // fall-through case headers: - this->headers_promise.set_exception(std::make_exception_ptr(error)); + this->headers_promise.set_exception(error); + // fall-through case body: if (!callback) { // N.B. if callback is non-null, then body_promise has already been // set to value "" to indicate body is handled by streaming handler // so no exception should be set - this->body_promise.set_exception(std::make_exception_ptr(error)); + this->body_promise.set_exception(error); } + else + callback( char_const_range(), report_code ); break; + // fall-through default: BOOST_ASSERT(false && "Bug, report this to the developers!"); } } } - string_type parse_chunk_encoding(string_type& body_string) { - string_type body; - string_type crlf = "\r\n"; - - typename string_type::iterator begin = body_string.begin(); - for (typename string_type::iterator iter = - std::search(begin, body_string.end(), crlf.begin(), crlf.end()); - iter != body_string.end(); - iter = - std::search(begin, body_string.end(), crlf.begin(), crlf.end())) { - string_type line(begin, iter); - if (line.empty()) { - break; - } - std::stringstream stream(line); - int len; - stream >> std::hex >> len; - std::advance(iter, 2); - if (len == 0) { - break; - } - if (len <= body_string.end() - iter) { - body.insert(body.end(), iter, iter + len); - std::advance(iter, len + 2); - } - begin = iter; - } - - return body; - } - int timeout_; - asio::deadline_timer timer_; + bool remove_chunk_markers_; + boost::asio::steady_timer timer_; bool is_timedout_; bool follow_redirect_; resolver_type& resolver_; resolve_function resolve_; - asio::io_service::strand request_strand_; + boost::asio::io_service::strand request_strand_; connection_delegate_ptr delegate_; - asio::streambuf command_streambuf; + boost::asio::streambuf command_streambuf; string_type method; + chunk_encoding_parser_type parse_chunk_encoding; }; } // namespace impl diff --git a/boost/network/protocol/http/client/connection/async_protocol_handler.hpp b/boost/network/protocol/http/client/connection/async_protocol_handler.hpp index a860efb61..383b62038 100644 --- a/boost/network/protocol/http/client/connection/async_protocol_handler.hpp +++ b/boost/network/protocol/http/client/connection/async_protocol_handler.hpp @@ -13,10 +13,12 @@ #include #include #include +#include #include #include #include #include +#include namespace boost { namespace network { @@ -57,30 +59,30 @@ struct http_async_protocol_handler { // TODO(dberris): review parameter necessity. (void)get_body; - std::shared_future source_future( + boost::shared_future source_future( source_promise.get_future()); source(response_, source_future); - std::shared_future destination_future( + boost::shared_future destination_future( destination_promise.get_future()); destination(response_, destination_future); - std::shared_future::type> headers_future( + boost::shared_future::type> headers_future( headers_promise.get_future()); headers(response_, headers_future); - std::shared_future body_future(body_promise.get_future()); + boost::shared_future body_future(body_promise.get_future()); body(response_, body_future); - std::shared_future version_future( + boost::shared_future version_future( version_promise.get_future()); version(response_, version_future); - std::shared_future status_future( + boost::shared_future status_future( status_promise.get_future()); status(response_, status_future); - std::shared_future status_message_future( + boost::shared_future status_message_future( status_message_promise.get_future()); status_message(response_, status_message_future); } @@ -127,19 +129,19 @@ struct http_async_protocol_handler { << "\""); #endif std::runtime_error error("Invalid Version Part."); - version_promise.set_exception(std::make_exception_ptr(error)); - status_promise.set_exception(std::make_exception_ptr(error)); - status_message_promise.set_exception(std::make_exception_ptr(error)); - headers_promise.set_exception(std::make_exception_ptr(error)); - source_promise.set_exception(std::make_exception_ptr(error)); - destination_promise.set_exception(std::make_exception_ptr(error)); - body_promise.set_exception(std::make_exception_ptr(error)); + version_promise.set_exception(error); + status_promise.set_exception(error); + status_message_promise.set_exception(error); + headers_promise.set_exception(error); + source_promise.set_exception(error); + destination_promise.set_exception(error); + body_promise.set_exception(error); } else { partial_parsed.append(std::begin(result_range), std::end(result_range)); part_begin = part.begin(); delegate_->read_some( - asio::mutable_buffers_1(part.data(), part.size()), + boost::asio::mutable_buffers_1(part.data(), part.size()), callback); } return parsed_ok; @@ -174,18 +176,18 @@ struct http_async_protocol_handler { << "\""); #endif std::runtime_error error("Invalid status part."); - status_promise.set_exception(std::make_exception_ptr(error)); - status_message_promise.set_exception(std::make_exception_ptr(error)); - headers_promise.set_exception(std::make_exception_ptr(error)); - source_promise.set_exception(std::make_exception_ptr(error)); - destination_promise.set_exception(std::make_exception_ptr(error)); - body_promise.set_exception(std::make_exception_ptr(error)); + status_promise.set_exception(error); + status_message_promise.set_exception(error); + headers_promise.set_exception(error); + source_promise.set_exception(error); + destination_promise.set_exception(error); + body_promise.set_exception(error); } else { partial_parsed.append(std::begin(result_range), std::end(result_range)); part_begin = part.begin(); delegate_->read_some( - asio::mutable_buffers_1(part.data(), part.size()), + boost::asio::mutable_buffers_1(part.data(), part.size()), callback); } return parsed_ok; @@ -220,17 +222,17 @@ struct http_async_protocol_handler { << "\""); #endif std::runtime_error error("Invalid status message part."); - status_message_promise.set_exception(std::make_exception_ptr(error)); - headers_promise.set_exception(std::make_exception_ptr(error)); - source_promise.set_exception(std::make_exception_ptr(error)); - destination_promise.set_exception(std::make_exception_ptr(error)); - body_promise.set_exception(std::make_exception_ptr(error)); + status_message_promise.set_exception(error); + headers_promise.set_exception(error); + source_promise.set_exception(error); + destination_promise.set_exception(error); + body_promise.set_exception(error); } else { partial_parsed.append(std::begin(result_range), std::end(result_range)); part_begin = part.begin(); delegate_->read_some( - asio::mutable_buffers_1(part.data(), part.size()), + boost::asio::mutable_buffers_1(part.data(), part.size()), callback); } return parsed_ok; @@ -245,6 +247,10 @@ struct http_async_protocol_handler { response_parser_type::http_header_line_done); typename headers_container::type headers; std::pair header_pair; + //init params + is_content_length = false; + content_length = -1; + is_chunk_end = false; while (!boost::empty(input_range)) { std::tie(parsed_ok, result_range) = headers_parser.parse_until( response_parser_type::http_header_colon, input_range); @@ -265,6 +271,16 @@ struct http_async_protocol_handler { } trim(header_pair.second); headers.insert(header_pair); + if (!is_content_length && + boost::iequals(header_pair.first, "Content-Length")) { + try { + content_length = std::stoll(header_pair.second); + is_content_length = true; + } + catch (std::exception&) { + //is_content_length = false; + } + } } // determine if the body parser will need to handle chunked encoding typename headers_range >::type transfer_encoding_range = @@ -308,48 +324,101 @@ struct http_async_protocol_handler { << boost::distance(result_range)); #endif std::runtime_error error("Invalid header part."); - headers_promise.set_exception(std::make_exception_ptr(error)); - body_promise.set_exception(std::make_exception_ptr(error)); - source_promise.set_exception(std::make_exception_ptr(error)); - destination_promise.set_exception(std::make_exception_ptr(error)); + headers_promise.set_exception(error); + body_promise.set_exception(error); + source_promise.set_exception(error); + destination_promise.set_exception(error); } else { partial_parsed.append(std::begin(result_range), std::end(result_range)); part_begin = part.begin(); delegate_->read_some( - asio::mutable_buffers_1(part.data(), part.size()), + boost::asio::mutable_buffers_1(part.data(), part.size()), callback); } return std::make_tuple( parsed_ok, std::distance(std::end(result_range), part_end)); } + inline bool check_parse_body_complete() const { + if (this->is_chunk_encoding) { + return parse_chunk_encoding_complete(); + } + if (this->is_content_length && this->content_length >= 0) { + return parse_content_length_complete(); + } + return false; + } + + inline bool parse_content_length_complete() const { + return this->partial_parsed.length() >= this-> content_length; + } + + bool parse_chunk_encoding_complete() const { + string_type body; + string_type crlf = "\r\n"; + + typename string_type::const_iterator begin = partial_parsed.begin(); + for (typename string_type::const_iterator iter = + std::search(begin, partial_parsed.end(), crlf.begin(), crlf.end()); + iter != partial_parsed.end(); + iter = std::search(begin, partial_parsed.end(), crlf.begin(), crlf.end())) { + string_type line(begin, iter); + if (line.empty()) { + std::advance(iter, 2); + begin = iter; + continue; + } + std::stringstream stream(line); + int len; + stream >> std::hex >> len; + std::advance(iter, 2); + if (!len) return true; + if (len <= partial_parsed.end() - iter) { + std::advance(iter, len); + } else { + return false; + } + begin = iter; + } + return false; + } + template void parse_body(Delegate& delegate_, Callback callback, size_t bytes) { // TODO(dberris): we should really not use a string for the partial body // buffer. - partial_parsed.append(part_begin, bytes); + auto it = part_begin; + std::advance(it, bytes); + partial_parsed.append(part_begin, it); part_begin = part.begin(); - delegate_->read_some( - asio::mutable_buffers_1(part.data(), part.size()), callback); + if (check_parse_body_complete()) { + callback(boost::asio::error::eof, 0); + } else { + delegate_->read_some( + boost::asio::mutable_buffers_1(part.data(), part.size()), callback); + } } typedef response_parser response_parser_type; - // TODO(dberris): make 1024 go away and become a configurable value. - typedef std::array::type, 1024> buffer_type; + typedef std::array::type, + BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE> buffer_type; response_parser_type response_parser_; - std::promise version_promise; - std::promise status_promise; - std::promise status_message_promise; - std::promise::type> headers_promise; - std::promise source_promise; - std::promise destination_promise; - std::promise body_promise; + boost::promise version_promise; + boost::promise status_promise; + boost::promise status_message_promise; + boost::promise::type> headers_promise; + boost::promise source_promise; + boost::promise destination_promise; + boost::promise body_promise; buffer_type part; typename buffer_type::const_iterator part_begin; string_type partial_parsed; bool is_chunk_encoding; + bool is_chunk_end; + bool is_content_length; + long long unsigned content_length; }; } // namespace impl diff --git a/boost/network/protocol/http/client/connection/connection_delegate.hpp b/boost/network/protocol/http/client/connection/connection_delegate.hpp index fb18a04a1..6bbf4d32c 100644 --- a/boost/network/protocol/http/client/connection/connection_delegate.hpp +++ b/boost/network/protocol/http/client/connection/connection_delegate.hpp @@ -9,8 +9,9 @@ #include #include -#include -#include +#include +#include +#include namespace boost { namespace network { @@ -18,15 +19,15 @@ namespace http { namespace impl { struct connection_delegate { - virtual void connect(asio::ip::tcp::endpoint &endpoint, std::string host, - std::uint16_t source_port, - std::function handler) = 0; + virtual void connect(boost::asio::ip::tcp::endpoint &endpoint, std::string host, + std::uint16_t source_port, optional sni_hostname, + std::function handler) = 0; virtual void write( - asio::streambuf &command_streambuf, - std::function handler) = 0; + boost::asio::streambuf &command_streambuf, + std::function handler) = 0; virtual void read_some( - asio::mutable_buffers_1 const &read_buffer, - std::function handler) = 0; + boost::asio::mutable_buffers_1 const &read_buffer, + std::function handler) = 0; virtual void disconnect() = 0; virtual ~connection_delegate() = default; }; diff --git a/boost/network/protocol/http/client/connection/connection_delegate_factory.hpp b/boost/network/protocol/http/client/connection/connection_delegate_factory.hpp index 7a78002e5..fa419e1e6 100644 --- a/boost/network/protocol/http/client/connection/connection_delegate_factory.hpp +++ b/boost/network/protocol/http/client/connection/connection_delegate_factory.hpp @@ -34,7 +34,7 @@ struct connection_delegate_factory { // This is the factory method that actually returns the delegate instance. // TODO(dberris): Support passing in proxy settings when crafting connections. static connection_delegate_ptr new_connection_delegate( - asio::io_service& service, bool https, bool always_verify_peer, + boost::asio::io_service& service, bool https, bool always_verify_peer, optional certificate_filename, optional verify_path, optional certificate_file, optional private_key_file, optional ciphers, diff --git a/boost/network/protocol/http/client/connection/normal_delegate.hpp b/boost/network/protocol/http/client/connection/normal_delegate.hpp index eb8b43a69..24955cd05 100644 --- a/boost/network/protocol/http/client/connection/normal_delegate.hpp +++ b/boost/network/protocol/http/client/connection/normal_delegate.hpp @@ -10,10 +10,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include namespace boost { @@ -22,16 +22,16 @@ namespace http { namespace impl { struct normal_delegate : connection_delegate { - explicit normal_delegate(asio::io_service &service); + explicit normal_delegate(boost::asio::io_service &service); - void connect(asio::ip::tcp::endpoint &endpoint, std::string host, - std::uint16_t source_port, - std::function handler) override; - void write(asio::streambuf &command_streambuf, - std::function handler) + void connect(boost::asio::ip::tcp::endpoint &endpoint, std::string host, + std::uint16_t source_port, optional sni_hostname, + std::function handler) override; + void write(boost::asio::streambuf &command_streambuf, + std::function handler) override; - void read_some(asio::mutable_buffers_1 const &read_buffer, - std::function handler) + void read_some(boost::asio::mutable_buffers_1 const &read_buffer, + std::function handler) override; void disconnect() override; ~normal_delegate() override = default; @@ -40,8 +40,8 @@ struct normal_delegate : connection_delegate { normal_delegate &operator=(normal_delegate) = delete; private: - asio::io_service &service_; - std::unique_ptr socket_; + boost::asio::io_service &service_; + std::unique_ptr socket_; }; } // namespace impl diff --git a/boost/network/protocol/http/client/connection/normal_delegate.ipp b/boost/network/protocol/http/client/connection/normal_delegate.ipp index 091313c99..027f04a8c 100644 --- a/boost/network/protocol/http/client/connection/normal_delegate.ipp +++ b/boost/network/protocol/http/client/connection/normal_delegate.ipp @@ -9,46 +9,46 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include boost::network::http::impl::normal_delegate::normal_delegate( - asio::io_service &service) + boost::asio::io_service &service) : service_(service) {} void boost::network::http::impl::normal_delegate::connect( - asio::ip::tcp::endpoint &endpoint, std::string host, - std::uint16_t source_port, - std::function handler) { + boost::asio::ip::tcp::endpoint &endpoint, std::string host, + std::uint16_t source_port, optional sni_hostname, + std::function handler) { // TODO(dberris): review parameter necessity. (void)host; - socket_.reset(new asio::ip::tcp::socket( + socket_.reset(new boost::asio::ip::tcp::socket( service_, - asio::ip::tcp::endpoint(asio::ip::address(), source_port))); + boost::asio::ip::tcp::endpoint(boost::asio::ip::address(), source_port))); socket_->async_connect(endpoint, handler); } void boost::network::http::impl::normal_delegate::write( - asio::streambuf &command_streambuf, - std::function handler) { - asio::async_write(*socket_, command_streambuf, handler); + boost::asio::streambuf &command_streambuf, + std::function handler) { + boost::asio::async_write(*socket_, command_streambuf, handler); } void boost::network::http::impl::normal_delegate::read_some( - asio::mutable_buffers_1 const &read_buffer, - std::function handler) { + boost::asio::mutable_buffers_1 const &read_buffer, + std::function handler) { socket_->async_read_some(read_buffer, handler); } void boost::network::http::impl::normal_delegate::disconnect() { if (socket_.get() && socket_->is_open()) { - std::error_code ignored; - socket_->shutdown(asio::ip::tcp::socket::shutdown_both, ignored); + boost::system::error_code ignored; + socket_->shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored); if (!ignored) { socket_->close(ignored); } diff --git a/boost/network/protocol/http/client/connection/ssl_delegate.hpp b/boost/network/protocol/http/client/connection/ssl_delegate.hpp index 0916af235..6ad298dcb 100644 --- a/boost/network/protocol/http/client/connection/ssl_delegate.hpp +++ b/boost/network/protocol/http/client/connection/ssl_delegate.hpp @@ -10,8 +10,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -24,7 +24,7 @@ namespace impl { struct ssl_delegate : public connection_delegate, public std::enable_shared_from_this { - ssl_delegate(asio::io_service &service, bool always_verify_peer, + ssl_delegate(boost::asio::io_service &service, bool always_verify_peer, optional certificate_filename, optional verify_path, optional certificate_file, @@ -32,20 +32,20 @@ struct ssl_delegate : public connection_delegate, optional ciphers, optional sni_hostname, long ssl_options); - void connect(asio::ip::tcp::endpoint &endpoint, std::string host, - std::uint16_t source_port, - std::function handler) override; + void connect(boost::asio::ip::tcp::endpoint &endpoint, std::string host, + std::uint16_t source_port, optional sni_hostname, + std::function handler) override; void write( - asio::streambuf &command_streambuf, - std::function handler) override; + boost::asio::streambuf &command_streambuf, + std::function handler) override; void read_some( - asio::mutable_buffers_1 const &read_buffer, - std::function handler) override; + boost::asio::mutable_buffers_1 const &read_buffer, + std::function handler) override; void disconnect() override; ~ssl_delegate() override; private: - asio::io_service &service_; + boost::asio::io_service &service_; optional certificate_filename_; optional verify_path_; optional certificate_file_; @@ -53,16 +53,16 @@ struct ssl_delegate : public connection_delegate, optional ciphers_; optional sni_hostname_; long ssl_options_; - std::unique_ptr context_; - std::unique_ptr tcp_socket_; - std::unique_ptr > socket_; + std::unique_ptr context_; + std::unique_ptr tcp_socket_; + std::unique_ptr > socket_; bool always_verify_peer_; ssl_delegate(ssl_delegate const &); // = delete ssl_delegate &operator=(ssl_delegate); // = delete - void handle_connected(std::error_code const &ec, - std::function handler); + void handle_connected(boost::system::error_code const &ec, + std::function handler); }; } // namespace impl diff --git a/boost/network/protocol/http/client/connection/ssl_delegate.ipp b/boost/network/protocol/http/client/connection/ssl_delegate.ipp index b303a24de..7575b12b4 100644 --- a/boost/network/protocol/http/client/connection/ssl_delegate.ipp +++ b/boost/network/protocol/http/client/connection/ssl_delegate.ipp @@ -9,11 +9,11 @@ #include #include -#include +#include #include boost::network::http::impl::ssl_delegate::ssl_delegate( - asio::io_service &service, bool always_verify_peer, + boost::asio::io_service &service, bool always_verify_peer, optional certificate_filename, optional verify_path, optional certificate_file, optional private_key_file, optional ciphers, @@ -29,11 +29,12 @@ boost::network::http::impl::ssl_delegate::ssl_delegate( always_verify_peer_(always_verify_peer) {} void boost::network::http::impl::ssl_delegate::connect( - asio::ip::tcp::endpoint &endpoint, std::string host, - std::uint16_t source_port, - std::function handler) { + boost::asio::ip::tcp::endpoint &endpoint, std::string host, + std::uint16_t source_port, optional sni_hostname, + std::function handler) { + context_.reset( - new asio::ssl::context(asio::ssl::context::method::sslv23_client)); + new boost::asio::ssl::context(boost::asio::ssl::context::method::sslv23_client)); if (ciphers_) { ::SSL_CTX_set_cipher_list(context_->native_handle(), ciphers_->c_str()); } @@ -41,69 +42,77 @@ void boost::network::http::impl::ssl_delegate::connect( context_->set_options(ssl_options_); } else { // By default, disable v3 support. - context_->set_options(asio::ssl::context::no_sslv3); + context_->set_options(boost::asio::ssl::context::no_sslv3); } if (certificate_filename_ || verify_path_) { - context_->set_verify_mode(asio::ssl::context::verify_peer); + context_->set_verify_mode(boost::asio::ssl::context::verify_peer); if (certificate_filename_) context_->load_verify_file(*certificate_filename_); if (verify_path_) context_->add_verify_path(*verify_path_); } else { if (always_verify_peer_) { - context_->set_verify_mode(asio::ssl::context::verify_peer); + context_->set_verify_mode(boost::asio::ssl::context::verify_peer); // use openssl default verify paths. uses openssl environment variables // SSL_CERT_DIR, SSL_CERT_FILE context_->set_default_verify_paths(); } else { - context_->set_verify_mode(asio::ssl::context::verify_none); + context_->set_verify_mode(boost::asio::ssl::context::verify_none); } } if (certificate_file_) - context_->use_certificate_file(*certificate_file_, asio::ssl::context::pem); + context_->use_certificate_file(*certificate_file_, boost::asio::ssl::context::pem); if (private_key_file_) - context_->use_private_key_file(*private_key_file_, asio::ssl::context::pem); + context_->use_private_key_file(*private_key_file_, boost::asio::ssl::context::pem); - tcp_socket_.reset(new asio::ip::tcp::socket( - service_, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), source_port))); - socket_.reset(new asio::ssl::stream( + tcp_socket_.reset(new boost::asio::ip::tcp::socket( + service_, boost::asio::ip::tcp::endpoint(endpoint.address().is_v4() + ? boost::asio::ip::tcp::v4() + : boost::asio::ip::tcp::v6(), + source_port))); + socket_.reset(new boost::asio::ssl::stream( *(tcp_socket_.get()), *context_)); - if (sni_hostname_) + if (sni_hostname) { // at request level + SSL_set_tlsext_host_name(socket_->native_handle(), sni_hostname->c_str()); + } else if (sni_hostname_) { // at client level SSL_set_tlsext_host_name(socket_->native_handle(), sni_hostname_->c_str()); + } + + if (always_verify_peer_) - socket_->set_verify_callback(asio::ssl::rfc2818_verification(host)); + socket_->set_verify_callback(boost::asio::ssl::rfc2818_verification(host)); auto self = this->shared_from_this(); socket_->lowest_layer().async_connect( endpoint, - [=](std::error_code const &ec) { self->handle_connected(ec, handler); }); + [=](boost::system::error_code const &ec) { self->handle_connected(ec, handler); }); } void boost::network::http::impl::ssl_delegate::handle_connected( - std::error_code const &ec, - std::function handler) { + boost::system::error_code const &ec, + std::function handler) { if (!ec) { - socket_->async_handshake(asio::ssl::stream_base::client, handler); + socket_->async_handshake(boost::asio::ssl::stream_base::client, handler); } else { handler(ec); } } void boost::network::http::impl::ssl_delegate::write( - asio::streambuf &command_streambuf, - std::function handler) { - asio::async_write(*socket_, command_streambuf, handler); + boost::asio::streambuf &command_streambuf, + std::function handler) { + boost::asio::async_write(*socket_, command_streambuf, handler); } void boost::network::http::impl::ssl_delegate::read_some( - asio::mutable_buffers_1 const &read_buffer, - std::function handler) { + boost::asio::mutable_buffers_1 const &read_buffer, + std::function handler) { socket_->async_read_some(read_buffer, handler); } void boost::network::http::impl::ssl_delegate::disconnect() { if (socket_.get() && socket_->lowest_layer().is_open()) { - std::error_code ignored; - socket_->lowest_layer().shutdown(asio::ip::tcp::socket::shutdown_both, + boost::system::error_code ignored; + socket_->lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored); if (!ignored) { socket_->lowest_layer().close(ignored); diff --git a/boost/network/protocol/http/client/connection/sync_base.hpp b/boost/network/protocol/http/client/connection/sync_base.hpp index 4d940c334..efe488c11 100644 --- a/boost/network/protocol/http/client/connection/sync_base.hpp +++ b/boost/network/protocol/http/client/connection/sync_base.hpp @@ -8,10 +8,10 @@ // http://www.boost.org/LICENSE_1_0.txt) #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include @@ -41,8 +41,8 @@ struct sync_connection_base_impl { void init_socket(Socket& socket_, resolver_type& resolver_, string_type /*unused*/ const& hostname, string_type const& port, resolver_function_type resolve_) { - using asio::ip::tcp; - std::error_code error = asio::error::host_not_found; + using boost::asio::ip::tcp; + boost::system::error_code error = boost::asio::error::host_not_found; typename resolver_type::iterator endpoint_iterator, end; boost::tie(endpoint_iterator, end) = resolve_(resolver_, hostname, port); while (error && endpoint_iterator != end) { @@ -53,13 +53,13 @@ struct sync_connection_base_impl { ++endpoint_iterator; } - if (error) throw std::system_error(error); + if (error) throw boost::system::system_error(error); } template void read_status(Socket& socket_, basic_response& response_, - asio::streambuf& response_buffer) { - asio::read_until(socket_, response_buffer, "\r\n"); + boost::asio::streambuf& response_buffer) { + boost::asio::read_until(socket_, response_buffer, "\r\n"); std::istream response_stream(&response_buffer); string_type http_version; unsigned int status_code; @@ -78,8 +78,8 @@ struct sync_connection_base_impl { template void read_headers(Socket& socket_, basic_response& response_, - asio::streambuf& response_buffer) { - asio::read_until(socket_, response_buffer, "\r\n\r\n"); + boost::asio::streambuf& response_buffer) { + boost::asio::read_until(socket_, response_buffer, "\r\n\r\n"); std::istream response_stream(&response_buffer); string_type header_line, name; while (std::getline(response_stream, header_line) && header_line != "\r") { @@ -101,7 +101,7 @@ struct sync_connection_base_impl { template void send_request_impl(Socket& socket_, string_type /*unused*/ const& method, - asio::streambuf& request_buffer) { + boost::asio::streambuf& request_buffer) { // TODO(dberris): review parameter necessity. (void)method; @@ -110,15 +110,15 @@ struct sync_connection_base_impl { template void read_body_normal(Socket& socket_, basic_response& response_, - asio::streambuf& response_buffer, + boost::asio::streambuf& response_buffer, typename ostringstream::type& body_stream) { // TODO(dberris): review parameter necessity. (void)response_; - std::error_code error; + boost::system::error_code error; if (response_buffer.size() > 0) body_stream << &response_buffer; - while (asio::read(socket_, response_buffer, asio::transfer_at_least(1), + while (boost::asio::read(socket_, response_buffer, boost::asio::transfer_at_least(1), error)) { body_stream << &response_buffer; } @@ -127,9 +127,9 @@ struct sync_connection_base_impl { template void read_body_transfer_chunk_encoding( Socket& socket_, basic_response& response_, - asio::streambuf& response_buffer, + boost::asio::streambuf& response_buffer, typename ostringstream::type& body_stream) { - std::error_code error; + boost::system::error_code error; // look for the content-length header typename headers_range >::type content_length_range = headers(response_)["Content-Length"]; @@ -146,8 +146,8 @@ struct sync_connection_base_impl { do { std::size_t chunk_size_line = read_until(socket_, response_buffer, "\r\n", error); - if ((chunk_size_line == 0) && (error != asio::error::eof)) - throw std::system_error(error); + if ((chunk_size_line == 0) && (error != boost::asio::error::eof)) + throw boost::system::system_error(error); std::size_t chunk_size = 0; string_type data; { @@ -159,8 +159,8 @@ struct sync_connection_base_impl { if (chunk_size == 0) { stopping = true; if (!read_until(socket_, response_buffer, "\r\n", error) && - (error != asio::error::eof)) - throw std::system_error(error); + (error != boost::asio::error::eof)) + throw boost::system::system_error(error); } else { bool stopping_inner = false; do { @@ -169,9 +169,9 @@ struct sync_connection_base_impl { (chunk_size + 2) - response_buffer.size(); std::size_t chunk_bytes_read = read(socket_, response_buffer, - asio::transfer_at_least(bytes_to_read), error); + boost::asio::transfer_at_least(bytes_to_read), error); if (chunk_bytes_read == 0) { - if (error != asio::error::eof) throw std::system_error(error); + if (error != boost::asio::error::eof) throw boost::system::system_error(error); stopping_inner = true; } } @@ -200,8 +200,8 @@ struct sync_connection_base_impl { return; } size_t bytes_read = 0; - while ((bytes_read = asio::read(socket_, response_buffer, - asio::transfer_at_least(1), error))) { + while ((bytes_read = boost::asio::read(socket_, response_buffer, + boost::asio::transfer_at_least(1), error))) { body_stream << &response_buffer; length -= bytes_read; if ((length <= 0) || error) break; @@ -211,7 +211,7 @@ struct sync_connection_base_impl { template void read_body(Socket& socket_, basic_response& response_, - asio::streambuf& response_buffer) { + boost::asio::streambuf& response_buffer) { typename ostringstream::type body_stream; // TODO(dberris): tag dispatch based on whether it's HTTP 1.0 or HTTP 1.1 if (version_major == 1 && version_minor == 0) { @@ -282,11 +282,11 @@ struct sync_connection_base { basic_request const& request_, body_generator_function_type generator) = 0; virtual void read_status(basic_response& response_, - asio::streambuf& response_buffer) = 0; + boost::asio::streambuf& response_buffer) = 0; virtual void read_headers(basic_response& response_, - asio::streambuf& response_buffer) = 0; + boost::asio::streambuf& response_buffer) = 0; virtual void read_body(basic_response& response_, - asio::streambuf& response_buffer) = 0; + boost::asio::streambuf& response_buffer) = 0; virtual bool is_open() = 0; virtual void close_socket() = 0; virtual ~sync_connection_base() = default; diff --git a/boost/network/protocol/http/client/connection/sync_normal.hpp b/boost/network/protocol/http/client/connection/sync_normal.hpp index 27e1e1cc6..1f3775474 100644 --- a/boost/network/protocol/http/client/connection/sync_normal.hpp +++ b/boost/network/protocol/http/client/connection/sync_normal.hpp @@ -10,8 +10,8 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -61,7 +61,7 @@ struct http_sync_connection void send_request_impl(string_type const& method, basic_request const& request_, body_generator_function_type generator) { - asio::streambuf request_buffer; + boost::asio::streambuf request_buffer; linearize( request_, method, version_major, version_minor, std::ostreambuf_iterator::type>(&request_buffer)); @@ -77,26 +77,26 @@ struct http_sync_connection } } if (timeout_ > 0) { - timer_.expires_from_now(boost::posix_time::seconds(timeout_)); + timer_.expires_from_now(std::chrono::seconds(timeout_)); auto self = this->shared_from_this(); - timer_.async_wait([=] (std::error_code const &ec) { + timer_.async_wait([=] (boost::system::error_code const &ec) { self->handle_timeout(ec); }); } } void read_status(basic_response& response_, - asio::streambuf& response_buffer) { + boost::asio::streambuf& response_buffer) { connection_base::read_status(socket_, response_, response_buffer); } void read_headers(basic_response& response, - asio::streambuf& response_buffer) { + boost::asio::streambuf& response_buffer) { connection_base::read_headers(socket_, response, response_buffer); } void read_body(basic_response& response_, - asio::streambuf& response_buffer) { + boost::asio::streambuf& response_buffer) { connection_base::read_body(socket_, response_, response_buffer); typename headers_range >::type connection_range = headers(response_)["Connection"]; @@ -116,8 +116,8 @@ struct http_sync_connection if (!is_open()) { return; } - std::error_code ignored; - socket_.shutdown(asio::ip::tcp::socket::shutdown_both, ignored); + boost::system::error_code ignored; + socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored); if (ignored) { return; } @@ -125,17 +125,17 @@ struct http_sync_connection } private: - void handle_timeout(std::error_code const& ec) { + void handle_timeout(boost::system::error_code const& ec) { if (!ec) { close_socket(); } } int timeout_; - asio::deadline_timer timer_; + boost::asio::steady_timer timer_; resolver_type& resolver_; resolver_function_type resolve_; - asio::ip::tcp::socket socket_; + boost::asio::ip::tcp::socket socket_; }; } // namespace impl diff --git a/boost/network/protocol/http/client/connection/sync_ssl.hpp b/boost/network/protocol/http/client/connection/sync_ssl.hpp index d973fc0d6..349449512 100644 --- a/boost/network/protocol/http/client/connection/sync_ssl.hpp +++ b/boost/network/protocol/http/client/connection/sync_ssl.hpp @@ -9,10 +9,10 @@ // http://www.boost.org/LICENSE_1_0.txt) #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include @@ -63,7 +63,7 @@ struct https_sync_connection timer_(resolver.get_io_service()), resolver_(resolver), resolve_(std::move(resolve)), - context_(resolver.get_io_service(), asio::ssl::context::sslv23_client), + context_(resolver.get_io_service(), boost::asio::ssl::context::sslv23_client), socket_(resolver.get_io_service(), context_) { if (ciphers) { ::SSL_CTX_set_cipher_list(context_.native_handle(), ciphers->c_str()); @@ -72,7 +72,7 @@ struct https_sync_connection context_.set_options(ssl_options); } if (certificate_filename || verify_path) { - context_.set_verify_mode(asio::ssl::context::verify_peer); + context_.set_verify_mode(boost::asio::ssl::context::verify_peer); // FIXME make the certificate filename and verify path parameters // be // optional ranges @@ -81,14 +81,14 @@ struct https_sync_connection if (verify_path) context_.add_verify_path(*verify_path); } else { if (always_verify_peer) - context_.set_verify_mode(asio::ssl::context_base::verify_peer); + context_.set_verify_mode(boost::asio::ssl::context_base::verify_peer); else - context_.set_verify_mode(asio::ssl::context_base::verify_none); + context_.set_verify_mode(boost::asio::ssl::context_base::verify_none); } if (certificate_file) - context_.use_certificate_file(*certificate_file, asio::ssl::context::pem); + context_.use_certificate_file(*certificate_file, boost::asio::ssl::context::pem); if (private_key_file) - context_.use_private_key_file(*private_key_file, asio::ssl::context::pem); + context_.use_private_key_file(*private_key_file, boost::asio::ssl::context::pem); if (sni_hostname) SSL_set_tlsext_host_name(socket_.native_handle(), sni_hostname->c_str()); } @@ -97,13 +97,13 @@ struct https_sync_connection string_type const& port) { connection_base::init_socket(socket_.lowest_layer(), resolver_, hostname, port, resolve_); - socket_.handshake(asio::ssl::stream_base::client); + socket_.handshake(boost::asio::ssl::stream_base::client); } void send_request_impl(string_type /*unused*/ const& method, basic_request const& request_, body_generator_function_type generator) { - asio::streambuf request_buffer; + boost::asio::streambuf request_buffer; linearize( request_, method, version_major, version_minor, std::ostreambuf_iterator::type>(&request_buffer)); @@ -119,25 +119,25 @@ struct https_sync_connection } } if (timeout_ > 0) { - timer_.expires_from_now(boost::posix_time::seconds(timeout_)); + timer_.expires_from_now(std::chrono::seconds(timeout_)); auto self = this->shared_from_this(); timer_.async_wait( - [=](std::error_code const& ec) { self->handle_timeout(ec); }); + [=](boost::system::error_code const& ec) { self->handle_timeout(ec); }); } } void read_status(basic_response& response_, - asio::streambuf& response_buffer) { + boost::asio::streambuf& response_buffer) { connection_base::read_status(socket_, response_, response_buffer); } void read_headers(basic_response& response_, - asio::streambuf& response_buffer) { + boost::asio::streambuf& response_buffer) { connection_base::read_headers(socket_, response_, response_buffer); } void read_body(basic_response& response_, - asio::streambuf& response_buffer) { + boost::asio::streambuf& response_buffer) { connection_base::read_body(socket_, response_, response_buffer); typename headers_range >::type connection_range = headers(response_)["Connection"]; @@ -154,8 +154,8 @@ struct https_sync_connection void close_socket() { timer_.cancel(); - std::error_code ignored; - socket_.lowest_layer().shutdown(asio::ip::tcp::socket::shutdown_both, + boost::system::error_code ignored; + socket_.lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored); if (ignored) { return; @@ -166,18 +166,18 @@ struct https_sync_connection ~https_sync_connection() { close_socket(); } private: - void handle_timeout(std::error_code const& ec) { + void handle_timeout(boost::system::error_code const& ec) { if (!ec) { close_socket(); } } int timeout_; - asio::deadline_timer timer_; + boost::asio::steady_timer timer_; resolver_type& resolver_; resolver_function_type resolve_; - asio::ssl::context context_; - asio::ssl::stream socket_; + boost::asio::ssl::context context_; + boost::asio::ssl::stream socket_; }; } // namespace impl diff --git a/boost/network/protocol/http/client/facade.hpp b/boost/network/protocol/http/client/facade.hpp index ff05d078b..bfe498060 100644 --- a/boost/network/protocol/http/client/facade.hpp +++ b/boost/network/protocol/http/client/facade.hpp @@ -40,13 +40,19 @@ class basic_client_facade { /** The response type. This models the HTTP Response concept.*/ typedef basic_response response; + typedef + typename std::array::type, + BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE>:: + const_iterator const_iterator; + typedef iterator_range char_const_range; + /** * This callback is invoked with a range representing part of the response's * body as it comes in. In case of errors, the second argument is an error * code. */ - typedef std::function const&, - std::error_code const&)> + typedef std::function body_callback_function_type; /** @@ -128,7 +134,7 @@ class basic_client_facade { } else { if (boost::empty(content_type_headers)) { typedef typename char_::type char_type; - static char_type content_type[] = "x-application/octet-stream"; + static char_type const content_type[] = "x-application/octet-stream"; request << header("Content-Type", content_type); } } @@ -233,7 +239,7 @@ class basic_client_facade { } else { if (boost::empty(content_type_headers)) { typedef typename char_::type char_type; - static char_type content_type[] = "x-application/octet-stream"; + static char_type const content_type[] = "x-application/octet-stream"; request << header("Content-Type", content_type); } } @@ -309,7 +315,8 @@ class basic_client_facade { options.openssl_verify_path(), options.openssl_certificate_file(), options.openssl_private_key_file(), options.openssl_ciphers(), options.openssl_sni_hostname(), options.openssl_options(), - options.io_service(), options.timeout())); + options.io_service(), options.timeout(), + options.remove_chunk_markers())); } }; diff --git a/boost/network/protocol/http/client/macros.hpp b/boost/network/protocol/http/client/macros.hpp index 81135f548..8be4028bd 100644 --- a/boost/network/protocol/http/client/macros.hpp +++ b/boost/network/protocol/http/client/macros.hpp @@ -7,13 +7,24 @@ // http://www.boost.org/LICENSE_1_0.txt) #include +#include #include +#ifndef BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE +/** + * We define the buffer size for each connection that we will use on the client + * side. + */ +#define BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE 4096uL +#endif + #ifndef BOOST_NETWORK_HTTP_BODY_CALLBACK -#define BOOST_NETWORK_HTTP_BODY_CALLBACK(function_name, range_name, \ - error_name) \ - void function_name(boost::iterator_range const& (range_name), \ - std::error_code const& (error_name)) +#define BOOST_NETWORK_HTTP_BODY_CALLBACK(function_name, range_name, error_name)\ + void function_name( \ + boost::iterator_range< \ + std::array:: \ + const_iterator>(range_name), \ + boost::system::error_code const&(error_name)) #endif #endif /* BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_MACROS_HPP_20110430 */ diff --git a/boost/network/protocol/http/client/options.hpp b/boost/network/protocol/http/client/options.hpp index 2c109a88d..afc265abd 100644 --- a/boost/network/protocol/http/client/options.hpp +++ b/boost/network/protocol/http/client/options.hpp @@ -8,7 +8,7 @@ // http://www.boost.org/LICENSE_1_0.txt) #include -#include +#include #include #include @@ -34,7 +34,8 @@ class client_options { openssl_options_(0), io_service_(), always_verify_peer_(true), - timeout_(0) {} + timeout_(0), + remove_chunk_markers_(true) {} client_options(client_options const& other) : cache_resolved_(other.cache_resolved_), @@ -48,7 +49,8 @@ class client_options { openssl_options_(other.openssl_options_), io_service_(other.io_service_), always_verify_peer_(other.always_verify_peer_), - timeout_(other.timeout_) {} + timeout_(other.timeout_), + remove_chunk_markers_(other.remove_chunk_markers_) {} client_options& operator=(client_options other) { other.swap(*this); @@ -69,6 +71,7 @@ class client_options { swap(io_service_, other.io_service_); swap(always_verify_peer_, other.always_verify_peer_); swap(timeout_, other.timeout_); + swap(remove_chunk_markers_, other.remove_chunk_markers_); } /// Specify whether the client should cache resolved endpoints. @@ -91,39 +94,39 @@ class client_options { /// Set the filename of the certificate to load for the SSL connection for /// verification. client_options& openssl_certificate(string_type const& v) { - openssl_certificate_ = v; + openssl_certificate_ = make_optional(v); return *this; } /// Set the directory for which the certificate authority files are located. client_options& openssl_verify_path(string_type const& v) { - openssl_verify_path_ = v; + openssl_verify_path_ = make_optional(v); return *this; } /// Set the filename of the certificate to use for client-side SSL session /// establishment. client_options& openssl_certificate_file(string_type const& v) { - openssl_certificate_file_ = v; + openssl_certificate_file_ = make_optional(v); return *this; } /// Set the filename of the private key to use for client-side SSL session /// establishment. client_options& openssl_private_key_file(string_type const& v) { - openssl_private_key_file_ = v; + openssl_private_key_file_ = make_optional(v); return *this; } /// Set the ciphers to support for SSL negotiation. client_options& openssl_ciphers(string_type const& v) { - openssl_ciphers_ = v; + openssl_ciphers_ = make_optional(v); return *this; } /// Set the hostname for SSL SNI hostname support. client_options& openssl_sni_hostname(string_type const& v) { - openssl_sni_hostname_ = v; + openssl_sni_hostname_ = make_optional(v); return *this; } @@ -133,8 +136,8 @@ class client_options { return *this; } - /// Provide an `asio::io_service` hosted in a shared pointer. - client_options& io_service(std::shared_ptr v) { + /// Provide an `boost::asio::io_service` hosted in a shared pointer. + client_options& io_service(std::shared_ptr v) { io_service_ = v; return *this; } @@ -154,6 +157,12 @@ class client_options { return *this; } + /// Set whether we process chunked-encoded streams. + client_options& remove_chunk_markers(bool v) { + remove_chunk_markers_ = v; + return *this; + } + bool cache_resolved() const { return cache_resolved_; } bool follow_redirects() const { return follow_redirects_; } @@ -184,12 +193,14 @@ class client_options { long openssl_options() const { return openssl_options_; } - std::shared_ptr io_service() const { return io_service_; } + std::shared_ptr io_service() const { return io_service_; } bool always_verify_peer() const { return always_verify_peer_; } int timeout() const { return timeout_; } + bool remove_chunk_markers() const { return remove_chunk_markers_; } + private: bool cache_resolved_; bool follow_redirects_; @@ -200,9 +211,10 @@ class client_options { boost::optional openssl_ciphers_; boost::optional openssl_sni_hostname_; long openssl_options_; - std::shared_ptr io_service_; + std::shared_ptr io_service_; bool always_verify_peer_; int timeout_; + bool remove_chunk_markers_; }; template diff --git a/boost/network/protocol/http/client/pimpl.hpp b/boost/network/protocol/http/client/pimpl.hpp index 2f7f28c67..01c77ca70 100644 --- a/boost/network/protocol/http/client/pimpl.hpp +++ b/boost/network/protocol/http/client/pimpl.hpp @@ -7,7 +7,7 @@ // http://www.boost.org/LICENSE_1_0.txt) #include -#include +#include #include #include #include @@ -74,10 +74,12 @@ struct basic_client_impl optional const& private_key_file, optional const& ciphers, optional const& sni_hostname, long ssl_options, - std::shared_ptr service, int timeout) - : base_type(cache_resolved, follow_redirect, always_verify_peer, timeout, - service, certificate_filename, verify_path, certificate_file, - private_key_file, ciphers, sni_hostname, ssl_options) {} + std::shared_ptr service, int timeout, + bool remove_chunk_markers) + : base_type(cache_resolved, follow_redirect, always_verify_peer, timeout, + remove_chunk_markers, service, certificate_filename, verify_path, + certificate_file, private_key_file, ciphers, sni_hostname, + ssl_options) {} ~basic_client_impl() = default; }; diff --git a/boost/network/protocol/http/client/sync_impl.hpp b/boost/network/protocol/http/client/sync_impl.hpp index 4f07446f5..354dfd3eb 100644 --- a/boost/network/protocol/http/client/sync_impl.hpp +++ b/boost/network/protocol/http/client/sync_impl.hpp @@ -32,13 +32,13 @@ struct sync_client connection_base; typedef typename resolver::type resolver_type; typedef std::function const&, - std::error_code const&)> + boost::system::error_code const&)> body_callback_function_type; typedef std::function body_generator_function_type; friend struct basic_client_impl; - std::shared_ptr service_ptr; - asio::io_service& service_; + std::shared_ptr service_ptr; + boost::asio::io_service& service_; resolver_type resolver_; optional certificate_filename_; optional verify_path_; @@ -51,7 +51,7 @@ struct sync_client sync_client( bool cache_resolved, bool follow_redirect, bool always_verify_peer, - int timeout, std::shared_ptr service, + int timeout, std::shared_ptr service, optional certificate_filename = optional(), optional verify_path = optional(), optional certificate_file = optional(), @@ -61,7 +61,7 @@ struct sync_client long ssl_options = 0) : connection_base(cache_resolved, follow_redirect, timeout), service_ptr(service.get() ? service - : std::make_shared()), + : std::make_shared()), service_(*service_ptr), resolver_(service_), certificate_filename_(std::move(certificate_filename)), diff --git a/boost/network/protocol/http/impl/request.hpp b/boost/network/protocol/http/impl/request.hpp index 85ab0f3ae..04d0b8562 100644 --- a/boost/network/protocol/http/impl/request.hpp +++ b/boost/network/protocol/http/impl/request.hpp @@ -50,29 +50,32 @@ namespace http { */ template struct basic_request : public basic_message { - mutable boost::network::uri::uri uri_; - std::uint16_t source_port_; - typedef basic_message base_type; - public: typedef Tag tag; typedef typename string::type string_type; typedef std::uint16_t port_type; + private: + mutable boost::network::uri::uri uri_; + std::uint16_t source_port_; + optional sni_hostname_; + typedef basic_message base_type; + + public: explicit basic_request(string_type const& uri_) - : uri_(uri_), source_port_(0) {} + : uri_(uri_), source_port_(0), sni_hostname_() {} explicit basic_request(boost::network::uri::uri const& uri_) - : uri_(uri_), source_port_(0) {} + : uri_(uri_), source_port_(0), sni_hostname_() {} void uri(string_type const& new_uri) { uri_ = new_uri; } void uri(boost::network::uri::uri const& new_uri) { uri_ = new_uri; } - basic_request() : base_type(), source_port_(0) {} + basic_request() : base_type(), source_port_(0), sni_hostname_() {} basic_request(basic_request const& other) - : base_type(other), uri_(other.uri_), source_port_(other.source_port_) {} + : base_type(other), uri_(other.uri_), source_port_(other.source_port_), sni_hostname_(other.sni_hostname_) {} basic_request& operator=(basic_request rhs) { rhs.swap(*this); @@ -85,6 +88,7 @@ struct basic_request : public basic_message { base_ref.swap(this_ref); boost::swap(other.uri_, this->uri_); boost::swap(other.source_port_, this->source_port_); + boost::swap(other.sni_hostname_, this->sni_hostname_); } string_type const host() const { return uri_.host(); } @@ -114,6 +118,10 @@ struct basic_request : public basic_message { void source_port(const std::uint16_t port) { source_port_ = port; } std::uint16_t source_port() const { return source_port_; } + + void sni_hostname(string_type const &sni_hostname) { sni_hostname_ = sni_hostname; } + + const optional &sni_hostname() const { return sni_hostname_; } }; /** This is the implementation of a POD request type diff --git a/boost/network/protocol/http/impl/response.ipp b/boost/network/protocol/http/impl/response.ipp index 24055776c..a685a2169 100644 --- a/boost/network/protocol/http/impl/response.ipp +++ b/boost/network/protocol/http/impl/response.ipp @@ -16,7 +16,7 @@ #ifndef BOOST_NETWORK_PROTOCOL_HTTP_IMPL_RESPONSE_RESPONSE_IPP #define BOOST_NETWORK_PROTOCOL_HTTP_IMPL_RESPONSE_RESPONSE_IPP -#include +#include #include #include #include @@ -100,9 +100,9 @@ struct basic_response { /// underlying memory blocks, therefore the reply object must remain /// valid and /// not be changed until the write operation has completed. - std::vector to_buffers() { - using asio::const_buffer; - using asio::buffer; + std::vector to_buffers() { + using boost::asio::const_buffer; + using boost::asio::buffer; static const char name_value_separator[] = {':', ' '}; static const char crlf[] = {'\r', '\n'}; std::vector buffers; @@ -408,13 +408,13 @@ struct basic_response { } } - asio::const_buffer trim_null(asio::const_buffer buffer) { - std::size_t size = asio::buffer_size(buffer); - return asio::buffer(buffer, size - 1); + boost::asio::const_buffer trim_null(boost::asio::const_buffer buffer) { + std::size_t size = boost::asio::buffer_size(buffer); + return boost::asio::buffer(buffer, size - 1); } - asio::const_buffer to_buffer(status_type status) { - using asio::buffer; + boost::asio::const_buffer to_buffer(status_type status) { + using boost::asio::buffer; switch (status) { // 2xx Success case basic_response::ok: diff --git a/boost/network/protocol/http/message/async_message.hpp b/boost/network/protocol/http/message/async_message.hpp index bca9148b2..8fd86a0a0 100644 --- a/boost/network/protocol/http/message/async_message.hpp +++ b/boost/network/protocol/http/message/async_message.hpp @@ -9,13 +9,13 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include #include #include // FIXME move this out to a trait #include #include +#include namespace boost { namespace network { @@ -43,6 +43,9 @@ struct async_message { destination_(), status_(), headers_(), + retrieved_headers_(), + added_headers(), + removed_headers(), body_() {} async_message(async_message const& other) @@ -52,35 +55,38 @@ struct async_message { destination_(other.destination_), status_(other.status_), headers_(other.headers_), + retrieved_headers_(other.retrieved_headers_), + added_headers(other.added_headers), + removed_headers(other.removed_headers), body_(other.body_) {} string_type const status_message() const { return status_message_.get(); } - void status_message(std::shared_future const& future) const { + void status_message(boost::shared_future const& future) const { status_message_ = future; } string_type const version() const { return version_.get(); } - void version(std::shared_future const& future) const { + void version(boost::shared_future const& future) const { version_ = future; } std::uint16_t status() const { return status_.get(); } - void status(std::shared_future const& future) const { + void status(boost::shared_future const& future) const { status_ = future; } string_type const source() const { return source_.get(); } - void source(std::shared_future const& future) const { + void source(boost::shared_future const& future) const { source_ = future; } string_type const destination() const { return destination_.get(); } - void destination(std::shared_future const& future) const { + void destination(boost::shared_future const& future) const { destination_ = future; } @@ -91,11 +97,11 @@ struct async_message { for (string_type const & key : removed_headers) { raw_headers.erase(key); } - retrieved_headers_ = raw_headers; + retrieved_headers_ = make_optional(raw_headers); return *retrieved_headers_; } - void headers(std::shared_future const& future) + void headers(boost::shared_future const& future) const { headers_ = future; } @@ -112,7 +118,7 @@ struct async_message { string_type const body() const { return body_.get(); } - void body(std::shared_future const& future) const { + void body(boost::shared_future const& future) const { body_ = future; } @@ -123,6 +129,9 @@ struct async_message { std::swap(source_, other.source_); std::swap(destination_, other.destination_); std::swap(headers_, other.headers_); + std::swap(retrieved_headers_, other.retrieved_headers_); + std::swap(added_headers, other.added_headers); + std::swap(removed_headers, other.removed_headers); std::swap(body_, other.body_); } @@ -132,14 +141,14 @@ struct async_message { } private: - mutable std::shared_future status_message_, version_, source_, + mutable boost::shared_future status_message_, version_, source_, destination_; - mutable std::shared_future status_; - mutable std::shared_future headers_; + mutable boost::shared_future status_; + mutable boost::shared_future headers_; + mutable boost::optional retrieved_headers_; mutable headers_container_type added_headers; mutable std::set removed_headers; - mutable std::shared_future body_; - mutable boost::optional retrieved_headers_; + mutable boost::shared_future body_; friend struct boost::network::http::impl::ready_wrapper; }; diff --git a/boost/network/protocol/http/message/directives/status.hpp b/boost/network/protocol/http/message/directives/status.hpp index 010ad2f2a..f64cb94d3 100644 --- a/boost/network/protocol/http/message/directives/status.hpp +++ b/boost/network/protocol/http/message/directives/status.hpp @@ -7,11 +7,11 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include #include #include #include #include +#include #include #include #include @@ -25,18 +25,18 @@ struct basic_response; struct status_directive { - boost::variant > + boost::variant > status_; explicit status_directive(std::uint16_t status) : status_(status) {} - explicit status_directive(std::shared_future const &status) + explicit status_directive(boost::shared_future const &status) : status_(status) {} status_directive(status_directive const &other) : status_(other.status_) {} template - struct value : mpl::if_, std::shared_future, + struct value : mpl::if_, boost::shared_future, std::uint16_t> {}; template diff --git a/boost/network/protocol/http/message/traits/status.hpp b/boost/network/protocol/http/message/traits/status.hpp index ce1b551a8..92c6c3d6c 100644 --- a/boost/network/protocol/http/message/traits/status.hpp +++ b/boost/network/protocol/http/message/traits/status.hpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace boost { namespace network { @@ -23,7 +24,7 @@ template struct status : mpl::if_< is_async, - std::shared_future, + boost::shared_future, typename mpl::if_, std::uint16_t, unsupported_tag >::type> {}; diff --git a/boost/network/protocol/http/message/traits/status_message.hpp b/boost/network/protocol/http/message/traits/status_message.hpp index 544d55b3f..61b89ec02 100644 --- a/boost/network/protocol/http/message/traits/status_message.hpp +++ b/boost/network/protocol/http/message/traits/status_message.hpp @@ -6,11 +6,11 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include #include #include #include #include +#include namespace boost { namespace network { @@ -25,7 +25,7 @@ template struct status_message : mpl::if_< is_async, - std::shared_future::type>, + boost::shared_future::type>, typename mpl::if_< mpl::or_, is_same, diff --git a/boost/network/protocol/http/message/traits/version.hpp b/boost/network/protocol/http/message/traits/version.hpp index 103483fcc..3fbcc7348 100644 --- a/boost/network/protocol/http/message/traits/version.hpp +++ b/boost/network/protocol/http/message/traits/version.hpp @@ -6,12 +6,12 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include #include #include #include #include #include +#include namespace boost { namespace network { @@ -30,7 +30,7 @@ struct version { template struct version >::type> { - typedef std::shared_future::type> + typedef boost::shared_future::type> type; }; diff --git a/boost/network/protocol/http/policies/async_connection.hpp b/boost/network/protocol/http/policies/async_connection.hpp index 34a1f0c21..db239eef9 100644 --- a/boost/network/protocol/http/policies/async_connection.hpp +++ b/boost/network/protocol/http/policies/async_connection.hpp @@ -30,15 +30,20 @@ struct async_connection_policy : resolver_policy::type { typedef typename resolver_base::resolve_function resolve_function; typedef typename resolver_base::resolve_completion_function resolve_completion_function; - typedef std::function const&, - std::error_code const&)> + typedef + typename std::array::type, + BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE>:: + const_iterator const_iterator; + typedef iterator_range char_const_range; + typedef std::function body_callback_function_type; typedef std::function body_generator_function_type; struct connection_impl { connection_impl( bool follow_redirect, bool always_verify_peer, resolve_function resolve, - resolver_type& resolver, bool https, int timeout, + resolver_type& resolver, bool https, int timeout, bool remove_chunk_markers, optional /*unused*/ const& certificate_filename, optional const& verify_path, optional const& certificate_file, @@ -47,9 +52,9 @@ struct async_connection_policy : resolver_policy::type { optional const& sni_hostname, long ssl_options) { pimpl = impl::async_connection_base:: new_connection(resolve, resolver, follow_redirect, always_verify_peer, - https, timeout, certificate_filename, verify_path, - certificate_file, private_key_file, ciphers, - sni_hostname, ssl_options); + https, timeout, remove_chunk_markers, + certificate_filename, verify_path, certificate_file, + private_key_file, ciphers, sni_hostname, ssl_options); } basic_response send_request(string_type /*unused*/ const& method, @@ -86,20 +91,22 @@ struct async_connection_policy : resolver_policy::type { this->resolve(resolver, host, port, once_resolved); }, resolver, boost::iequals(protocol_, string_type("https")), timeout_, - certificate_filename, verify_path, certificate_file, private_key_file, - ciphers, sni_hostname, ssl_options); + remove_chunk_markers_, certificate_filename, verify_path, + certificate_file, private_key_file, ciphers, sni_hostname, ssl_options); } void cleanup() {} async_connection_policy(bool cache_resolved, bool follow_redirect, - int timeout) + int timeout, bool remove_chunk_markers) : resolver_base(cache_resolved), follow_redirect_(follow_redirect), - timeout_(timeout) {} + timeout_(timeout), + remove_chunk_markers_(remove_chunk_markers) {} bool follow_redirect_; int timeout_; + bool remove_chunk_markers_; }; } // namespace http diff --git a/boost/network/protocol/http/policies/async_resolver.hpp b/boost/network/protocol/http/policies/async_resolver.hpp index ac30d1586..c03cd5a36 100644 --- a/boost/network/protocol/http/policies/async_resolver.hpp +++ b/boost/network/protocol/http/policies/async_resolver.hpp @@ -10,8 +10,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -31,7 +31,7 @@ struct async_resolver : std::enable_shared_from_this > { typedef typename string::type string_type; typedef std::unordered_map endpoint_cache; - typedef std::function + typedef std::function resolve_completion_function; typedef std::function resolve_function; @@ -39,8 +39,8 @@ struct async_resolver : std::enable_shared_from_this > { protected: bool cache_resolved_; endpoint_cache endpoint_cache_; - std::shared_ptr service_; - std::shared_ptr resolver_strand_; + std::shared_ptr service_; + std::shared_ptr resolver_strand_; explicit async_resolver(bool cache_resolved) : cache_resolved_(cache_resolved), endpoint_cache_() {} @@ -51,7 +51,7 @@ struct async_resolver : std::enable_shared_from_this > { typename endpoint_cache::iterator iter = endpoint_cache_.find(boost::to_lower_copy(host)); if (iter != endpoint_cache_.end()) { - std::error_code ignored; + boost::system::error_code ignored; once_resolved(ignored, iter->second); return; } @@ -60,7 +60,7 @@ struct async_resolver : std::enable_shared_from_this > { typename resolver_type::query q(host, std::to_string(port)); auto self = this->shared_from_this(); resolver_.async_resolve( - q, resolver_strand_->wrap([=](std::error_code const &ec, + q, resolver_strand_->wrap([=](boost::system::error_code const &ec, resolver_iterator endpoint_iterator) { self->handle_resolve(boost::to_lower_copy(host), once_resolved, ec, endpoint_iterator); @@ -69,7 +69,7 @@ struct async_resolver : std::enable_shared_from_this > { void handle_resolve(string_type /*unused*/ const &host, resolve_completion_function once_resolved, - std::error_code const &ec, + boost::system::error_code const &ec, resolver_iterator endpoint_iterator) { typename endpoint_cache::iterator iter; bool inserted = false; diff --git a/boost/network/protocol/http/policies/pooled_connection.hpp b/boost/network/protocol/http/policies/pooled_connection.hpp index 845dd0d4a..34339367d 100644 --- a/boost/network/protocol/http/policies/pooled_connection.hpp +++ b/boost/network/protocol/http/policies/pooled_connection.hpp @@ -35,7 +35,7 @@ struct pooled_connection_policy : resolver_policy::type { resolver_type&, string_type const&, string_type const&)> resolver_function_type; typedef std::function const&, - std::error_code const&)> + boost::system::error_code const&)> body_callback_function_type; typedef std::function body_generator_function_type; @@ -110,12 +110,12 @@ struct pooled_connection_policy : resolver_policy::type { response_ << ::boost::network::source(request_.host()); pimpl->send_request_impl(method, request_, generator); - asio::streambuf response_buffer; + boost::asio::streambuf response_buffer; try { pimpl->read_status(response_, response_buffer); - } catch (std::system_error& e) { - if (!retry && e.code() == asio::error::eof) { + } catch (boost::system::system_error& e) { + if (!retry && e.code() == boost::asio::error::eof) { retry = true; pimpl->init_socket(request_.host(), std::to_string(request_.port())); diff --git a/boost/network/protocol/http/policies/simple_connection.hpp b/boost/network/protocol/http/policies/simple_connection.hpp index 5a96c5ade..dca2fb354 100644 --- a/boost/network/protocol/http/policies/simple_connection.hpp +++ b/boost/network/protocol/http/policies/simple_connection.hpp @@ -36,7 +36,7 @@ struct simple_connection_policy : resolver_policy::type { typedef typename resolver_base::resolver_completion_function resolver_completion_function; typedef std::function const&, - std::error_code const&)> + boost::system::error_code const&)> body_callback_function_type; typedef std::function body_generator_function_type; @@ -80,7 +80,7 @@ struct simple_connection_policy : resolver_policy::type { response_ = basic_response(); response_ << network::source(request_.host()); - asio::streambuf response_buffer; + boost::asio::streambuf response_buffer; pimpl->read_status(response_, response_buffer); pimpl->read_headers(response_, response_buffer); if (get_body) pimpl->read_body(response_, response_buffer); diff --git a/boost/network/protocol/http/server/async_connection.hpp b/boost/network/protocol/http/server/async_connection.hpp index e5c361ab6..58a1df1ac 100644 --- a/boost/network/protocol/http/server/async_connection.hpp +++ b/boost/network/protocol/http/server/async_connection.hpp @@ -16,11 +16,11 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include @@ -56,7 +56,7 @@ * We define the buffer size for each connection that we will use on the server * side. */ -#define BOOST_NETWORK_HTTP_SERVER_CONNECTION_BUFFER_SIZE 1024uL +#define BOOST_NETWORK_HTTP_SERVER_CONNECTION_BUFFER_SIZE 4096uL #endif namespace boost { @@ -183,7 +183,7 @@ struct async_connection public: async_connection( - asio::io_service& io_service, Handler& handler, + boost::asio::io_service& io_service, Handler& handler, utils::thread_pool& thread_pool, std::shared_ptr ctx = std::shared_ptr()) : strand(io_service), @@ -205,8 +205,8 @@ struct async_connection } ~async_connection() throw() { - std::error_code ignored; - socket_.shutdown(asio::ip::tcp::socket::shutdown_receive, ignored); + boost::system::error_code ignored; + socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_receive, ignored); } /** @@ -228,7 +228,7 @@ struct async_connection std::logic_error("Headers have already been sent.")); if (error_encountered) - boost::throw_exception(std::system_error(*error_encountered)); + boost::throw_exception(boost::system::system_error(*error_encountered)); typedef constants consts; { @@ -264,7 +264,7 @@ struct async_connection boost::throw_exception(std::logic_error( "Headers have already been sent, cannot reset status.")); if (error_encountered) - boost::throw_exception(std::system_error(*error_encountered)); + boost::throw_exception(boost::system::system_error(*error_encountered)); status = new_status; } @@ -289,7 +289,7 @@ struct async_connection * set_status and/or set_headers before any calls to write. * * @param[in] range A Boost.Range ``Single Pass Range`` of char's for writing. - * @throw std::system_error The encountered underlying error in previous + * @throw boost::system::system_error The encountered underlying error in previous * operations. * @post Status and headers have been sent, contents in the range have been * serialized. @@ -298,9 +298,9 @@ struct async_connection void write(Range const& range) { lock_guard lock(headers_mutex); if (error_encountered) - boost::throw_exception(std::system_error(*error_encountered)); + boost::throw_exception(boost::system::system_error(*error_encountered)); auto self = this->shared_from_this(); - auto f = [this, self](std::error_code ec) { this->default_error(ec); }; + auto f = [this, self](boost::system::error_code ec) { this->default_error(ec); }; write_impl(boost::make_iterator_range(range), f); } @@ -313,32 +313,32 @@ struct async_connection * memory at once. * * @param[in] range A Boost.Range ``Single Pass Range`` of char's for writing. - * @param[in] callback A function of type `void(std::error_code)`. - * @throw std::system_error The encountered underlying error in previous + * @param[in] callback A function of type `void(boost::system::error_code)`. + * @throw boost::system::system_error The encountered underlying error in previous * operations. * @post Status and headers have been sent, contents in the range have been * serialized and scheduled for writing through the socket. */ template typename disable_if< - is_base_of, void>::type + is_base_of, void>::type write(Range const& range, Callback const& callback) { lock_guard lock(headers_mutex); if (error_encountered) - boost::throw_exception(std::system_error(*error_encountered)); + boost::throw_exception(boost::system::system_error(*error_encountered)); write_impl(boost::make_iterator_range(range), callback); } /** - * Writes a given set of `asio::const_buffer`s out using a more efficient + * Writes a given set of `boost::asio::const_buffer`s out using a more efficient * implementation. * - * @param[in] seq A sequence of `asio::const_buffer` objects. - * @param[in] callback A function of type `void(std::error_code)`. + * @param[in] seq A sequence of `boost::asio::const_buffer` objects. + * @param[in] callback A function of type `void(boost::system::error_code)`. */ template typename enable_if< - is_base_of, + is_base_of, void>::type write(ConstBufferSeq const& seq, Callback const& callback) { write_vec_impl(seq, callback, shared_array_list(), shared_buffers()); @@ -355,7 +355,7 @@ struct async_connection /// Type required for ``read`` callbacks. Takes an input range, an error /// code, the number of bytes read, and a connection pointer. - typedef std::function read_callback_function; /** @@ -370,15 +370,15 @@ struct async_connection * void(input_range, error_code, size_t, connection_ptr) * * @param[in] callback Invoked when the read has data ready for processing. - * @throw std::system_error The underlying error encountered in previous + * @throw boost::system::system_error The underlying error encountered in previous * operations. */ void read(read_callback_function callback) { if (error_encountered) - boost::throw_exception(std::system_error(*error_encountered)); + boost::throw_exception(boost::system::system_error(*error_encountered)); if (new_start != read_buffer_.begin()) { input_range input = - boost::make_iterator_range(new_start, read_buffer_.end()); + boost::make_iterator_range(new_start, data_end); buffer_type::iterator start_tmp = new_start; new_start = read_buffer_.begin(); auto self = this->shared_from_this(); @@ -389,11 +389,12 @@ struct async_connection } auto self = this->shared_from_this(); - socket().async_read_some(asio::buffer(read_buffer_), - strand.wrap([this, self, callback]( - std::error_code ec, size_t bytes_transferred) { - callback(ec, bytes_transferred); - })); + socket().async_read_some( + boost::asio::buffer(read_buffer_), + strand.wrap([this, self, callback](boost::system::error_code ec, + size_t bytes_transferred) { + this->wrap_read_handler(callback, ec, bytes_transferred); + })); } /// Returns a reference to the underlying socket. @@ -407,13 +408,13 @@ struct async_connection bool has_error() { return (!!error_encountered); } /// Returns the most recent error encountered. - optional error() { return error_encountered; } + optional error() { return error_encountered; } private: void wrap_read_handler(read_callback_function callback, - std::error_code const& ec, + boost::system::error_code const& ec, std::size_t bytes_transferred) { - if (ec) error_encountered = in_place(ec); + if (ec) error_encountered = in_place(ec); buffer_type::const_iterator data_start = read_buffer_.begin(), data_end = read_buffer_.begin(); std::advance(data_end, bytes_transferred); @@ -424,23 +425,23 @@ struct async_connection }); } - void default_error(std::error_code const& ec) { - if (ec) error_encountered = in_place(ec); + void default_error(boost::system::error_code const& ec) { + if (ec) error_encountered = in_place(ec); } typedef std::array array; typedef std::list > array_list; typedef std::shared_ptr shared_array_list; - typedef std::shared_ptr > shared_buffers; + typedef std::shared_ptr > shared_buffers; typedef request_parser request_parser_type; typedef std::lock_guard lock_guard; typedef std::list > pending_actions_list; - asio::io_service::strand strand; + boost::asio::io_service::strand strand; Handler& handler; utils::thread_pool& thread_pool_; - asio::streambuf headers_buffer; + boost::asio::streambuf headers_buffer; boost::network::stream_handler socket_; bool handshake_done; volatile bool headers_already_sent, headers_in_progress; @@ -452,7 +453,7 @@ struct async_connection request request_; buffer_type::iterator new_start, data_end; string_type partial_parsed; - optional error_encountered; + optional error_encountered; pending_actions_list pending_actions; template @@ -461,26 +462,33 @@ struct async_connection enum state_t { method, uri, version, headers }; void start() { - typename ostringstream::type ip_stream; - ip_stream << socket_.remote_endpoint().address().to_string() << ':' - << socket_.remote_endpoint().port(); - request_.source = ip_stream.str(); - read_more(method); + boost::system::error_code ec; + auto remote_endpoint = socket_.remote_endpoint(ec); + + if (ec) { + error_encountered = in_place(ec); + } else { + typename ostringstream::type ip_stream; + ip_stream << remote_endpoint.address().to_string() << ':' + << remote_endpoint.port(); + request_.source = ip_stream.str(); + read_more(method); + } } void read_more(state_t state) { auto self = this->shared_from_this(); #ifdef BOOST_NETWORK_ENABLE_HTTPS if (socket_.is_ssl_enabled() && !handshake_done) { - socket_.async_handshake(asio::ssl::stream_base::server, - [this, self, state](std::error_code ec) { + socket_.async_handshake(boost::asio::ssl::stream_base::server, + [this, self, state](boost::system::error_code ec) { handle_handshake(ec, state); }); } else { #endif socket_.async_read_some( - asio::buffer(read_buffer_), - strand.wrap([this, self, state](std::error_code ec, + boost::asio::buffer(read_buffer_), + strand.wrap([this, self, state](boost::system::error_code ec, size_t bytes_transferred) { handle_read_data(state, ec, bytes_transferred); })); @@ -489,7 +497,7 @@ struct async_connection #endif } - void handle_read_data(state_t state, std::error_code const& ec, + void handle_read_data(state_t state, boost::system::error_code const& ec, std::size_t bytes_transferred) { if (!ec) { logic::tribool parsed_ok; @@ -578,7 +586,7 @@ struct async_connection } new_start = std::end(result_range); auto self = this->shared_from_this(); - thread_pool().post([this, self] { handler(request_, self); }); + thread_pool().post([self] () { self->handler(self->request_, self); }); return; } else { partial_parsed.append(std::begin(result_range), @@ -594,7 +602,7 @@ struct async_connection std::abort(); } } else { - error_encountered = in_place(ec); + error_encountered = in_place(ec); } } @@ -604,20 +612,20 @@ struct async_connection "text/plain\r\nContent-Length: 12\r\n\r\nBad Request."; auto self = this->shared_from_this(); - asio::async_write( - socket(), asio::buffer(bad_request, strlen(bad_request)), - strand.wrap([this, self](std::error_code ec, size_t bytes_transferred) { + boost::asio::async_write( + socket(), boost::asio::buffer(bad_request, strlen(bad_request)), + strand.wrap([this, self](boost::system::error_code ec, size_t bytes_transferred) { client_error_sent(ec, bytes_transferred); })); } - void client_error_sent(std::error_code const& ec, std::size_t) { + void client_error_sent(boost::system::error_code const& ec, std::size_t) { if (!ec) { - std::error_code ignored; - socket().shutdown(asio::ip::tcp::socket::shutdown_both, ignored); + boost::system::error_code ignored; + socket().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored); socket().close(ignored); } else { - error_encountered = in_place(ec); + error_encountered = in_place(ec); } } @@ -625,15 +633,15 @@ struct async_connection if (headers_in_progress) return; headers_in_progress = true; auto self = this->shared_from_this(); - asio::async_write(socket(), headers_buffer, + boost::asio::async_write(socket(), headers_buffer, strand.wrap([this, self, callback]( - std::error_code ec, size_t bytes_transferred) { + boost::system::error_code ec, size_t bytes_transferred) { handle_write_headers(callback, ec, bytes_transferred); })); } void handle_write_headers(std::function callback, - std::error_code const& ec, std::size_t) { + boost::system::error_code const& ec, std::size_t) { lock_guard lock(headers_mutex); if (!ec) { headers_buffer.consume(headers_buffer.size()); @@ -645,19 +653,19 @@ struct async_connection } pending_actions_list().swap(pending_actions); } else { - error_encountered = in_place(ec); + error_encountered = in_place(ec); } } - void handle_write(std::function callback, + void handle_write(std::function callback, shared_array_list, shared_buffers, - std::error_code const& ec, std::size_t) { + boost::system::error_code const& ec, std::size_t) { // we want to forget the temporaries and buffers thread_pool().post([callback, ec] { callback(ec); }); } template - void write_impl(Range range, std::function callback) { + void write_impl(Range range, std::function callback) { // linearize the whole range into a vector // of fixed-sized buffers, then schedule an asynchronous // write of these buffers -- make sure they are live @@ -675,7 +683,7 @@ struct async_connection BOOST_NETWORK_HTTP_SERVER_CONNECTION_BUFFER_SIZE; shared_array_list temporaries = std::make_shared(); shared_buffers buffers = - std::make_shared >(0); + std::make_shared >(0); std::size_t range_size = boost::distance(range); buffers->reserve((range_size / connection_buffer_size) + @@ -687,7 +695,7 @@ struct async_connection std::shared_ptr new_array = std::make_shared(); boost::copy(range | sliced(0, slice_size), new_array->begin()); temporaries->push_back(new_array); - buffers->push_back(asio::buffer(new_array->data(), slice_size)); + buffers->push_back(boost::asio::buffer(new_array->data(), slice_size)); std::advance(start, slice_size); range = boost::make_iterator_range(start, end); range_size = boost::distance(range); @@ -704,7 +712,7 @@ struct async_connection shared_array_list temporaries, shared_buffers buffers) { lock_guard lock(headers_mutex); if (error_encountered) - boost::throw_exception(std::system_error(*error_encountered)); + boost::throw_exception(boost::system::system_error(*error_encountered)); auto self = this->shared_from_this(); auto continuation = [this, self, seq, callback, temporaries, buffers] { write_vec_impl(seq, callback, temporaries, buffers); @@ -717,19 +725,19 @@ struct async_connection pending_actions.push_back(continuation); return; } - asio::async_write( + boost::asio::async_write( socket_, seq, [this, self, callback, temporaries, buffers]( - std::error_code ec, size_t bytes_transferred) { + boost::system::error_code ec, size_t bytes_transferred) { handle_write(callback, temporaries, buffers, ec, bytes_transferred); }); } - void handle_handshake(const std::error_code& ec, state_t state) { + void handle_handshake(const boost::system::error_code& ec, state_t state) { if (!ec) { handshake_done = true; read_more(state); } else { - error_encountered = in_place(ec); + error_encountered = in_place(ec); } } }; diff --git a/boost/network/protocol/http/server/async_server.hpp b/boost/network/protocol/http/server/async_server.hpp index 954e0a5c3..c1e3c662e 100644 --- a/boost/network/protocol/http/server/async_server.hpp +++ b/boost/network/protocol/http/server/async_server.hpp @@ -35,13 +35,17 @@ struct async_server_base : server_storage_base, socket_options_base { /// Defines the type for the connection pointer. typedef std::shared_ptr connection_ptr; + /// Defines the type for the options. + typedef server_options options; + /// Constructs and initializes the asynchronous server core. - explicit async_server_base(server_options const &options) + explicit async_server_base(options const &options) : server_storage_base(options), socket_options_base(options), handler(options.handler()), address_(options.address()), port_(options.port()), + protocol_family(options.protocol_family()), thread_pool(options.thread_pool() ? options.thread_pool() : std::make_shared()), @@ -86,7 +90,7 @@ struct async_server_base : server_storage_base, socket_options_base { // listening scoped_mutex_lock stopping_lock(stopping_mutex_); stopping = true; - std::error_code ignored; + boost::system::error_code ignored; acceptor.close(ignored); listening = false; service_.post([this]() { this->handle_stop(); }); @@ -108,13 +112,21 @@ struct async_server_base : server_storage_base, socket_options_base { } } + /// Returns the server socket address, either IPv4 or IPv6 depending on + /// options.protocol_family() + const string_type& address() const { return address_; } + + /// Returns the server socket port + const string_type& port() const { return port_; } + private: typedef std::unique_lock scoped_mutex_lock; Handler &handler; string_type address_, port_; + typename options::protocol_family_t protocol_family; std::shared_ptr thread_pool; - asio::ip::tcp::acceptor acceptor; + boost::asio::ip::tcp::acceptor acceptor; bool stopping; connection_ptr new_connection; std::mutex listening_mutex_; @@ -129,7 +141,7 @@ struct async_server_base : server_storage_base, socket_options_base { // the stop command is reached } - void handle_accept(std::error_code const &ec) { + void handle_accept(boost::system::error_code const &ec) { { scoped_mutex_lock stopping_lock(stopping_mutex_); if (stopping) @@ -156,16 +168,24 @@ struct async_server_base : server_storage_base, socket_options_base { #else new_connection->socket(), #endif - [this](std::error_code const &ec) { this->handle_accept(ec); }); + [this](boost::system::error_code const &ec) { this->handle_accept(ec); }); } void start_listening() { - using asio::ip::tcp; - std::error_code error; + using boost::asio::ip::tcp; + boost::system::error_code error; // this allows repeated cycles of run -> stop -> run service_.reset(); tcp::resolver resolver(service_); - tcp::resolver::query query(address_, port_); + tcp::resolver::query query( [&]{ + switch(protocol_family) { + case options::ipv4: + return tcp::resolver::query(tcp::v4(), address_, port_); + case options::ipv6: + return tcp::resolver::query(tcp::v6(), address_, port_); + default: + return tcp::resolver::query(address_, port_); + }}()); tcp::resolver::iterator endpoint_iterator = resolver.resolve(query, error); if (error) { BOOST_NETWORK_MESSAGE("Error resolving '" << address_ << ':' << port_); @@ -185,7 +205,9 @@ struct async_server_base : server_storage_base, socket_options_base { << port_); return; } - acceptor.listen(asio::socket_base::max_connections, error); + address_ = acceptor.local_endpoint().address().to_string(); + port_ = std::to_string(acceptor.local_endpoint().port()); + acceptor.listen(boost::asio::socket_base::max_connections, error); if (error) { BOOST_NETWORK_MESSAGE("Error listening on socket: '" << error << "' on " << address_ << ":" << port_); @@ -198,7 +220,7 @@ struct async_server_base : server_storage_base, socket_options_base { #else new_connection->socket(), #endif - [this](std::error_code const &ec) { this->handle_accept(ec); }); + [this](boost::system::error_code const &ec) { this->handle_accept(ec); }); listening = true; scoped_mutex_lock stopping_lock(stopping_mutex_); stopping = false; // if we were in the process of stopping, we revoke diff --git a/boost/network/protocol/http/server/impl/parsers.ipp b/boost/network/protocol/http/server/impl/parsers.ipp index b0de37597..c31e60eac 100644 --- a/boost/network/protocol/http/server/impl/parsers.ipp +++ b/boost/network/protocol/http/server/impl/parsers.ipp @@ -49,16 +49,15 @@ namespace http { BOOST_NETWORK_INLINE void parse_version( std::string const& partial_parsed, std::tuple& version_pair) { - using namespace boost::spirit::qi; - parse(partial_parsed.begin(), partial_parsed.end(), - (lit("HTTP/") >> ushort_ >> '.' >> ushort_), version_pair); + boost::spirit::qi::parse(partial_parsed.begin(), partial_parsed.end(), + (boost::spirit::qi::lit("HTTP/") >> boost::spirit::qi::ushort_ >> '.' >> boost::spirit::qi::ushort_), version_pair); } BOOST_NETWORK_INLINE void parse_headers( std::string const& input, std::vector& container) { - using namespace boost::spirit::qi; u8_to_u32_iterator begin = input.begin(), end = input.end(); + using namespace boost::spirit::qi; typedef as as_u32_string; parse(begin, end, *(+((alnum | punct) - ':') >> lit(": ") >> diff --git a/boost/network/protocol/http/server/options.hpp b/boost/network/protocol/http/server/options.hpp index d3d9f03a1..e84188bf3 100644 --- a/boost/network/protocol/http/server/options.hpp +++ b/boost/network/protocol/http/server/options.hpp @@ -9,8 +9,8 @@ // http://www.boost.org/LICENSE_1_0.txt) #include -#include -#include +#include +#include #include #include #include @@ -34,6 +34,7 @@ struct server_options { handler_(handler), address_("localhost"), port_("80"), + protocol_family_(undefined), reuse_address_(false), report_aborted_(false), non_blocking_io_(true), @@ -71,7 +72,7 @@ struct server_options { } /// Provides an Asio io_service for the server. Default is nullptr. - server_options &io_service(std::shared_ptr v) { + server_options &io_service(std::shared_ptr v) { io_service_ = v; return *this; } @@ -88,6 +89,14 @@ struct server_options { return *this; } + enum protocol_family_t { ipv4, ipv6, undefined }; + + /// Set the protocol family for address resolving. Default is AF_UNSPEC. + server_options &protocol_family(protocol_family_t v) { + protocol_family_ = v; + return *this; + } + /// Set whether to reuse the address (SO_REUSE_ADDR). Default is false. server_options &reuse_address(bool v) { reuse_address_ = v; @@ -120,26 +129,26 @@ struct server_options { /// Set the socket receive buffer size. Unset by default. server_options &receive_buffer_size( - asio::socket_base::receive_buffer_size v) { + boost::asio::socket_base::receive_buffer_size v) { receive_buffer_size_ = v; return *this; } /// Set the send buffer size. Unset by default. - server_options &send_buffer_size(asio::socket_base::send_buffer_size v) { + server_options &send_buffer_size(boost::asio::socket_base::send_buffer_size v) { send_buffer_size_ = v; return *this; } /// Set the socket receive low watermark. Unset by default. server_options &receive_low_watermark( - asio::socket_base::receive_low_watermark v) { + boost::asio::socket_base::receive_low_watermark v) { receive_low_watermark_ = v; return *this; } /// Set the socket send low watermark. Unset by default. - server_options &send_low_watermark(asio::socket_base::send_low_watermark v) { + server_options &send_low_watermark(boost::asio::socket_base::send_low_watermark v) { send_low_watermark_ = v; return *this; } @@ -151,7 +160,7 @@ struct server_options { } /// Returns the provided Asio io_service. - std::shared_ptr io_service() const { return io_service_; } + std::shared_ptr io_service() const { return io_service_; } /// Returns the address to listen on. string_type address() const { return address_; } @@ -159,6 +168,9 @@ struct server_options { /// Returns the port to listen on. string_type port() const { return port_; } + /// Returns the protocol family used for address resolving. + protocol_family_t protocol_family() const { return protocol_family_; } + /// Returns a reference to the provided handler. Handler &handler() const { return handler_; } @@ -178,25 +190,25 @@ struct server_options { size_t linger_timeout() const { return linger_timeout_; } /// Returns the optional receive buffer size. - boost::optional receive_buffer_size() + boost::optional receive_buffer_size() const { return receive_buffer_size_; } /// Returns the optional send buffer size. - boost::optional send_buffer_size() + boost::optional send_buffer_size() const { return send_buffer_size_; } /// Returns the optional receive low watermark. - boost::optional + boost::optional receive_low_watermark() const { return receive_low_watermark_; } /// Returns the optional send low watermark. - boost::optional send_low_watermark() + boost::optional send_low_watermark() const { return send_low_watermark_; } @@ -215,6 +227,7 @@ struct server_options { swap(io_service_, other.io_service_); swap(address_, other.address_); swap(port_, other.port_); + swap(protocol_family_, other.protocol_family_); swap(reuse_address_, other.reuse_address_); swap(report_aborted_, other.report_aborted_); swap(non_blocking_io_, other.non_blocking_io_); @@ -229,20 +242,21 @@ struct server_options { } private: - std::shared_ptr io_service_; + std::shared_ptr io_service_; Handler &handler_; string_type address_; string_type port_; + protocol_family_t protocol_family_; bool reuse_address_; bool report_aborted_; bool non_blocking_io_; bool linger_; size_t linger_timeout_; - boost::optional receive_buffer_size_; - boost::optional send_buffer_size_; - boost::optional + boost::optional receive_buffer_size_; + boost::optional send_buffer_size_; + boost::optional receive_low_watermark_; - boost::optional send_low_watermark_; + boost::optional send_low_watermark_; std::shared_ptr thread_pool_; std::shared_ptr context_; }; diff --git a/boost/network/protocol/http/server/socket_options_base.hpp b/boost/network/protocol/http/server/socket_options_base.hpp index dc1bd15c5..f82a3d7b9 100644 --- a/boost/network/protocol/http/server/socket_options_base.hpp +++ b/boost/network/protocol/http/server/socket_options_base.hpp @@ -14,15 +14,15 @@ namespace http { struct socket_options_base { protected: - asio::socket_base::reuse_address acceptor_reuse_address; - asio::socket_base::enable_connection_aborted acceptor_report_aborted; - boost::optional receive_buffer_size; - boost::optional send_buffer_size; - boost::optional + boost::asio::socket_base::reuse_address acceptor_reuse_address; + boost::asio::socket_base::enable_connection_aborted acceptor_report_aborted; + boost::optional receive_buffer_size; + boost::optional send_buffer_size; + boost::optional receive_low_watermark; - boost::optional send_low_watermark; + boost::optional send_low_watermark; bool non_blocking_io; - asio::socket_base::linger linger; + boost::asio::socket_base::linger linger; template explicit socket_options_base(server_options const &options) @@ -35,13 +35,13 @@ struct socket_options_base { non_blocking_io(options.non_blocking_io()), linger(options.linger(), options.linger_timeout()) {} - void acceptor_options(asio::ip::tcp::acceptor &acceptor) { + void acceptor_options(boost::asio::ip::tcp::acceptor &acceptor) { acceptor.set_option(acceptor_reuse_address); acceptor.set_option(acceptor_report_aborted); } - void socket_options(asio::ip::tcp::socket &socket) { - std::error_code ignored; + void socket_options(boost::asio::ip::tcp::socket &socket) { + boost::system::error_code ignored; socket.non_blocking(non_blocking_io); socket.set_option(linger, ignored); if (receive_buffer_size) socket.set_option(*receive_buffer_size, ignored); diff --git a/boost/network/protocol/http/server/storage_base.hpp b/boost/network/protocol/http/server/storage_base.hpp index 9383e5e92..ec134a9f3 100644 --- a/boost/network/protocol/http/server/storage_base.hpp +++ b/boost/network/protocol/http/server/storage_base.hpp @@ -22,11 +22,11 @@ struct server_storage_base { explicit server_storage_base(server_options const& options) : self_service_(options.io_service() ? options.io_service() - : std::make_shared()), + : std::make_shared()), service_(*self_service_) {} - std::shared_ptr self_service_; - asio::io_service& service_; + std::shared_ptr self_service_; + boost::asio::io_service& service_; }; } /* http */ diff --git a/boost/network/protocol/http/traits/resolver.hpp b/boost/network/protocol/http/traits/resolver.hpp index cfcfc19fd..dec498745 100644 --- a/boost/network/protocol/http/traits/resolver.hpp +++ b/boost/network/protocol/http/traits/resolver.hpp @@ -6,8 +6,8 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include -#include +#include +#include #include #include #include @@ -26,9 +26,9 @@ struct unsupported_tag; template struct resolver : mpl::if_, is_http >, - asio::ip::tcp::resolver, + boost::asio::ip::tcp::resolver, typename mpl::if_, is_http >, - asio::ip::udp::resolver, + boost::asio::ip::udp::resolver, unsupported_tag >::type> { static_assert(mpl::not_, is_tcp > >::value, "Transport protocol must be TCP or UDP"); diff --git a/boost/network/protocol/stream_handler.hpp b/boost/network/protocol/stream_handler.hpp index ae355b724..ffb09b82b 100644 --- a/boost/network/protocol/stream_handler.hpp +++ b/boost/network/protocol/stream_handler.hpp @@ -11,32 +11,33 @@ #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #ifdef BOOST_NETWORK_ENABLE_HTTPS -#include +#include #endif namespace boost { namespace network { -typedef asio::ip::tcp::socket tcp_socket; +typedef boost::asio::ip::tcp::socket tcp_socket; #ifndef BOOST_NETWORK_ENABLE_HTTPS typedef tcp_socket stream_handler; typedef void ssl_context; #else -typedef asio::ssl::stream ssl_socket; -typedef asio::ssl::context ssl_context; +typedef boost::asio::ssl::stream ssl_socket; +typedef boost::asio::ssl::context ssl_context; struct stream_handler { public: @@ -48,7 +49,7 @@ struct stream_handler { stream_handler(std::shared_ptr socket) : ssl_sock_(std::move(socket)), ssl_enabled(true) {} - stream_handler(asio::io_service& io, + stream_handler(boost::asio::io_service& io, std::shared_ptr ctx = std::shared_ptr()) { tcp_sock_ = std::make_shared(boost::ref(io)); @@ -62,10 +63,10 @@ struct stream_handler { } template - ASIO_INITFN_RESULT_TYPE(WriteHandler, - void(std::error_code, std::size_t)) + BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, + void(boost::system::error_code, std::size_t)) async_write_some(const ConstBufferSequence& buffers, - ASIO_MOVE_ARG(WriteHandler) handler) { + BOOST_ASIO_MOVE_ARG(WriteHandler) handler) { try { if (ssl_enabled) { ssl_sock_->async_write_some(buffers, handler); @@ -73,19 +74,16 @@ struct stream_handler { tcp_sock_->async_write_some(buffers, handler); } } - catch (const std::error_code& e) { - std::cerr << e.message() << std::endl; - } - catch (const std::system_error& e) { - std::cerr << e.code() << ": " << e.what() << std::endl; + catch (const boost::system::system_error&) { + // print system error } } template - ASIO_INITFN_RESULT_TYPE(ReadHandler, - void(std::error_code, std::size_t)) + BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, + void(boost::system::error_code, std::size_t)) async_read_some(const MutableBufferSequence& buffers, - ASIO_MOVE_ARG(ReadHandler) handler) { + BOOST_ASIO_MOVE_ARG(ReadHandler) handler) { try { if (ssl_enabled) { ssl_sock_->async_read_some(buffers, handler); @@ -93,15 +91,12 @@ struct stream_handler { tcp_sock_->async_read_some(buffers, handler); } } - catch (const std::error_code& e) { - std::cerr << e.message() << std::endl; - } - catch (const std::system_error& e) { - std::cerr << e.code() << ": " << e.what() << std::endl; + catch (const boost::system::system_error& e) { + // print system error } } - void close(std::error_code& e) { + void close(boost::system::error_code& e) { if (ssl_enabled) { ssl_sock_->next_layer().close(); } else { @@ -109,28 +104,34 @@ struct stream_handler { } } - tcp_socket::endpoint_type remote_endpoint() const { + tcp_socket::endpoint_type remote_endpoint(boost::system::error_code& ec) const { if (ssl_enabled) { - return ssl_sock_->next_layer().remote_endpoint(); + return ssl_sock_->next_layer().remote_endpoint(ec); } else { - return tcp_sock_->remote_endpoint(); + return tcp_sock_->remote_endpoint(ec); } } - void shutdown(asio::socket_base::shutdown_type st, - std::error_code& e) { + tcp_socket::endpoint_type remote_endpoint() const { + boost::system::error_code ec; + tcp_socket::endpoint_type r = remote_endpoint(ec); + if (ec) { + boost::asio::detail::throw_error(ec, "remote_endpoint"); + } + return r; + } + + void shutdown(boost::asio::socket_base::shutdown_type st, + boost::system::error_code& e) { try { if (ssl_enabled) { ssl_sock_->shutdown(e); } else { - tcp_sock_->shutdown(asio::ip::tcp::socket::shutdown_send, e); + tcp_sock_->shutdown(boost::asio::ip::tcp::socket::shutdown_send, e); } } - catch (const std::error_code& e) { - std::cerr << e.message() << std::endl; - } - catch (const std::system_error& e) { - std::cerr << e.code() << ": " << e.what() << std::endl; + catch (const boost::system::system_error&) { + } } @@ -151,10 +152,10 @@ struct stream_handler { } template - ASIO_INITFN_RESULT_TYPE(HandshakeHandler, - void(std::error_code)) + BOOST_ASIO_INITFN_RESULT_TYPE(HandshakeHandler, + void(boost::system::error_code)) async_handshake(ssl_socket::handshake_type type, - ASIO_MOVE_ARG(HandshakeHandler) handler) { + BOOST_ASIO_MOVE_ARG(HandshakeHandler) handler) { try { if (ssl_enabled) { return ssl_sock_->async_handshake(type, handler); @@ -162,11 +163,8 @@ struct stream_handler { // NOOP } } - catch (const std::error_code& e) { - std::cerr << e.message() << std::endl; - } - catch (const std::system_error& e) { - std::cerr << e.code() << ": " << e.what() << std::endl; + catch (const boost::system::system_error& e) { + } } std::shared_ptr get_tcp_socket() { return tcp_sock_; } diff --git a/boost/network/uri/builder.hpp b/boost/network/uri/builder.hpp index c30d1fd86..568b7fbf8 100644 --- a/boost/network/uri/builder.hpp +++ b/boost/network/uri/builder.hpp @@ -6,7 +6,7 @@ #ifndef __BOOST_NETWORK_URI_BUILDER_INC__ #define __BOOST_NETWORK_URI_BUILDER_INC__ -#include +#include #include namespace boost { @@ -51,23 +51,23 @@ class builder { builder &host(const string_type &host) { return set_host(host); } - builder &set_host(const asio::ip::address &address) { + builder &set_host(const boost::asio::ip::address &address) { uri_.uri_.append(address.to_string()); uri_.parse(); return *this; } - builder &host(const asio::ip::address &host) { return set_host(host); } + builder &host(const boost::asio::ip::address &host) { return set_host(host); } - builder &set_host(const asio::ip::address_v4 &address) { + builder &set_host(const boost::asio::ip::address_v4 &address) { uri_.uri_.append(address.to_string()); uri_.parse(); return *this; } - builder &host(const asio::ip::address_v4 &host) { return set_host(host); } + builder &host(const boost::asio::ip::address_v4 &host) { return set_host(host); } - builder &set_host(const asio::ip::address_v6 &address) { + builder &set_host(const boost::asio::ip::address_v6 &address) { uri_.uri_.append("["); uri_.uri_.append(address.to_string()); uri_.uri_.append("]"); @@ -75,7 +75,7 @@ class builder { return *this; } - builder &host(const asio::ip::address_v6 &host) { return set_host(host); } + builder &host(const boost::asio::ip::address_v6 &host) { return set_host(host); } builder &set_port(const string_type &port) { uri_.uri_.append(":"); diff --git a/boost/network/uri/detail/uri_parts.hpp b/boost/network/uri/detail/uri_parts.hpp index e250396c6..3fcfe99ae 100644 --- a/boost/network/uri/detail/uri_parts.hpp +++ b/boost/network/uri/detail/uri_parts.hpp @@ -29,27 +29,27 @@ struct hierarchical_part { void update() { if (!user_info) { if (host) { - user_info = iterator_range(std::begin(host.get()), - std::begin(host.get())); + user_info = make_optional(iterator_range(std::begin(host.get()), + std::begin(host.get()))); } else if (path) { - user_info = iterator_range(std::begin(path.get()), - std::begin(path.get())); + user_info = make_optional(iterator_range(std::begin(path.get()), + std::begin(path.get()))); } } if (!host) { - host = iterator_range(std::begin(path.get()), - std::begin(path.get())); + host = make_optional(iterator_range(std::begin(path.get()), + std::begin(path.get()))); } if (!port) { - port = iterator_range(std::end(host.get()), - std::end(host.get())); + port = make_optional(iterator_range(std::end(host.get()), + std::end(host.get()))); } if (!path) { - path = iterator_range(std::end(port.get()), - std::end(port.get())); + path = make_optional(iterator_range(std::end(port.get()), + std::end(port.get()))); } } }; @@ -70,13 +70,13 @@ struct uri_parts { hier_part.update(); if (!query) { - query = iterator_range(std::end(hier_part.path.get()), - std::end(hier_part.path.get())); + query = make_optional(iterator_range(std::end(hier_part.path.get()), + std::end(hier_part.path.get()))); } if (!fragment) { - fragment = iterator_range(std::end(query.get()), - std::end(query.get())); + fragment = make_optional(iterator_range(std::end(query.get()), + std::end(query.get()))); } } }; diff --git a/boost/network/uri/uri.ipp b/boost/network/uri/uri.ipp index 19bea7743..7b56131d3 100644 --- a/boost/network/uri/uri.ipp +++ b/boost/network/uri/uri.ipp @@ -246,7 +246,7 @@ struct uri_grammar bool parse(std::string::const_iterator first, std::string::const_iterator last, uri_parts &parts) { namespace qi = boost::spirit::qi; - static detail::uri_grammar grammar; + detail::uri_grammar grammar; bool is_valid = qi::parse(first, last, grammar, parts); return is_valid && (first == last); } diff --git a/boost/network/utils/thread_group.hpp b/boost/network/utils/thread_group.hpp index 0540b6afb..d9b14439c 100644 --- a/boost/network/utils/thread_group.hpp +++ b/boost/network/utils/thread_group.hpp @@ -55,7 +55,7 @@ class thread_group { std::unique_lock guard(m); for (auto &thread : threads) { - if (thread->joinable()) { + if (thread->joinable() && thread->get_id() != std::this_thread::get_id()) { thread->join(); } } diff --git a/boost/network/utils/thread_pool.hpp b/boost/network/utils/thread_pool.hpp index bea9ab5ad..515ac586d 100644 --- a/boost/network/utils/thread_pool.hpp +++ b/boost/network/utils/thread_pool.hpp @@ -9,8 +9,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -19,9 +18,9 @@ namespace boost { namespace network { namespace utils { -typedef std::shared_ptr io_service_ptr; +typedef std::shared_ptr io_service_ptr; typedef std::shared_ptr worker_threads_ptr; -typedef std::shared_ptr sentinel_ptr; +typedef std::shared_ptr sentinel_ptr; template struct basic_thread_pool { @@ -55,7 +54,7 @@ struct basic_thread_pool { BOOST_SCOPE_EXIT_END if (!io_service_.get()) { - io_service_.reset(new asio::io_service); + io_service_.reset(new boost::asio::io_service); } if (!worker_threads_.get()) { @@ -63,7 +62,7 @@ struct basic_thread_pool { } if (!sentinel_.get()) { - sentinel_.reset(new asio::io_service::work(*io_service_)); + sentinel_.reset(new boost::asio::io_service::work(*io_service_)); } for (std::size_t counter = 0; counter < threads_; ++counter) { diff --git a/boost/network/version.hpp b/boost/network/version.hpp index f8ca3307a..585c60a63 100644 --- a/boost/network/version.hpp +++ b/boost/network/version.hpp @@ -10,7 +10,7 @@ #include #define BOOST_NETLIB_VERSION_MAJOR 0 -#define BOOST_NETLIB_VERSION_MINOR 12 +#define BOOST_NETLIB_VERSION_MINOR 13 #define BOOST_NETLIB_VERSION_INCREMENT 0 #ifndef BOOST_NETLIB_VERSION diff --git a/deps/asio b/deps/asio deleted file mode 160000 index 66e76b9e4..000000000 --- a/deps/asio +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 66e76b9e4252ff4681227d0d8e34374ec1fa20e5 diff --git a/libs/network/doc/_ext/breathe b/libs/network/doc/_ext/breathe index 853385ef4..65440b267 160000 --- a/libs/network/doc/_ext/breathe +++ b/libs/network/doc/_ext/breathe @@ -1 +1 @@ -Subproject commit 853385ef4f0c3dd126887750e20d5f7456065998 +Subproject commit 65440b2673ebcc5c6ee2792b0b25754effba1183 diff --git a/libs/network/doc/conf.py b/libs/network/doc/conf.py index 79137328e..3cd122423 100644 --- a/libs/network/doc/conf.py +++ b/libs/network/doc/conf.py @@ -62,9 +62,9 @@ # built documents. # # The short X.Y version. -version = '0.11' +version = '0.13' # The full version, including alpha/beta/rc tags. -release = '0.11.2' +release = '0.13.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -111,7 +111,7 @@ # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -html_title = 'cpp-netlib v0.11.2' +html_title = 'cpp-netlib v0.13.0' # A shorter title for the navigation bar. Default is the same as html_title. # html_short_title = 'cpp-netlib' diff --git a/libs/network/doc/examples.rst b/libs/network/doc/examples.rst index 0e359144b..87f549c9d 100644 --- a/libs/network/doc/examples.rst +++ b/libs/network/doc/examples.rst @@ -24,4 +24,3 @@ embedded into larger applications. examples/http/hello_world_server examples/http/hello_world_client examples/http/atom_reader - examples/http/twitter_search diff --git a/libs/network/doc/examples/http/hello_world_server.rst b/libs/network/doc/examples/http/hello_world_server.rst index 3dace4e6e..5e84a6234 100644 --- a/libs/network/doc/examples/http/hello_world_server.rst +++ b/libs/network/doc/examples/http/hello_world_server.rst @@ -27,15 +27,13 @@ simple response to any HTTP request. typedef http::server server; struct hello_world { - void operator()(server::request const &request, server::response &response) { + void operator()(server::request const &request, server::connection_ptr connection) { server::string_type ip = source(request); unsigned int port = request.source_port; std::ostringstream data; data << "Hello, " << ip << ':' << port << '!'; - response = server::response::stock_reply(server::response::ok, data.str()); - } - void log(const server::string_type& message) { - std::cerr << "ERROR: " << message << std::endl; + connection->set_status(server::connection::ok); + connection->write(data.str()); } }; @@ -103,15 +101,12 @@ This header contains all the code needed to develop an HTTP server with typedef http::server server; struct hello_world { - void operator()(server::request const &request, server::response &response) { + void operator()(server::request const &request, server::connection_ptr connection) { server::string_type ip = source(request); unsigned int port = request.source_port; std::ostringstream data; data << "Hello, " << ip << ':' << port << '!'; - response = server::response::stock_reply(server::response::ok, data.str()); - } - void log(const server::string_type& message) { - std::cerr << "ERROR: " << message << std::endl; + connection->write(data.str()); } }; @@ -119,6 +114,8 @@ This header contains all the code needed to develop an HTTP server with All the operator does here is return an HTTP response with HTTP code 200 and the body ``"Hello, :!"``. The ```` in this case would be the IP address of the client that made the request and ```` the clients port. +If you like to send an other status have a look at the function +``set_status(status_t status)`` from connection. There are a number of pre-defined stock replies differentiated by status code with configurable bodies. @@ -144,4 +141,3 @@ The ``options`` constructor's single argument is the handler object defined prev resources across threads. The handler is passed by reference to the server constructor and you should ensure that any calls to the ``operator()`` overload are thread-safe. - diff --git a/libs/network/doc/examples/http/twitter_search.rst b/libs/network/doc/examples/http/twitter_search.rst deleted file mode 100644 index 4b1945d22..000000000 --- a/libs/network/doc/examples/http/twitter_search.rst +++ /dev/null @@ -1,117 +0,0 @@ -.. _twitter_search: - -**************** - Twitter search -**************** - -This example uses `Twitter's search API`_ to list recent tweets given -a user query. New features introduced here include the URI builder -and ``uri::encoded`` function. - -.. _`Twitter's search API`: https://dev.twitter.com/docs/using-search - -The code -======== - -.. code-block:: c++ - - #include - #include "rapidjson/rapidjson.h" - #include "rapidjson/document.h" - #include - - int main(int argc, char *argv[]) { - using namespace boost::network; - using namespace rapidjson; - - if (argc != 2) { - std::cout << "Usage: " << argv[0] << " " << std::endl; - return 1; - } - - try { - http::client client; - - uri::uri base_uri("http://search.twitter.com/search.json"); - - std::cout << "Searching Twitter for query: " << argv[1] << std::endl; - uri::uri search; - search << base_uri << uri::query("q", uri::encoded(argv[1])); - http::client::request request(search); - http::client::response response = client.get(request); - - Document d; - if (!d.Parse<0>(response.body().c_str()).HasParseError()) { - const Value &results = d["results"]; - for (SizeType i = 0; i < results.Size(); ++i) - { - const Value &user = results[i]["from_user_name"]; - const Value &text = results[i]["text"]; - std::cout << "From: " << user.GetString() << std::endl - << " " << text.GetString() << std::endl - << std::endl; - } - } - } - catch (std::exception &e) { - std::cerr << e.what() << std::endl; - } - - return 0; - } - -.. note:: To parse the results of these queries, this example uses - `rapidjson`_, a header-only library that is released under - the `MIT License`_. - -.. _`rapidjson`: https://github.com/miloyip/rapidjson -.. _`MIT License`: http://www.opensource.org/licenses/mit-license.php - -Building and running ``twitter_search`` -======================================= - -.. code-block:: bash - - $ cd ~/cpp-netlib-build - $ make twitter_search - -Twitter provides a powerful set of operators to modify the behaviour -of search queries. Some examples are provided below: - -.. code-block:: bash - - $ ./example/twitter_search "Lady Gaga" - -Returns any results that contain the exact phrase "Lady Gaga". - -.. code-block:: bash - - $ ./example/twitter_search "#olympics" - -Returns any results with the #olympics hash tag. - -.. code-block:: bash - - $ ./example/twitter_search "flight :(" - -Returns any results that contain "flight" and have a negative -attitude. - -More examples can be found on `Twitter's search API`_ page. - -Diving into the code -==================== - -.. code-block:: c++ - - uri::uri base_uri("http://search.twitter.com/search.json"); - - std::cout << "Searching Twitter for query: " << argv[1] << std::endl; - uri::uri search; - search << base_uri << uri::query("q", uri::encoded(argv[1])); - -The :mod:`cpp-netlib` URI builder uses a stream-like syntax to allow -developers to construct more complex URIs. The example above re-uses -the same base URI and allows the command line argument to be used as -part of the URI query. The builder also supports percent encoding -using the ``encoded`` directive. diff --git a/libs/network/doc/getting_started.rst b/libs/network/doc/getting_started.rst index 7350acadd..7df6101d4 100644 --- a/libs/network/doc/getting_started.rst +++ b/libs/network/doc/getting_started.rst @@ -70,7 +70,7 @@ Getting Boost ============= :mod:`cpp-netlib` depends on Boost_. It should work for any version -of Boost above 1.50.0. If Boost is not installed on your system, the +of Boost above 1.58.0. If Boost is not installed on your system, the latest package can be found on the `Boost web-site`_. The environment variable ``BOOST_ROOT`` must be defined, which must be the full path name of the top directory of the Boost distribution. Although Boost @@ -98,10 +98,10 @@ still requires linking with `Boost.System`_, `Boost.Date_time`_, and Getting CMake ============= -The :mod:`cpp-netlib` uses CMake_ to generate platform-specific build files. If -you intend to run the test suite, you can follow the instructions below. -Otherwise, you don't need CMake to use :mod:`cpp-netlib` in your project. The -:mod:`cpp-netlib` requires CMake version 2.8 or higher. +The :mod:`cpp-netlib` uses CMake_ to generate platform-specific build +files. If you intend to run the test suite, you can follow the +instructions below. The :mod:`cpp-netlib` requires CMake version 2.8 +or higher. .. _CMake: http://www.cmake.org/ @@ -234,7 +234,7 @@ Projects using CMake can add the following lines in their ``CMakeLists.txt`` to be able to use :mod:`cpp-netlib`:: set ( CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ~/cpp-netlib-build ) - find_package ( cppnetlib 0.11.0 REQUIRED ) + find_package ( cppnetlib 0.13.0 REQUIRED ) include_directories ( ${CPPNETLIB_INCLUDE_DIRS} ) target_link_libraries ( MyApplication ${CPPNETLIB_LIBRARIES} ) @@ -259,4 +259,3 @@ for the project at http://github.com/cpp-netlib/cpp-netlib/issues. You can also opt to join the developers mailing list for a more personal interaction with the developers of the project. You can join the mailing list through http://groups.google.com/forum/#!forum/cpp-netlib. - diff --git a/libs/network/doc/html/.buildinfo b/libs/network/doc/html/.buildinfo index 38959c6ef..f2943ce0d 100644 --- a/libs/network/doc/html/.buildinfo +++ b/libs/network/doc/html/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: adbe6ea7ac2e69d5b593dfb1e312603d +config: 2a727c93c7f2495ee4d62797d88de6a1 tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/libs/network/doc/html/_sources/contents.rst.txt b/libs/network/doc/html/_sources/contents.rst.txt new file mode 100644 index 000000000..0c41b80a7 --- /dev/null +++ b/libs/network/doc/html/_sources/contents.rst.txt @@ -0,0 +1,14 @@ +.. _contents: + +Contents +-------- + +.. toctree:: + :maxdepth: 4 + + index.rst + whats_new.rst + getting_started.rst + examples.rst + reference.rst + references.rst diff --git a/libs/network/doc/html/_sources/examples.rst.txt b/libs/network/doc/html/_sources/examples.rst.txt new file mode 100644 index 000000000..87f549c9d --- /dev/null +++ b/libs/network/doc/html/_sources/examples.rst.txt @@ -0,0 +1,26 @@ +.. _examples: + +Examples +======== + +The :mod:`cpp-netlib` is a practical library that is designed to aid +the development of applications for that need to communicate using +common networking protocols. The following set of examples describe a +series of realistic examples that use the :mod:`cpp-netlib` for these +kinds of application. All examples are built using CMake. + +HTTP examples +````````````` + +The HTTP component of the :mod:`cpp-netlib` contains a client and server. +The examples that follow show how to use both for programs that can be +embedded into larger applications. + +.. toctree:: + :maxdepth: 1 + + examples/http/http_client + examples/http/simple_wget + examples/http/hello_world_server + examples/http/hello_world_client + examples/http/atom_reader diff --git a/libs/network/doc/html/_sources/examples/http/atom_reader.rst.txt b/libs/network/doc/html/_sources/examples/http/atom_reader.rst.txt new file mode 100644 index 000000000..2e0a9917f --- /dev/null +++ b/libs/network/doc/html/_sources/examples/http/atom_reader.rst.txt @@ -0,0 +1,78 @@ +.. _atom_reader: + +****************** + Atom feed reader +****************** + +The next examples show some simple, more practical applications using +the HTTP client. The first one reads a simple Atom_ feed and prints +the titles of each entry to the console. + +.. _Atom: http://en.wikipedia.org/wiki/Atom_(standard) + +The code +======== + +.. code-block:: c++ + + #include "atom.hpp" + #include + #include + #include + + int main(int argc, char * argv[]) { + using namespace boost::network; + + if (argc != 2) { + std::cout << "Usage: " << argv[0] << " " << std::endl; + return 1; + } + + try { + http::client client; + http::client::request request(argv[1]); + request << header("Connection", "close"); + http::client::response response = client.get(request); + atom::feed feed(response); + + std::cout << "Feed: " << feed.title() + << " (" << feed.subtitle() << ")" << std::endl; + BOOST_FOREACH(const atom::entry &entry, feed) { + std::cout << entry.title() + << " (" << entry.published() << ")" << std::endl; + } + } + catch (std::exception &e) { + std::cerr << e.what() << std::endl; + } + + return 0; + } + +Building and running ``atom_reader`` +==================================== + +.. code-block:: bash + + $ cd ~/cpp-netlib-build + $ make atom_reader + +And to run the example from the command line to access the feed that +lists of all the commits on cpp-netlib's master branch: + +.. code-block:: bash + + $ ./example/atom_reader https://github.com/cpp-netlib/cpp-netlib/commits/master.atom + +Diving into the code +==================== + +Most of this will now be familiar. The response is passed to the +constructor to the ``atom::feed`` class, which parses the resultant +XML. To keep this example as simple as possible, `rapidxml`_, a +header-only XML parser library, was used to parse the response. + +.. _`rapidxml`: http://rapidxml.sourceforge.net/ + +A similar example using RSS feeds exists in +``libs/network/example/rss``. diff --git a/libs/network/doc/html/_sources/examples/http/hello_world_client.rst.txt b/libs/network/doc/html/_sources/examples/http/hello_world_client.rst.txt new file mode 100644 index 000000000..e4163926f --- /dev/null +++ b/libs/network/doc/html/_sources/examples/http/hello_world_client.rst.txt @@ -0,0 +1,94 @@ +.. _hello_world_http_client: + +*************************** + "Hello world" HTTP client +*************************** + +Since we have a "Hello World" HTTP server, let's then create an HTTP client to +access that server. This client will be similar to the HTTP client we made +earlier in the documentation. + +The code +======== + +We want to create a simple HTTP client that just makes a request to the HTTP +server that we created earlier. This really simple client will look like this: + +.. code-block:: c++ + + #include + #include + #include + #include + + namespace http = boost::network::http; + + int main(int argc, char * argv[]) { + if (argc != 3) { + std::cerr << "Usage: " << argv[0] << " address port" << std::endl; + return 1; + } + + try { + http::client client; + std::ostringstream url; + url << "http://" << argv[1] << ":" << argv[2] << "/"; + http::client::request request(url.str()); + http::client::response response = + client.get(request); + std::cout << body(response) << std::endl; + } catch (std::exception & e) { + std::cerr << e.what() << std::endl; + return 1; + } + return 0; + } + +Building and running the client +=============================== + +Just like with the HTTP Server and HTTP client example before, we can build this +example by doing the following on the shell: + +.. code-block:: bash + + $ cd ~/cpp-netlib-build + $ make hello_world_client + +This example can be run from the command line as follows: + +.. code-block:: bash + + $ ./example/hello_world_client http://127.0.0.1:8000 + +.. note:: This assumes that you have the ``hello_world_server`` running on + localhost port 8000. + +Diving into the code +==================== + +All this example shows is how easy it is to write an HTTP client that connects +to an HTTP server, and gets the body of the response. The relevant lines are: + +.. code-block:: c++ + + http::client client; + http::client::request request(url.str()); + http::client::response response = + client.get(request); + std::cout << body(response) << std::endl; + +You can then imagine using this in an XML-RPC client, where you can craft the +XML-RPC request as payload which you can pass as the body to a request, then +perform the request via HTTP: + +.. code-block:: c++ + + http::client client; + http::client::request request("http://my.webservice.com/"); + http::client::response = + client.post(request, some_xml_string, "application/xml"); + std::data = body(response); + +The next set of examples show some more practical applications using +the :mod:`cpp-netlib` HTTP client. diff --git a/libs/network/doc/html/_sources/examples/http/hello_world_server.rst.txt b/libs/network/doc/html/_sources/examples/http/hello_world_server.rst.txt new file mode 100644 index 000000000..5e84a6234 --- /dev/null +++ b/libs/network/doc/html/_sources/examples/http/hello_world_server.rst.txt @@ -0,0 +1,143 @@ +.. _hello_world_http_server: + +*************************** + "Hello world" HTTP server +*************************** + +Now that we've seen how we can deal with request and response objects from the +client side, we'll see how we can then use the same abstractions on the server +side. In this example we're going to create a simple HTTP Server in C++ using +:mod:`cpp-netlib`. + +The code +======== + +The :mod:`cpp-netlib` provides the framework to develop embedded HTTP +servers. For this example, the server is configured to return a +simple response to any HTTP request. + +.. code-block:: c++ + + #include + #include + + namespace http = boost::network::http; + + struct hello_world; + typedef http::server server; + + struct hello_world { + void operator()(server::request const &request, server::connection_ptr connection) { + server::string_type ip = source(request); + unsigned int port = request.source_port; + std::ostringstream data; + data << "Hello, " << ip << ':' << port << '!'; + connection->set_status(server::connection::ok); + connection->write(data.str()); + } + }; + + int main(int argc, char *argv[]) { + + if (argc != 3) { + std::cerr << "Usage: " << argv[0] << " address port" << std::endl; + return 1; + } + + try { + hello_world handler; + server::options options(handler); + server server_(options.address(argv[1]).port(argv[2])); + server_.run(); + } + catch (std::exception &e) { + std::cerr << e.what() << std::endl; + return 1; + } + + return 0; + } + +This is about a straightforward as server programming will get in C++. + +Building and running the server +=============================== + +Just like with the HTTP client, we can build this example by doing the following +on the shell: + +.. code-block:: bash + + $ cd ~/cpp-netlib-build + $ make hello_world_server + +The first two arguments to the ``server`` constructor are the host and +the port on which the server will listen. The third argument is the +the handler object defined previously. This example can be run from +a command line as follows: + +.. code-block:: bash + + $ ./example/hello_world_server 0.0.0.0 8000 + +.. note:: If you're going to run the server on port 80, you may have to run it + as an administrator. + +Diving into the code +==================== + +Let's take a look at the code listing above in greater detail. + +.. code-block:: c++ + + #include + +This header contains all the code needed to develop an HTTP server with +:mod:`cpp-netlib`. + +.. code-block:: c++ + + struct hello_world; + typedef http::server server; + + struct hello_world { + void operator()(server::request const &request, server::connection_ptr connection) { + server::string_type ip = source(request); + unsigned int port = request.source_port; + std::ostringstream data; + data << "Hello, " << ip << ':' << port << '!'; + connection->write(data.str()); + } + }; + +``hello_world`` is a functor class which handles HTTP requests. +All the operator does here is return an HTTP response with HTTP code 200 +and the body ``"Hello, :!"``. The ```` in this case would be +the IP address of the client that made the request and ```` the clients port. +If you like to send an other status have a look at the function +``set_status(status_t status)`` from connection. + +There are a number of pre-defined stock replies differentiated by +status code with configurable bodies. +All the supported enumeration values for the response status codes can be found +in ``boost/network/protocol/http/impl/response.ipp``. + +.. code-block:: c++ + + hello_world handler; + server::options options(handler); + server server_(options.address(argv[1]).port(argv[2])); + server_.run(); + +The ``server`` constructor requires an object of the ``options`` class, +this object stores all needed options, especially the host and +the port on which the server will listen. +The ``options`` constructor's single argument is the handler object defined previously. + +.. note:: In this example, the server is specifically made to be single-threaded. + In a multi-threaded server, you would invoke the ``hello_world::run`` member + method in a set of threads. In a multi-threaded environment you would also + make sure that the handler does all the necessary synchronization for shared + resources across threads. The handler is passed by reference to the server + constructor and you should ensure that any calls to the ``operator()`` overload + are thread-safe. diff --git a/libs/network/doc/html/_sources/examples/http/http_client.rst.txt b/libs/network/doc/html/_sources/examples/http/http_client.rst.txt new file mode 100644 index 000000000..9b423dd00 --- /dev/null +++ b/libs/network/doc/html/_sources/examples/http/http_client.rst.txt @@ -0,0 +1,125 @@ +.. _http_client: + +************* + HTTP client +************* + +The first code example is the simplest thing you can do with the +:mod:`cpp-netlib`. The application is a simple HTTP client, which can +be found in the subdirectory ``libs/network/example/http_client.cpp``. +All this example doing is creating and sending an HTTP request to a server +and printing the response body. + +The code +======== + +Without further ado, the code to do this is as follows: + +.. code-block:: c++ + + #include + #include + + int main(int argc, char *argv[]) { + using namespace boost::network; + + if (argc != 2) { + std::cout << "Usage: " << argv[0] << " [url]" << std::endl; + return 1; + } + + http::client client; + http::client::request request(argv[1]); + request << header("Connection", "close"); + http::client::response response = client.get(request); + std::cout << body(response) << std::endl; + + return 0; + } + +Running the example +=================== + +You can then run this to get the Boost_ website: + +.. code-block:: bash + + $ cd ~/cpp-netlib-build + $ make http_client + $ ./example/http_client http://www.boost.org/ + +.. _Boost: http://www.boost.org/ + +.. note:: + + The instructions for all these examples assume that + :mod:`cpp-netlib` is build outside the source tree, + according to `CMake conventions`_. For the sake of + consistency we assume that this is in the + ``~/cpp-netlib-build`` directory. + +.. _`CMake conventions`: http://www.cmake.org/Wiki/CMake_FAQ#What_is_an_.22out-of-source.22_build.3F + +Diving into the code +==================== + +Since this is the first example, each line will be presented and +explained in detail. + +.. code-block:: c++ + + #include + +All the code needed for the HTTP client resides in this header. + +.. code-block:: c++ + + http::client client; + +First we create a ``client`` object. The ``client`` abstracts all the +connection and protocol logic. The default HTTP client is version +1.1, as specified in `RFC 2616`_. + +.. code-block:: c++ + + http::client::request request(argv[1]); + +Next, we create a ``request`` object, with a URI string passed as a +constructor argument. + +.. code-block:: c++ + + request << header("Connection", "close"); + +:mod:`cpp-netlib` makes use of stream syntax and *directives* to allow +developers to build complex message structures with greater +flexibility and clarity. Here, we add the HTTP header "Connection: +close" to the request in order to signal that the connection will be +closed after the request has completed. + +.. code-block:: c++ + + http::client::response response = client.get(request); + +Once we've built the request, we then make an HTTP GET request +throught the ``http::client`` from which an ``http::response`` is +returned. ``http::client`` supports all common HTTP methods: GET, +POST, HEAD, DELETE. + +.. code-block:: c++ + + std::cout << body(response) << std::endl; + +Finally, though we don't do any error checking, the response body is +printed to the console using the ``body`` directive. + +That's all there is to the HTTP client. In fact, it's possible to +compress this to a single line: + +.. code-block:: c++ + + std::cout << body(http::client().get(http::request("http://www.boost.org/"))); + +The next example will introduce the ``uri`` class. + +.. _`RFC 2616`: http://www.w3.org/Protocols/rfc2616/rfc2616.html diff --git a/libs/network/doc/html/_sources/examples/http/simple_wget.rst.txt b/libs/network/doc/html/_sources/examples/http/simple_wget.rst.txt new file mode 100644 index 000000000..c78491627 --- /dev/null +++ b/libs/network/doc/html/_sources/examples/http/simple_wget.rst.txt @@ -0,0 +1,110 @@ +.. _simple_wget: + +*************** + Simple `wget` +*************** + +This example is a very simple implementation of a ``wget`` style +clone. It's very similar to the previous example, but introduces the +``uri`` class. + +The code +======== + +.. code-block:: c++ + + #include + #include + #include + #include + #include + + namespace http = boost::network::http; + namespace uri = boost::network::uri; + + namespace { + std::string get_filename(const uri::uri &url) { + std::string path = uri::path(url); + std::size_t index = path.find_last_of('/'); + std::string filename = path.substr(index + 1); + return filename.empty()? "index.html" : filename; + } + } // namespace + + int + main(int argc, char *argv[]) { + if (argc != 2) { + std::cerr << "Usage: " << argv[0] << " url" << std::endl; + return 1; + } + + try { + http::client client; + http::client::request request(argv[1]); + http::client::response response = client.get(request); + + std::string filename = get_filename(request.uri()); + std::cout << "Saving to: " << filename << std::endl; + std::ofstream ofs(filename.c_str()); + ofs << static_cast(body(response)) << std::endl; + } + catch (std::exception &e) { + std::cerr << e.what() << std::endl; + return 1; + } + + return 0; + } + +Running the example +=================== + +You can then run this to copy the Boost_ website: + +.. code-block:: bash + + $ cd ~/cpp-netlib-build + $ make simple_wget + $ ./example/simple_wget http://www.boost.org/ + $ cat index.html + +.. _Boost: http://www.boost.org/ + +Diving into the code +==================== + +As with ``wget``, this example simply makes an HTTP request to the +specified resource, and saves it on the filesystem. If the file name +is not specified, it names the resultant file as ``index.html``. + +The new thing to note here is use of the ``uri`` class. The ``uri`` +takes a string as a constructor argument and parses it. The ``uri`` +parser is fully-compliant with `RFC 3986`_. The URI is provided in +the following header: + +.. _`RFC 3986`: http://www.ietf.org/rfc/rfc3986.txt + +.. code-block:: c++ + + #include + +Most of the rest of the code is familiar from the previous example. +To retrieve the URI resource's file name, the following function is +provided: + +.. code-block:: c++ + + std::string get_filename(const uri::uri &url) { + std::string path = uri::path(url); + std::size_t index = path.find_last_of('/'); + std::string filename = path.substr(index + 1); + return filename.empty()? "index.html" : filename; + } + +The ``uri`` interface provides access to its different components: +``scheme``, ``user_info``, ``host``, ``port``, ``path``, ``query`` and +``fragment``. The code above takes the URI path to determine the +resource name. + +Next we'll develop a simple client/server application using +``http::server`` and ``http::client``. diff --git a/libs/network/doc/html/_sources/getting_started.rst.txt b/libs/network/doc/html/_sources/getting_started.rst.txt new file mode 100644 index 000000000..7df6101d4 --- /dev/null +++ b/libs/network/doc/html/_sources/getting_started.rst.txt @@ -0,0 +1,261 @@ +.. _getting_started: + +***************** + Getting Started +***************** + +Downloading an official release +=============================== + +You can find links to the latest official release from the project's official +website: + + http://cpp-netlib.org/ + +All previous stable versions of :mod:`cpp-netlib` can be downloaded from +Github_ from this url: + + http://github.com/cpp-netlib/cpp-netlib/downloads + +Each release is available as gzipped (Using the command +``tar xzf cpp-netlib.tar.gz``) or bzipped (Using ``tar xjf +cpp-netlib.tar.bz2``) tarball, or as a zipfile (``unzip +cpp-netlib.zip``, or on Windows using a tool such as 7zip_). + +.. _Github: http://github.com/cpp-netlib/cpp-netlib/downloads +.. _7zip: http://www.7-zip.org/ + +Downloading a development version +================================= + +The :mod:`cpp-netlib` uses Git_ for source control, so to use any +development versions Git must be installed on your system. + +Using the command line, the command to get the latest code is: + +:: + + shell$ git clone git://github.com/cpp-netlib/cpp-netlib.git + +This should be enough information get to started. To do more complex +things with Git, such as pulling changes or checking out a new branch, +refer to the `Git documentation`_. + +.. note:: Previous versions of :mod:`cpp-netlib` referred to the + *mikhailberis* repository as the main development repository. This + account is still valid, but not always up-to-date. In the interest of + consistency, the main repository has been changed to *cpp-netlib*. + +Windows users need to use msysGit_, and to invoke the command above +from a shell. + +For fans of Subversion_, the same code can be checked out from +http://svn.github.com/cpp-netlib/cpp-netlib.git. + +.. _Git: http://git-scm.com/ +.. _`Git documentation`: http://git-scm.com/documentation +.. _msysGit: http://code.google.com/p/msysgit/downloads/list +.. _Subversion: http://subversion.tigris.org/ + +.. note:: The :mod:`cpp-netlib` project is hosted on GitHub_ and follows the + prescribed development model for GitHub_ based projects. This means in case + you want to submit patches, you will have to create a fork of the project + (read up on forking_) and then submit a pull request (read up on submitting + `pull requests`_). + +.. _forking: http://help.github.com/forking/ +.. _`pull requests`: http://help.github.com/pull-requests/ + +Getting Boost +============= + +:mod:`cpp-netlib` depends on Boost_. It should work for any version +of Boost above 1.58.0. If Boost is not installed on your system, the +latest package can be found on the `Boost web-site`_. The environment +variable ``BOOST_ROOT`` must be defined, which must be the full path +name of the top directory of the Boost distribution. Although Boost +is mostly header only, applications built using :mod:`cpp-netlib` +still requires linking with `Boost.System`_, `Boost.Date_time`_, and +`Boost.Regex`_. + +.. _Boost: http://www.boost.org/doc/libs/release/more/getting_started/index.html +.. _`Boost web-site`: http://www.boost.org/users/download/ +.. _`Boost.System`: http://www.boost.org/libs/system/index.html +.. _`Boost.Date_time`: http://www.boost.org/libs/date_time/index.html +.. _`Boost.Regex`: http://www.boost.org/libs/regex/index.html + +.. note:: You can follow the steps in the `Boost Getting Started`_ guide to + install Boost into your development system. + +.. _`Boost Getting Started`: + http://www.boost.org/doc/libs/release/more/getting_started/index.html + +.. warning:: There is a known incompatibility between :mod:`cpp-netlib` and + Boost 1.46.1 on some compilers. It is not recommended to use :mod:`cpp-netlib` + with Boost 1.46.1. Some have reported though that Boost 1.47.0 + and :mod:`cpp-netlib` work together better. + +Getting CMake +============= + +The :mod:`cpp-netlib` uses CMake_ to generate platform-specific build +files. If you intend to run the test suite, you can follow the +instructions below. The :mod:`cpp-netlib` requires CMake version 2.8 +or higher. + +.. _CMake: http://www.cmake.org/ + +Let's assume that you have unpacked the :mod:`cpp-netlib` at the top of your +HOME directory. On Unix-like systems you will typically be able to change into +your HOME directory using the command ``cd ~``. This sample below assumes that +the ``~/cpp-netlib`` directory exists, and is the top-level directory of the +:mod:`cpp-netlib` release. + +Building with CMake +=================== + +To build the tests that come with :mod:`cpp-netlib`, we first need to configure the +build system to use our compiler of choice. This is done by running the +``cmake`` command at the top-level directory of :mod:`cpp-netlib` with +additional parameters:: + + $ mkdir ~/cpp-netlib-build + $ cd ~/cpp-netlib-build + $ cmake -DCMAKE_BUILD_TYPE=Debug \ + > -DCMAKE_C_COMPILER=gcc \ + > -DCMAKE_CXX_COMPILER=g++ \ + > ../cpp-netlib + +.. note:: + + While it's not compulsory, it's recommended that + :mod:`cpp-netlib` is built outside the source directory. + For the purposes of documentation, we'll assume that all + builds are done in ``~/cpp-netlib-build``. + +If you intend to use the SSL support when using the HTTP client libraries in +:mod:`cpp-netlib`, you may need to build it with OpenSSL_ installed or at least +available to CMake. If you have the development headers for OpenSSL_ installed +on your system when you build :mod:`cpp-netlib`, CMake will be able to detect it +and set the ``BOOST_NETWORK_ENABLE_HTTPS`` macro when building the library to +support HTTPS URIs. + +One example for building the library with OpenSSL_ support with a custom +(non-installed) version of OpenSSL_ is by doing the following:: + + $ cmake -DCMAKE_BUILD_TYPE=Debug \ + > -DCMAKE_C_COMPILER=clang \ + > -DCMAKE_CXX_COMPILER=clang++ \ + > -DOPENSSL_ROOT_DIR=/Users/dberris/homebrew/Cellar/openssl/1.0.1f + > ../cpp-netlib + +.. _OpenSSL: http://www.openssl.org/ + +You can also use a different root directory for the Boost_ project by using the +``-DBOOST_ROOT`` configuration option to CMake. This is useful if you intend to +build the library with a specific version of Boost that you've built in a +separate directory:: + + $ cmake -DCMAKE_BUILD_TYPE=Debug \ + > -DCMAKE_C_COMPILER=clang \ + > -DCMAKE_CXX_COMPILER=clang++ \ + > -DOPENSSL_ROOT_DIR=/Users/dberris/homebrew/Cellar/openssl/1.0.1f \ + > -DBOOST_ROOT=/Users/dberris/Source/boost_1_55_0 + > ../cpp-netlib + +Building on Linux +~~~~~~~~~~~~~~~~~ + +On Linux, this will generate the appropriate Makefiles that will enable you to +build and run the tests and examples that come with :mod:`cpp-netlib`. To build +the tests, you can run ``make`` in the same top-level directory of +``~/cpp-netlib-build``:: + + $ make + +.. note:: Just like with traditional GNU Make, you can add the ``-j`` parameter + to specify how many parallel builds to run. In case you're in a sufficiently + powerful system and would like to parallelize the build into 4 jobs, you can + do this with:: + + make -j4 + + As a caveat, :mod:`cpp-netlib` is heavy on template metaprogramming and will + require a lot of computing and memory resources to build the individual + tests. Do this at the risk of thrashing_ your system. However, this + compile-time burden is much reduced in recent versions. + +.. _thrashing: http://en.wikipedia.org/wiki/Thrashing_(computer_science) + +Once the build has completed, you can now run the test suite by issuing:: + + $ make test + +You can install :mod:`cpp-netlib` by issuing:: + + $ sudo make install + +By default this installs :mod:`cpp-netlib` into ``/usr/local``. + +.. note:: As of version 0.9.3, :mod:`cpp-netlib` produces three static + libraries. Using GCC on Linux these are:: + + libcppnetlib-client-connections.a + libcppnetlib-server-parsers.a + libcppnetlib-uri.a + + Users can find them in ``~/cpp-netlib-build/libs/network/src``. + +Building On Windows +~~~~~~~~~~~~~~~~~~~ + +If you're using the Microsoft Visual C++ compiler or the Microsoft Visual Studio +IDE and you would like to build :mod:`cpp-netlib` from within Visual Studio, you +can look for the solution and project files as the artifacts of the call to +``cmake`` -- the file should be named ``CPP-NETLIB.sln`` (the solution) along +with a number of project files for Visual Studio. + +.. note:: As of version 0.9.3, :mod:`cpp-netlib` produces three static + libraries. Using Visual C++ on Windows they are:: + + cppnetlib-client-connections.lib + cppnetlib-server-parsers.lib + cppnetlib-uri.lib + + Users can find them in ``~/cpp-netlib-build/libs/network/src``. + +Using :mod:`cpp-netlib` +======================= + +CMake projects +~~~~~~~~~~~~~~ + +Projects using CMake can add the following lines in their ``CMakeLists.txt`` to +be able to use :mod:`cpp-netlib`:: + + set ( CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ~/cpp-netlib-build ) + find_package ( cppnetlib 0.13.0 REQUIRED ) + include_directories ( ${CPPNETLIB_INCLUDE_DIRS} ) + target_link_libraries ( MyApplication ${CPPNETLIB_LIBRARIES} ) + +.. note:: Setting ``CMAKE_PREFIX_PATH`` is only required when :mod:`cpp-netlib` + is not installed to a location that CMake searches. When :mod:`cpp-netlib` + is installed to the default location (``/usr/local``), ``CMake`` can find it. + +.. note:: We assume that ``MyApplication`` is the application that you are + building and which depends on :mod:`cpp-netlib`. + + +Reporting Issues, Getting Support +================================= + +In case you find yourself stuck or if you've found a bug (or you want to just +join the discussion) you have a few options to choose from. + +For reporting bugs, feature requests, and asking questions about the +implementation and/or the documentation, you can go to the GitHub issues page +for the project at http://github.com/cpp-netlib/cpp-netlib/issues. + +You can also opt to join the developers mailing list for a more personal +interaction with the developers of the project. You can join the mailing list +through http://groups.google.com/forum/#!forum/cpp-netlib. diff --git a/libs/network/doc/html/_sources/index.rst.txt b/libs/network/doc/html/_sources/index.rst.txt new file mode 100644 index 000000000..0c6f5e374 --- /dev/null +++ b/libs/network/doc/html/_sources/index.rst.txt @@ -0,0 +1,122 @@ +.. _index: +.. rubric:: Straightforward network programming in modern C++ + +.. :Authors: Glyn Matthews +.. Dean Michael Berris +.. :Date: 2016-10-05 +.. :Version: 0.13.0 +.. :Description: Complete user documentation, with examples, for the :mod:`cpp-netlib`. +.. :Copyright: Copyright Glyn Matthews, Dean Michael Berris 2008-2013. +.. Copyrigh 2013 Google, Inc. +.. Distributed under the Boost Software License, Version +.. 1.0. (See accompanying file LICENSE_1_0.txt or copy at +.. http://www.boost.org/LICENSE_1_0.txt) + +Getting cpp-netlib +================== + +You can find out more about the :mod:`cpp-netlib` project at +http://cpp-netlib.org/. + +**Download** + +You can get the latest official version of the library from the official +project website at: + + http://cpp-netlib.org/ + +This version of :mod:`cpp-netlib` is tagged as cpp-netlib-0.13.0 in the GitHub_ +repository. You can find more information about the progress of the development +by checking our GitHub_ project page at: + + http://github.com/cpp-netlib/cpp-netlib + +**Support** + +You can ask questions, join the discussion, and report issues to the +developers mailing list by joining via: + + https://groups.google.com/group/cpp-netlib + +You can also file issues on the Github_ issue tracker at: + + http://github.com/cpp-netlib/cpp-netlib/issues + +We are a growing community and we are happy to accept new +contributions and ideas. + +C++ Network Library +=================== + +:mod:`cpp-netlib` is a library collection that provides application layer +protocol support using modern C++ techniques. It is light-weight, fast, +portable and is intended to be as easy to configure as possible. + +Hello, world! +============= + +The :mod:`cpp-netlib` allows developers to write fast, portable +network applications with the minimum of fuss. + +An HTTP server-client example can be written in tens of lines of code. +The client is as simple as this: + +.. code-block:: cpp + + using namespace boost::network; + using namespace boost::network::http; + + client::request request_("http://127.0.0.1:8000/"); + request_ << header("Connection", "close"); + client client_; + client::response response_ = client_.get(request_); + std::string body_ = body(response_); + +And the corresponding server code is listed below: + +.. code-block:: cpp + + namespace http = boost::network::http; + + struct handler; + typedef http::server http_server; + + struct handler { + void operator() (http_server::request const &request, + http_server::response &response) { + response = http_server::response::stock_reply( + http_server::response::ok, "Hello, world!"); + } + + void log(http_server::string_type const &info) { + std::cerr << "ERROR: " << info << '\n'; + } + }; + + int main(int arg, char * argv[]) { + handler handler_; + http_server::options options(handler_); + http_server server_( + options.address("0.0.0.0") + .port("8000")); + server_.run(); + } + +Want to learn more? +=================== + + * :ref:`Take a look at the getting started guide ` + * :ref:`Learn from some simple examples ` + * :ref:`Find out what's new ` + * :ref:`Discover more through the full reference ` + * :ref:`Full table of contents ` + +.. warning:: Be aware that not all features are stable. The generic + message design is under review and the URI and HTTP + client implementation will continue to undergo + refactoring. Future versions will include support for + other network protocols. + + +.. _Boost: http://www.boost.org/ +.. _GitHub: http://github.com/ diff --git a/libs/network/doc/html/_sources/reference.rst.txt b/libs/network/doc/html/_sources/reference.rst.txt new file mode 100644 index 000000000..d4cbf99d2 --- /dev/null +++ b/libs/network/doc/html/_sources/reference.rst.txt @@ -0,0 +1,16 @@ +.. _reference: + +Reference Manual +================ + +This reference manual refers to the API documentation of the public interfaces +to the different client and/or server implementations within :mod:`cpp-netlib`. + +.. toctree:: + :maxdepth: 2 + + reference/http_client + reference/http_request + reference/http_response + reference/http_server + diff --git a/libs/network/doc/html/_sources/reference/http_client.rst.txt b/libs/network/doc/html/_sources/reference/http_client.rst.txt new file mode 100644 index 000000000..212193d00 --- /dev/null +++ b/libs/network/doc/html/_sources/reference/http_client.rst.txt @@ -0,0 +1,241 @@ + +HTTP Client API +=============== + +General +------- + +:mod:`cpp-netlib` includes and implements a number of HTTP clients that you can +use and embed in your own applications. All of the HTTP client implementations: + + * **Cannot be copied.** This means you may have to store instances of the + clients in dynamic memory if you intend to use them as function parameters + or pass them around in smart pointers or by reference. + * **Assume that requests made are independent of each other.** There currently + is no cookie or session management system built-in to cpp-netlib's HTTP client + implementations. + +The HTTP clients all share the same API, but the internals are documented in +terms of what is different and what to expect with the different +implementations. + +Features +-------- + +The HTTP client implementation supports requesting secure HTTP (HTTPS) content +only in the following situations: + + * **Client libraries are built with ``BOOST_NETWORK_ENABLE_HTTPS``.** This + tells the implementation to use HTTPS-specific code to handle HTTPS-based + content when making connections associated with HTTPS URI's. This requires + a dependency on OpenSSL_. + * **The ``BOOST_NETWORK_ENABLE_HTTPS`` macro is set when compiling user + code.** It is best to define this either at compile-time of all code using + the library, or before including any of the client headers. + +To use the client implementations that support HTTPS URIs, you may explicitly +do the following: + +.. code-block:: c++ + + #define BOOST_NETWORK_ENABLE_HTTPS + #include + +This forces HTTPS support to be enabled and forces a dependency on OpenSSL_. +This dependency is imposed by `Boost.Asio`_ + +.. _OpenSSL: http://www.openssl.org/ +.. _`Boost.Asio`: http://www.boost.org/libs/asio + +Client Implementation +--------------------- + +There is a single user-facing template class named ``basic_client`` which takes +three template parameters: + + * **Tag** - which static tag you choose that defines the behavior of the client. + + * **http_version_major** - an unsigned int that defines the HTTP major version + number, this directly affects the HTTP messages sent by the client. + + * **http_version_minor** - an unsigned int that defines the HTTP minor version + number. + +.. include:: ../in_depth/http_client_tags.rst + +In the above table the tags follow a pattern for describing the behavior +introduced by the tags. This pattern is shown below: + + ___ + +For example, the tag ``http_default_8bit_tcp_resolve`` indicates the protocol +``http``, a modifier ``default``, a character width of ``8bit``, and a resolve +strategy of ``tcp_resolve``. + +The client is implemented as an `Active Object`_. This means that the client +has and manages its own lifetime thread, and returns values that are +asynchronously filled in. The response object encapsulates futures which get +filled in once the values are available. + +.. _`Active Object`: http://en.wikipedia.org/wiki/Active_object + +.. note:: The client objects are thread safe, and can be shared across many + threads. Each request starts a sequence of asynchronous operations dedicated + to that request. The client does not re-cycle connections and uses a + one-request-one-connection model. + +When a client object is destroyed, it waits for all pending asynchronous +operations to finish. Errors encountered during operations on retrieving data +from the response objects cause exceptions to be thrown -- therefore it is best +that if a client object is constructed, it should outlive the response object +or be outside the try-catch block handling the errors from operations on +responses. In code, usage should look like the following: + +.. code-block:: c++ + + http::client client; + try { + http::client::response response = client.get("http://www.example.com/"); + std::cout << body(response); + } catch (std::exception& e) { + // deal with exceptions here + } + +A common mistake is to declare the client inside the try block which invokes +undefined behavior when errors arise from the handling of response objects. +Previous examples cited by the documentation showed the short version of the +code which didn't bother moving the ``http::client`` object outside of the same +``try`` block where the request/response objects are being used. + +Member Functions +---------------- + +In this section we assume that the following typedef is in effect: + +.. code-block:: c++ + + typedef boost::network::http::basic_client< + boost::network::http::tags::http_default_8bit_udp_resolve + , 1 + , 1 + > + client; + +Also, that code using the HTTP client will have use the following header: + +.. code-block:: c++ + + #include + +Constructors +~~~~~~~~~~~~ + +The client implementation can be default constructed, or customized at +initialization. + +``client()`` + Default constructor. +``explicit client(client::options const &)`` + Constructor taking a ``client_options`` object. The following table + shows the options you can set on a ``client_options`` instance. + +Client Options +~~~~~~~~~~~~~~ + +.. doxygenclass:: boost::network::http::client_options + :project: cppnetlib + :members: + +To use the above supported named parameters, you'll have code that looks like +the following: + +.. code-block:: c++ + + using namespace boost::network::http; // parameters are in this namespace + client::options options; + options.follow_redirects(true) + .cache_resolved(true) + .io_service(boost::make_shared()) + .openssl_certificate("/tmp/my-cert") + .openssl_verify_path("/tmp/ca-certs") + .timeout(10); + client client_(options); + // use client_ as normal from here on out. + +HTTP Methods +~~~~~~~~~~~~ + +The client implementation supports various HTTP methods. The following +constructs assume that a client has been properly constructed named ``client_`` +and that there is an appropriately constructed request object named ``request_`` +and that there is an appropriately constructed response object named +``response_`` like the following: + +.. code-block:: c++ + + using namespace boost::network::http; // parameters are here + client client_(); + client::request request_("http://cpp-netib.github.com/"); + client::response response_; + + +.. doxygenclass:: boost::network::http::basic_client + :project: cppnetlib + :members: + :undoc-members: + +.. doxygentypedef:: boost::network::http::client + :project: cppnetlib + +Streaming Body Handler +~~~~~~~~~~~~~~~~~~~~~~ + +As of v0.9.1 the library now offers a way to support a streaming body callback +function in all HTTP requests that expect a body part (GET, PUT, POST, DELETE). +A convenience macro is also provided to make callback handlers easier to write. +This macro is called ``BOOST_NETWORK_HTTP_BODY_CALLBACK`` which allows users to +write the following code to easily create functions or function objects that +are compatible with the callback function requirements. + +An example of how to use the macro is shown below: + +.. code-block:: c++ + + struct body_handler { + explicit body_handler(std::string & body) + : body(body) {} + + BOOST_NETWORK_HTTP_BODY_CALLBACK(operator(), range, error) { + // in here, range is the Boost.Range iterator_range, and error is + // the Boost.System error code. + if (!error) + body.append(boost::begin(range), boost::end(range)); + } + + std::string & body; + }; + + // somewhere else + std::string some_string; + response_ = client_.get(request("http://cpp-netlib.github.com/"), + body_handler(some_string)); + +You can also use if for standalone functions instead if you don't want or need +to create a function object. + +.. code-block:: c++ + + BOOST_NETWORK_HTTP_BODY_CALLBACK(print_body, range, error) { + if (!error) + std::cout << "Received " << boost::distance(range) << "bytes." + << std::endl; + else + std::cout << "Error: " << error << std::endl; + } + + // somewhere else + response_ = client_.get(request("http://cpp-netlib.github.com/"), + print_body); + +The ``BOOST_NETWORK_HTTP_BODY_CALLBACK`` macro is defined in +``boost/network/protocol/http/client/macros.hpp``. diff --git a/libs/network/doc/html/_sources/reference/http_request.rst.txt b/libs/network/doc/html/_sources/reference/http_request.rst.txt new file mode 100644 index 000000000..cbef6e187 --- /dev/null +++ b/libs/network/doc/html/_sources/reference/http_request.rst.txt @@ -0,0 +1,254 @@ + +HTTP Request +============ + +This part of the documentation talks about the publicly accessible API of the +HTTP Request objects. This section details the `Request Concepts`_ requirements, +the implemented and required Directives_, Modifiers_, and Wrappers_ that work +with the HTTP Request objects. + +Request Concepts +---------------- + +There are two generally supported Request Concepts implemented in the library. +The first of two is the `Normal Client Request Concept`_ and the second is the +`Pod Server Request Concept`_. + +The `Normal Client Request Concept`_ is what the HTTP Client interface requires. +All operations performed internally by the HTTP Client abide by the interface +required by this concept definition. + +The `Pod Server Request Concept`_ is as the name suggests what the HTTP Server +implementation requires from Request Objects. + +Switching on whether the `Request` concept chooses either of the `Normal Client +Request Concept`_ or the `Pod Server Request Concept`_ is done through the +nested ``tag`` type and whether that tag derives from the root tag ``pod``. +Simply, if the Request type's nested ``tag`` type derives from +``boost::network::tags::pod`` then it chooses to enforce the `Pod Server Request +Concept`_, otherwise it chooses the `Normal Client Request Concept`_. + +Normal Client Request Concept +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +A type models the Normal Client Request Concept if it models the `Message +Concept`_ and also supports the following constructs. + +**Legend** + +:R: The request type. +:r: An instance of R. +:S: The string type. +:s: An instance of S. +:P: The port type. +:p: An instance of P. + ++-----------------------+-------------+----------------------------------------+ +| Construct | Result | Description | ++=======================+=============+========================================+ +| ``R::string_type`` | ``S`` | The nested ``string_type`` type. | ++-----------------------+-------------+----------------------------------------+ +| ``R::port_type`` | ``P`` | The nested ``port_type`` type. | ++-----------------------+-------------+----------------------------------------+ +| ``R r(s)`` | **NA** | Construct a Request with an ``s`` | +| | | provided. This treats ``s`` as the URI | +| | | to where the request is destined for. | ++-----------------------+-------------+----------------------------------------+ +| ``host(request)`` | Convertible | Return the host to where the request | +| | to ``S`` | is destined for. | ++-----------------------+-------------+----------------------------------------+ +| ``port(request)`` | Convertible | Return the port to where the request | +| | to ``P`` | is destined for. | ++-----------------------+-------------+----------------------------------------+ +| ``path(request)`` | Convertible | Return the path included in the URI. | +| | to ``S`` | | ++-----------------------+-------------+----------------------------------------+ +| ``query(request)`` | Convertible | Return the query part of the URI. | +| | to ``S`` | | ++-----------------------+-------------+----------------------------------------+ +| ``anchor(request)`` | Convertible | Return the anchor part of the URI. | +| | to ``S`` | | ++-----------------------+-------------+----------------------------------------+ +| ``protocol(request)`` | Convertible | Return the protocol/scheme part of the | +| | to ``S`` | URI. | ++-----------------------+-------------+----------------------------------------+ +| ``r << uri(s)`` | ``R&`` | Set the URI of the request. | ++-----------------------+-------------+----------------------------------------+ +| ``uri(r, s)`` | ``void`` | Set the URI of the request. | ++-----------------------+-------------+----------------------------------------+ + +Pod Server Request Concept +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +A type models the Pod Server Request Concept if it models the `Message Concept`_ +and also supports the following constructs. + +**Legend** + +:R: The request type. +:r: An instance of R. +:S: The string type. +:I: An unsigned 8 bit integer. +:V: The vector type for headers. + ++-------------------------------+--------+-------------------------------------+ +| Construct | Result | Description | ++===============================+========+=====================================+ +| ``R::string_type`` | ``S`` | The nested ``string_type`` type. | ++-------------------------------+--------+-------------------------------------+ +| ``R::headers_container_type`` | ``V`` | The nested | +| | | ``headers_container_type`` type. | ++-------------------------------+--------+-------------------------------------+ +| ``r.source`` | ``S`` | The nested source of the request. | ++-------------------------------+--------+-------------------------------------+ +| ``r.method`` | ``S`` | The method of the request. | ++-------------------------------+--------+-------------------------------------+ +| ``r.destination`` | ``S`` | The destination of the request. | +| | | This is normally the URI of the | +| | | request. | ++-------------------------------+--------+-------------------------------------+ +| ``r.version_major`` | ``I`` | The major version number part of | +| | | the request. | ++-------------------------------+--------+-------------------------------------+ +| ``r.version_minor`` | ``I`` | The minor version number part of | +| | | the request. | ++-------------------------------+--------+-------------------------------------+ +| ``r.headers`` | ``V`` | The vector of headers. | ++-------------------------------+--------+-------------------------------------+ +| ``r.body`` | ``S`` | The body of the request. | ++-------------------------------+--------+-------------------------------------+ + +.. _Message Concept: ../in_depth/message.html#message-concept + +Directives +---------- + +This section details the provided directives that are provided by +:mod:`cpp-netlib`. The section was written to assume that an appropriately +constructed request instance is either of the following: + +.. code-block:: c++ + + boost::network::http::basic_request< + boost::network::http::tags::http_default_8bit_udp_resolve + > request; + + // or + + boost::network::http::basic_request< + boost::network::http::tags::http_server + > request; + +The section also assumes that there following using namespace declaration is in +effect: + +.. code-block:: c++ + + using namespace boost::network; + +Directives are meant to be used in the following manner: + +.. code-block:: c++ + + request << directive(...); + +.. warning:: + + There are two versions of directives, those that are applicable to + messages that support narrow strings (``std::string``) and those that are + applicable to messages that support wide strings (``std::wstring``). The + :mod:`cpp-netlib` implementation still does not convert wide strings into + UTF-8 encoded narrow strings. This will be implemented in subsequent + library releases. + + For now all the implemented directives are listed, even if some of them still + do not implement things correctly. + +*unspecified* ``source(std::string const & source_)`` + Create a source directive with a ``std::string`` as a parameter, to be set + as the source of the request. +*unspecified* ``source(std::wstring const & source_)`` + Create a source directive with a ``std::wstring`` as a parameter, to be set + as the source of the request. +*unspecified* ``destination(std::string const & source_)`` + Create a destination directive with a ``std::string`` as a parameter, to be + set as the destination of the request. +*unspecified* ``destination(std::wstring const & source_)`` + Create a destination directive with a ``std::wstring`` as a parameter, to be + set as the destination of the request. +*unspecified* ``header(std::string const & name, std::string const & value)`` + Create a header directive that will add the given name and value pair to the + headers already associated with the request. In this case the name and + values are both ``std::string``. +*unspecified* ``header(std::wstring const & name, std::wstring const & value)`` + Create a header directive that will add the given name and value pair to the + headers already associated with the request. In this case the name and + values are both ``std::wstring``. +*unspecified* ``remove_header(std::string const & name)`` + Create a remove_header directive that will remove all the occurences of the + given name from the headers already associated with the request. In this + case the name of the header is of type ``std::string``. +*unspecified* ``remove_header(std::wstring const & name)`` + Create a remove_header directive that will remove all the occurences of the + given name from the headers already associated with the request. In this + case the name of the header is of type ``std::wstring``. +*unspecified* ``body(std::string const & body_)`` + Create a body directive that will set the request's body to the given + parameter. In this case the type of the body is an ``std::string``. +*unspecified* ``body(std::wstring const & body_)`` + Create a body directive that will set the request's body to the given + parameter. In this case the type of the body is an ``std::wstring``. + +Modifiers +--------- + +This section details the provided modifiers that are provided by +:mod:`cpp-netlib`. + +``template inline void source(basic_request & request, typename string::type const & source_)`` + Modifies the source of the given ``request``. The type of ``source_`` is + dependent on the ``Tag`` specialization of ``basic_request``. +``template inline void destination(basic_request & request, typename string::type const & destination_)`` + Modifies the destination of the given ``request``. The type of ``destination_`` is + dependent on the ``Tag`` specialization of ``basic_request``. +``template inline void add_header(basic_request & request, typename string::type const & name, typename string::type const & value)`` + Adds a header to the given ``request``. The type of the ``name`` and + ``value`` parameters are dependent on the ``Tag`` specialization of + ``basic_request``. +``template inline void remove_header(basic_request & request, typename string::type const & name)`` + Removes a header from the given ``request``. The type of the ``name`` + parameter is dependent on the ``Tag`` specialization of ``basic_request``. +``template inline void clear_headers(basic_request & request)`` + Removes all headers from the given ``request``. +``template inline void body(basic_request & request, typename string::type const & body_)`` + Modifies the body of the given ``request``. The type of ``body_`` is + dependent on the ``Tag`` specialization of ``basic_request``. + +Wrappers +-------- + +This section details the provided request wrappers that come with +:mod:`cpp-netlib`. Wrappers are used to convert a message into a different type, +usually providing accessor operations to retrieve just part of the message. This +section assumes that the following using namespace directives are in +effect: + +.. code-block:: c++ + + using namespace boost::network; + using namespace boost::network::http; + +``template `` *unspecified* ``source(basic_request const & request)`` + Returns a wrapper convertible to ``typename string::type`` that + provides the source of a given request. +``template `` *unspecified* ``destination(basic_request const & request)`` + Returns a wrapper convertible to ``typename string::type`` that + provides the destination of a given request. +``template `` *unspecified* ``headers(basic_request const & request)`` + Returns a wrapper convertible to ``typename headers_range + >::type`` or ``typename basic_request::headers_container_type`` that + provides the headers of a given request. +``template `` *unspecified* ``body(basic_request const & request)`` + Returns a wrapper convertible to ``typename string::type`` that + provides the body of a given request. + diff --git a/libs/network/doc/html/_sources/reference/http_response.rst.txt b/libs/network/doc/html/_sources/reference/http_response.rst.txt new file mode 100644 index 000000000..d76bcba28 --- /dev/null +++ b/libs/network/doc/html/_sources/reference/http_response.rst.txt @@ -0,0 +1,313 @@ + +HTTP Response +============= + +This part of the documentation talks about the publicly accessible API of the +HTTP Response objects. This section details the `Response Concept`_ requirements, +the implemented and required Directives_, Modifiers_, and Wrappers_ that work +with the HTTP Response objects. + +.. note:: The HTTP server response object is a POD type, which doesn't support + any of the following details. There are only a few fields available in the + HTTP server response type, which can be seen in + ``boost/network/protocol/http/impl/response.ipp``. + +Response Concept +---------------- + +A type models the Response Concept if it models the `Message Concept`_ and also +supports the following constructs. + +**Legend** + +:R: The response type. +:r: An instance of R. +:S: The string type. +:s,e,g: Instances of S. +:P: The port type. +:p: An instance of P. +:V: The version type. +:v: An instance of v. +:T: The status type. +:t: An instance of T. +:M: The status message type. +:m: An instance of M. +:U: An unsigned 16-bit int. +:u: An instance of U. + +.. note:: In the table below, the namespace ``traits`` is an alias for + ``boost::network::http::traits``. + ++-------------------------------------+----------+-----------------------------+ +| Construct | Result | Description | ++=====================================+==========+=============================+ +| ``R::string_type`` | ``S`` | The nested ``string_type`` | +| | | type. | ++-------------------------------------+----------+-----------------------------+ +| ``traits::version::type`` | ``V`` | The version type associated | +| | | with R. | ++-------------------------------------+----------+-----------------------------+ +| ``traits::status::type`` | ``T`` | The status type associated | +| | | with R. | ++-------------------------------------+----------+-----------------------------+ +| ``traits::status_message::type`` | ``M`` | The status message type | +| | | associated with R. | ++-------------------------------------+----------+-----------------------------+ +| ``r << version(v)`` | ``R&`` | Sets the version of ``r``. | ++-------------------------------------+----------+-----------------------------+ +| ``r << status(t)`` | ``R&`` | Sets the status of ``r``. | ++-------------------------------------+----------+-----------------------------+ +| ``r << status_message(m)`` | ``R&`` | Sets the status message of | +| | | ``r``. | ++-------------------------------------+----------+-----------------------------+ +| ``version(r, v)`` | ``void`` | Sets the version of ``r``. | ++-------------------------------------+----------+-----------------------------+ +| ``status(r, t)`` | ``void`` | Sets the status of ``r``. | ++-------------------------------------+----------+-----------------------------+ +| ``status_message(r, m)`` | ``void`` | Sets the status message of | +| | | ``r``. | ++-------------------------------------+----------+-----------------------------+ +| ``S e = version(r)`` | **NA** | Get the version of ``r``. | ++-------------------------------------+----------+-----------------------------+ +| ``U u = status(r)`` | **NA** | Get the status of ``r``. | ++-------------------------------------+----------+-----------------------------+ +| ``S g = status_message(r)`` | **NA** | Get the status message of | +| | | ``r``. | ++-------------------------------------+----------+-----------------------------+ + +.. _Message Concept: ../in_depth/message.html#message-concept + +Directives +---------- + +This section details the provided directives that are provided by +:mod:`cpp-netlib`. The section was written to assume that an appropriately +constructed response instance is either of the following: + +.. code-block:: c++ + + boost::network::http::basic_response< + boost::network::http::tags::http_default_8bit_udp_resolve + > response; + + // or + + boost::network::http::basic_response< + boost::network::http::tags::http_server + > response; + +The section also assumes that there following using namespace declaration is in +effect: + +.. code-block:: c++ + + using namespace boost::network; + +Directives are meant to be used in the following manner: + +.. code-block:: c++ + + response << directive(...); + +.. warning:: There are four versions of directives, those that are applicable + to messages that support narrow strings (``std::string``), those that are + applicable to messages that support wide strings (``std::wstring``), those + that are applicable to messages that support future-wrapped narrow and wide + strings (``boost::shared_future`` and + ``boost::shared_future``). + + The :mod:`cpp-netlib` implementation still does not convert wide strings into + UTF-8 encoded narrow strings. This will be implemented in subsequent + library releases. + + For now all the implemented directives are listed, even if some of them still + do not implement things correctly. + +*unspecified* ``source(std::string const & source_)`` + Create a source directive with a ``std::string`` as a parameter, to be set + as the source of the response. +*unspecified* ``source(std::wstring const & source_)`` + Create a source directive with a ``std::wstring`` as a parameter, to be set + as the source of the response. +*unspecified* ``source(boost::shared_future const & source_)`` + Create a source directive with a ``boost::shared_future`` as a parameter, to be set + as the source of the response. +*unspecified* ``source(boost::shared_future const & source_)`` + Create a source directive with a ``boost::shared_future`` as a parameter, to be set + as the source of the response. +*unspecified* ``destination(std::string const & source_)`` + Create a destination directive with a ``std::string`` as a parameter, to be + set as the destination of the response. +*unspecified* ``destination(std::wstring const & source_)`` + Create a destination directive with a ``std::wstring`` as a parameter, to be + set as the destination of the response. +*unspecified* ``destination(boost::shared_future const & destination_)`` + Create a destination directive with a ``boost::shared_future`` as a parameter, to be set + as the destination of the response. +*unspecified* ``destination(boost::shared_future const & destination_)`` + Create a destination directive with a ``boost::shared_future`` as a parameter, to be set + as the destination of the response. +*unspecified* ``header(std::string const & name, std::string const & value)`` + Create a header directive that will add the given name and value pair to the + headers already associated with the response. In this case the name and + values are both ``std::string``. +*unspecified* ``header(std::wstring const & name, std::wstring const & value)`` + Create a header directive that will add the given name and value pair to the + headers already associated with the response. In this case the name and + values are both ``std::wstring``. +*unspecified* ``remove_header(std::string const & name)`` + Create a remove_header directive that will remove all the occurences of the + given name from the headers already associated with the response. In this + case the name of the header is of type ``std::string``. +*unspecified* ``remove_header(std::wstring const & name)`` + Create a remove_header directive that will remove all the occurences of the + given name from the headers already associated with the response. In this + case the name of the header is of type ``std::wstring``. +*unspecified* ``body(std::string const & body_)`` + Create a body directive that will set the response's body to the given + parameter. In this case the type of the body is an ``std::string``. +*unspecified* ``body(std::wstring const & body_)`` + Create a body directive that will set the response's body to the given + parameter. In this case the type of the body is an ``std::wstring``. +*unspecified* ``body(boost::shared_future const & body_)`` + Create a body directive that will set the response's body to the given + parameter. In this case the type of the body is an ``boost::shared_future``. +*unspecified* ``body(boost::shared_future const & body_)`` + Create a body directive that will set the response's body to the given + parameter. In this case the type of the body is an ``boost::shared_future``. +*unspecified* ``version(std::string const & version_)`` + Create a version directive that will set the response's version to the given + parameter. In this case the type of the version is an ``std::string``. + + Note that this version includes the full ``"HTTP/"`` string. +*unspecified* ``version(std::wstring const & version_)`` + Create a version directive that will set the response's version to the given + parameter. In this case the type of the version is an ``std::wstring``. + + Note that this version includes the full ``"HTTP/"`` string. +*unspecified* ``version(boost::shared_future const & version_)`` + Create a version directive that will set the response's version to the given + parameter. In this case the type of the version is an ``boost::shared_future``. + + Note that this version includes the full ``"HTTP/"`` string. +*unspecified* ``version(boost::shared_future const & version_)`` + Create a version directive that will set the response's version to the given + parameter. In this case the type of the version is an ``boost::shared_future``. + + Note that this version includes the full ``"HTTP/"`` string. +*unspecified* ``status_message(std::string const & status_message_)`` + Create a status_message directive that will set the response's status_message to the given + parameter. In this case the type of the status_message is an ``std::string``. + + Note that this status_message includes the full ``"HTTP/"`` string. +*unspecified* ``status_message(std::wstring const & status_message_)`` + Create a status_message directive that will set the response's status_message to the given + parameter. In this case the type of the status_message is an ``std::wstring``. + + Note that this status_message includes the full ``"HTTP/"`` string. +*unspecified* ``status_message(boost::shared_future const & status_message_)`` + Create a status_message directive that will set the response's status_message to the given + parameter. In this case the type of the status_message is an ``boost::shared_future``. + + Note that this status_message includes the full ``"HTTP/"`` string. +*unspecified* ``status_message(boost::shared_future const & status_message_)`` + Create a status_message directive that will set the response's status_message to the given + parameter. In this case the type of the status_message is an ``boost::shared_future``. + + Note that this status_message includes the full ``"HTTP/"`` string. +*unspecified* ``status(boost::uint16_t status_)`` + Create a status directive that will set the response's status to the given + parameter. In this case the type of ``status_`` is ``boost::uint16_t``. +*unspecified* ``status(boost::shared_future const & status_)`` + Create a status directive that will set the response's status to the given + parameter. In this case the type of ``status_`` is ``boost::shared_future``. + +Modifiers +--------- + +This section details the provided modifiers that are provided by +:mod:`cpp-netlib`. + +``template inline void source(basic_response & response, typename string::type const & source_)`` + Modifies the source of the given ``response``. The type of ``source_`` is + dependent on the ``Tag`` specialization of ``basic_response``. +``template inline void source(basic_response & response, boost::shared_future::type> const & source_)`` + Modifies the source of the given ``response``. The type of ``source_`` is + dependent on the ``Tag`` specialization of ``basic_response``. +``template inline void destination(basic_response & response, typename string::type const & destination_)`` + Modifies the destination of the given ``response``. The type of ``destination_`` is + dependent on the ``Tag`` specialization of ``basic_response``. +``template inline void destination(basic_response & response, boost::shared_future::type> const & destination_)`` + Modifies the destination of the given ``response``. The type of ``destination_`` is + dependent on the ``Tag`` specialization of ``basic_response``. +``template inline void add_header(basic_response & response, typename string::type const & name, typename string::type const & value)`` + Adds a header to the given ``response``. The type of the ``name`` and + ``value`` parameters are dependent on the ``Tag`` specialization of + ``basic_response``. +``template inline void remove_header(basic_response & response, typename string::type const & name)`` + Removes a header from the given ``response``. The type of the ``name`` + parameter is dependent on the ``Tag`` specialization of ``basic_response``. +``template inline void headers(basic_response & response, typename headers_container >::type const & headers_)`` + Sets the whole headers contained in ``response`` as the given parameter + ``headers_``. +``template inline void headers(basic_response & response, boost::shared_future >::type> const & headers_)`` + Sets the whole headers contained in ``response`` as the given parameter + ``headers_``. +``template inline void clear_headers(basic_response & response)`` + Removes all headers from the given ``response``. +``template inline void body(basic_response & response, typename string::type const & body_)`` + Modifies the body of the given ``response``. The type of ``body_`` is + dependent on the ``Tag`` specialization of ``basic_response``. +``template inline void body(basic_response & response, boost::shared_future::type> const & body_)`` + Modifies the body of the given ``response``. The type of ``body_`` is + dependent on the ``Tag`` specialization of ``basic_response``. +``template inline void version(basic_response & response, typename traits::version >::type const & version_)`` + Modifies the version of the given ``response``. The type of ``version_`` is + dependent on the ``Tag`` specialization of ``basic_response``. +``template inline void status(basic_response & response, typename traits::status >::type const & status_)`` + Modifies the status of the given ``response``. The type of ``status_`` is + dependent on the ``Tag`` specialization of ``basic_response``. +``template inline void status_message(basic_response & response, typename traits::status_message >::type const & status_message_)`` + Modifies the status message of the given ``response``. The type of ``status_message_`` is + dependent on the ``Tag`` specialization of ``basic_response``. + +Wrappers +-------- + +This section details the provided response wrappers that come with +:mod:`cpp-netlib`. Wrappers are used to convert a message into a different type, +usually providing accessor operations to retrieve just part of the message. This +section assumes that the following using namespace directives are in +effect: + +.. code-block:: c++ + + using namespace boost::network; + using namespace boost::network::http; + +``template `` *unspecified* ``source(basic_response const & response)`` + Returns a wrapper convertible to ``typename string::type`` that + provides the source of a given response. +``template `` *unspecified* ``destination(basic_response const & response)`` + Returns a wrapper convertible to ``typename string::type`` that + provides the destination of a given response. +``template `` *unspecified* ``headers(basic_response const & response)`` + Returns a wrapper convertible to ``typename headers_range + >::type`` or ``typename basic_response::headers_container_type`` that + provides the headers of a given response. +``template `` *unspecified* ``body(basic_response const & response)`` + Returns a wrapper convertible to ``typename string::type`` that + provides the body of a given response. +``template `` *unspecified* ``version(basic_response const & response)`` + Returns a wrapper convertible to ``typename string::type`` that + provides the version of the given response. +``template `` *unspecified* ``status(basic_response const & response)`` + Returns a wrapper convertible to ``typename boost::uint16_t`` that + provides the status of the given response. +``template `` *unspecified* ``status_message(basic_response const & response)`` + Returns a wrapper convertible to ``typename string::type`` that + provides the status message of the given response. +``template `` *unspecified* ``ready(basic_response const & response)`` + Returns a wrapper convertible to ``bool``. The return value is equivalent + to ``true`` if all the response parts have been fetched and it is guaranteed + that a successive call to any wrapper will not block. diff --git a/libs/network/doc/html/_sources/reference/http_server.rst.txt b/libs/network/doc/html/_sources/reference/http_server.rst.txt new file mode 100644 index 000000000..c0022bdda --- /dev/null +++ b/libs/network/doc/html/_sources/reference/http_server.rst.txt @@ -0,0 +1,180 @@ + +HTTP Server API +=============== + +General +------- + +:mod:`cpp-netlib` includes and implements and asynchronous HTTP server +implementation that you can use and embed in your own applications. The HTTP +Server implementation: + + * **Cannot be copied.** This means you may have to store instances of the HTTP + Server in dynamic memory if you intend to use them as function parameters or + pass them around in smart pointers of by reference. + * **Assume that requests made are independent of each other.** None of the + HTTP Server implementations support request pipelining (yet) so a single + connection only deals with a single request. + * **The Handler instance is invoked asynchronously**. This means the I/O + thread used to handle network-related events are free to handle only the + I/O related events. This enables the server to scale better as to the + number of concurrent connections it can handle. + * **The Handler is able to schedule asynchronous actions on the thread pool + associated with the server.** This allows handlers to perform multiple + asynchronous computations that later on perform writes to the connection. + * **The Handler is able to control the (asynchronous) writes to and reads + from the HTTP connection.** Because the connection is available to the + Handler, that means it can write out chunks of data at a time or stream + data through the connection continuously. + +The Handler concept for the HTTP Server is described by the following table: + +--------------- + +**Legend:** + +H + The Handler type. +h + An instance of H. +Req + A type that models the Request Concept. +ConnectionPtr + A type that models the Connection Pointer Concept. +req + An instance of Req. +conn + An instance of ConncetionPtr. + ++------------------+-------------+--------------------------------------------+ +| Construct | Return Type | Description | ++==================+=============+============================================+ +| ``h(req, conn)`` | ``void`` | Handle the request; conn is a shared | +| | | pointer which exposes functions for | +| | | writing to and reading from the connection.| ++------------------+-------------+--------------------------------------------+ + +--------------- + +The HTTP Server is meant to allow for better scalability in terms of the number +of concurrent connections and for performing asynchronous actions within the +handlers. The HTTP Server implementation is available from a single +user-facing template named ``server``. This template takes in a single template +parameter which is the type of the Handler to be called once a request has been +parsed from a connection. + +An instance of Handler is taken as a reference to the constructor of the server +instance. + +.. warning:: The HTTP Server implementation does not perform any + synchronization on the calls to the Handler invocation. This means if your + handler contains or maintains internal state, you are responsible for + implementing your own synchronization on accesses to the internal state of + the Handler. + +The general pattern for using the ``server`` template is shown below: + +.. code-block:: c++ + + struct handler; + typedef boost::network::http::server http_server; + + struct handler { + void operator()( + http_server::request const & req, + http_server::connection_ptr connection + ) { + // handle the request here, and use the connection to + // either read more data or write data out to the client + } + }; + +API Documentation +----------------- + +The following sections assume that the following file has been included: + +.. code-block:: c++ + + #include + #include + +And that the following typedef's have been put in place: + +.. code-block:: c++ + + struct handler_type; + typedef boost::network::http::server http_server; + + struct handler_type { + void operator()(http_server::request const & request, + http_server::connection_ptr connection) { + // do something here + } + }; + +Constructor +~~~~~~~~~~~ + +``explicit http_server(options)`` + Construct an HTTP server instance passing in a ``server_options`` instance. + +Server Options +~~~~~~~~~~~~~~ + +.. doxygenstruct:: boost::network::http::server_options + :project: cppnetlib + :members: + +Public Members +~~~~~~~~~~~~~~ + +.. doxygenstruct:: boost::network::http::server + :project: cppnetlib + :members: + :undoc-members: + +Connection Object +~~~~~~~~~~~~~~~~~ + +.. doxygenstruct:: boost::network::http::async_connection + :project: cppnetlib + :members: + +Adding SSL support to the HTTP Server +------------------------------------- + +In order to setup SSL support for an Asynchronous Server, it is best to start from +a regular Asynchronous Server (see above). Once this server is setup, SSL can be +enabled by adding a Boost.Asio.Ssl.Context_ to the options. The settings that can be +used are defined in the link. + +.. code-block:: c++ + + // Initialize SSL context + std::shared_ptr ctx = + std::make_shared(asio::ssl::context::sslv23); + ctx->set_options( + asio::ssl::context::default_workarounds + | asio::ssl::context::no_sslv3 + | asio::ssl::context::single_dh_use); + + // Set keys + ctx->set_password_callback(password_callback); + ctx->use_certificate_chain_file("server.pem"); + ctx->use_private_key_file("server.pem", asio::ssl::context::pem); + ctx->use_tmp_dh_file("dh512.pem"); + + handler_type handler; + http_server::options options(handler); + options.thread_pool(std::make_shared(2)); + http_server server(options.address("127.0.0.1").port("8442").context(ctx)); + + std::string password_callback(std::size_t max_length, asio::ssl::context_base::password_purpose purpose) { + return std::string("test"); + } + +.. _Boost.Range: http://www.boost.org/libs/range +.. _Boost.Function: http://www.boost.org/libs/function +.. _Boost.Asio.SSL.Context: http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/reference/ssl__context.html diff --git a/libs/network/doc/html/_sources/references.rst.txt b/libs/network/doc/html/_sources/references.rst.txt new file mode 100644 index 000000000..7f2c97d4f --- /dev/null +++ b/libs/network/doc/html/_sources/references.rst.txt @@ -0,0 +1,25 @@ +References +========== + +About :mod:`cpp-netlib` +~~~~~~~~~~~~~~~~~~~~~~~ + +* `BoostCon 2010 Slides`_ +* `BoostCon 2010 Paper`_ + +Other sources +~~~~~~~~~~~~~ + +* `Template Metaprogramming`_: The best guide to C++ template metaprogramming. +* `HTTP 1.0`_: The HTTP 1.0 specification. +* `HTTP 1.1 (RFC 2616)`_: The HTTP 1.1 specification. +* `URI Generic Syntax (RFC 3986)`_: Generic URI syntax specification. +* `Format for Literal IPv6 Addresses in URLs (RFC 2732)`_: Literal IPv6 Addresses in URLs. + +.. _`BoostCon 2010 Slides`: http://www.filetolink.com/b0e89d06 +.. _`BoostCon 2010 Paper`: http://github.com/downloads/mikhailberis/cpp-netlib-boostcon-paper/cpp-netlib.pdf +.. _`Template Metaprogramming`: http://www.boostpro.com/mplbook/ +.. _`HTTP 1.0`: http://www.w3.org/Protocols/HTTP/1.0/spec.html +.. _`HTTP 1.1 (RFC 2616)`: http://www.w3.org/Protocols/rfc2616/rfc2616.html +.. _`URI Generic Syntax (RFC 3986)`: http://www.ietf.org/rfc/rfc3986.txt +.. _`Format for Literal IPv6 Addresses in URLs (RFC 2732)`: http://www.ietf.org/rfc/rfc2732.txt diff --git a/libs/network/doc/html/_sources/whats_new.rst.txt b/libs/network/doc/html/_sources/whats_new.rst.txt new file mode 100644 index 000000000..6bf417cfc --- /dev/null +++ b/libs/network/doc/html/_sources/whats_new.rst.txt @@ -0,0 +1,263 @@ +.. _whats_new: + +************ + What's New +************ + +:mod:`cpp-netlib` 0.13 +---------------------- + +* Lots of little fixes. +* Support for per-request SNI hostnames +* Fixes to chunk and content-length encoding. +* Changed default connection buffer size to 4K. +* Support for IPv6 and HTTPS. +* Example of large upload handling with the HTTP server. +* Depend on Boost.Asio again instead of standalone Asio. +* Added Visual Studio 2015 support. +* Update minimum Boost to 1.58. Always use shared libs from Boost. + +:mod:`cpp-netlib` 0.12 +---------------------- + +* Added a code of conduct. +* Add TLS SNI hostname support in the HTTP Client options. +* Changes based on Coverity reports. +* Replace std::bind with lambdas. +* Use std::shared_ptr instead of boost::shared_ptr. +* Use standalone Asio instead of Boost.Asio. +* No Boost library (shared or static) dependencies. +* Use doxygen for documentation, integrated with Breathe to Sphinx. +* Require C++11 for builds, removes support for non-C++11 compilers. +* Update documentation for hello_world_server +* Use googletest for tests +* Fix XCode-generated debug binaries caused by URI parser complexity +* Remove synchronous client implementation. +* Remove support for connection keepalive (only supported in synchronous client). +* Disable SSLv3 by default. +* Use sanitisers in continuous integration (address and thread sanitiser). +* Update minimum Boost to 1.57. Always use shared libs from Boost. + +:mod:`cpp-netlib` 0.11 +---------------------- + +v0.11.2 +~~~~~~~ +* Support a source_port setting for connections made by the client per-request. +* Allow using cpp-netlib without OpenSSL. +* Fix build breakage for Visual Studio 2015. +* Add more options for HTTP client use of SSL/TLS options/ciphers. +* Made client_get_timeout_test less flaky. +* Fixes to URI encoding issues with multibyte strings. +* Make cpp-netlib not crash on unstable networks. +* Allow parsing empty query parameters (`#499`_). +* CMake build changes to simplify dependencies on cppnetlib-client-connections. +* Handle EOF correctly (`#496`_). +* Fix fileserver example to chunk data correctly. +* Copy hostname to avoid dangling reference to a temporary request object. (`#482`_) +* Catch exceptions in parse_headers to avoid propagating issues in parsing upwards. +* Fix some GCC warnings on signed/unsigned comparison. +* Support environment variable-based peer verification (via OpenSSL). +* Support IPv6 connections. +* Support certificate-based verification, and option to always verify hosts. + +.. _`#499`: https://github.com/cpp-netlib/cpp-netlib/issues/499 +.. _`#496`: https://github.com/cpp-netlib/cpp-netlib/issues/496 +.. _`#482`: https://github.com/cpp-netlib/cpp-netlib/issues/482 + + +v0.11.1 +~~~~~~~ +* Add support for request timeouts. +* Build configuration fixes. +* Support for Travis CI in-project config. +* Make the response parser more flexible to support older/ad-hoc servers that don't have standard format responses. +* Fix some instability in the client destructor. +* MSVC 2010 specific fixes. + +v0.11.0 +~~~~~~~ +* Fix thread leak in DNS resolution failure (`#245`_) +* Remove unsupported `client_fwd.hpp` header (`#277`_) +* Remove support for header-only usage (`#129`_) -- this means that the BOOST_NETWORK_NO_LIB option is no longer actually supported. +* Deprecate Synchronous Client implementations (`#279`_) +* Support streaming body chunks for PUT/POST client requests (`#27`_) +* Fix non-case-sensitive header parsing for some client tags (`#313`_) +* Remove unsupported Jamfiles from the whole project (`#316`_) +* Add ``make install`` for Linux and OS X (`#285`_) +* Fix incorrect Body processing (`#69`_) +* Support chunked transfer encoding from HTTP responses (`#86`_) +* Make OS X Clang builds use C++11 and libc++. +* Update Boost requirement to 1.54.0. +* Experimental Base64 encoding/decoding library (`#287`_) +* *Known test failure:* OS X Xcode Clang 5.0 + Boost 1.54.0 + libc++ don't play + well with Boost.Serialization issues, mitigate test breakage but + ``cpp-netlib-utils_base64_test`` still fails in this platform. (`#287`_) +* Provide a client option to always validate peers for HTTPS requests made by + the client. (`#349`_) +* Back-port fix for `#163`_ for improved URI parsing. +* Added support for client-side certificates and private keys (`#361`_). + +.. _`#129`: https://github.com/cpp-netlib/cpp-netlib/issues/129 +.. _`#163`: https://github.com/cpp-netlib/cpp-netlib/issues/163 +.. _`#245`: https://github.com/cpp-netlib/cpp-netlib/issues/245 +.. _`#277`: https://github.com/cpp-netlib/cpp-netlib/issues/277 +.. _`#279`: https://github.com/cpp-netlib/cpp-netlib/issues/279 +.. _`#27`: https://github.com/cpp-netlib/cpp-netlib/issues/27 +.. _`#285`: https://github.com/cpp-netlib/cpp-netlib/issues/285 +.. _`#287`: https://github.com/cpp-netlib/cpp-netlib/issues/287 +.. _`#313`: https://github.com/cpp-netlib/cpp-netlib/issues/313 +.. _`#316`: https://github.com/cpp-netlib/cpp-netlib/issues/316 +.. _`#349`: https://github.com/cpp-netlib/cpp-netlib/issues/349 +.. _`#69`: https://github.com/cpp-netlib/cpp-netlib/issues/69 +.. _`#86`: https://github.com/cpp-netlib/cpp-netlib/issues/86 +.. _`#361`: https://github.com/cpp-netlib/cpp-netlib/pull/361 + +:mod:`cpp-netlib` 0.10 +---------------------- + +v0.10.1 +~~~~~~~ +* Documentation updates (`#182`_, `#265`_, `#194`_, `#233`_, `#255`_) +* Fix issue with async server inadvertently stopping from listening when + accepting a connection fails. (`#172`_) +* Allow overriding and ultimately removing defaulted headers from HTTP + requests. (`#263`_) +* Add `-Wall` to the base rule for GCC builds. (`#264`_) +* Make the server implementation throw on startup errors. (`#166`_) + +.. _`#182`: https://github.com/cpp-netlib/cpp-netlib/issues/182 +.. _`#265`: https://github.com/cpp-netlib/cpp-netlib/issues/265 +.. _`#194`: https://github.com/cpp-netlib/cpp-netlib/issues/194 +.. _`#172`: https://github.com/cpp-netlib/cpp-netlib/issues/172 +.. _`#263`: https://github.com/cpp-netlib/cpp-netlib/issues/263 +.. _`#233`: https://github.com/cpp-netlib/cpp-netlib/issues/233 +.. _`#264`: https://github.com/cpp-netlib/cpp-netlib/issues/264 +.. _`#255`: https://github.com/cpp-netlib/cpp-netlib/issues/255 +.. _`#166`: https://github.com/cpp-netlib/cpp-netlib/issues/166 + +v0.10.0 +~~~~~~~ +* Added support for more HTTP status codes (206, 408, 412, 416, 507). +* Refactored the parser for chunked encoding. +* Fixed parsing chunked encoding if the response body has ``CLRFCLRF``. +* Added librt dependency on Linux. +* Check the callback in the asynchronous client before calling it. +* Fixed issues `#110`_, `#168`_, `#213`_. + +.. _`#110`: https://github.com/cpp-netlib/cpp-netlib/issues/110 +.. _`#168`: https://github.com/cpp-netlib/cpp-netlib/issues/168 +.. _`#213`: https://github.com/cpp-netlib/cpp-netlib/issues/213 + +:mod:`cpp-netlib` 0.9 +--------------------- + +v0.9.5 +~~~~~~ +* Removed dependency on Boost.Parameter from HTTP client and server. +* Fixed for Clang error on Twitter example. +* Added source port to the request (HTTP server). +* Updated CMake config for MSVC 2010/2012. +* Now support chunked content encoding in client response parsing. +* Fixed bug with client not invoking callback when a request fails. + +v0.9.4 +~~~~~~ +* Lots of URI fixes. +* Fixed async_server's request handler so it doesn't make copies of the supplied handler. +* Fix for issue `#73`_ regarding SSL connections ending in short read errors. +* Final C++03-only release. + +.. _`#73`: https://github.com/cpp-netlib/cpp-netlib/issues/73 + +v0.9.3 +~~~~~~ +* URI, HTTP client and HTTP server are now built as static libraries (``libcppnetlib-uri.a``, ``libcppnetlib-client-connections.a`` and ``libcppnetlib-server-parsers.a`` on Linux and ``cppnetlib-uri.lib``, ``cppnetlib-client-connections.lib`` and ``cppnetlib-server-parsers.lib`` on Windows). +* Updated URI parser. +* A new URI builder. +* URI support for IPv6 RFC 2732. +* Fixed issues `#67`_, `#72`_, `#78`_, `#79`_, `#80`_, `#81`_, `#82`_, `#83`_. +* New examples for the HTTP client, including an Atom feed, an RSS feed and a + very simple client that uses the Twitter Search API. + +.. _`#67`: https://github.com/cpp-netlib/cpp-netlib/issues/67 +.. _`#72`: https://github.com/cpp-netlib/cpp-netlib/issues/72 +.. _`#78`: https://github.com/cpp-netlib/cpp-netlib/issues/78 +.. _`#79`: https://github.com/cpp-netlib/cpp-netlib/issues/79 +.. _`#80`: https://github.com/cpp-netlib/cpp-netlib/issues/80 +.. _`#81`: https://github.com/cpp-netlib/cpp-netlib/issues/81 +.. _`#82`: https://github.com/cpp-netlib/cpp-netlib/issues/82 +.. _`#83`: https://github.com/cpp-netlib/cpp-netlib/issues/83 + +v0.9.2 +~~~~~~ +* Critial bug fixes to v0.9.1. + +v0.9.1 +~~~~~~ +* Introduced macro ``BOOST_NETWORK_DEFAULT_TAG`` to allow for programmatically + defining the default flag to use throughout the compilation unit. +* Support for streaming body handlers when performing HTTP client operations. + See documentation for HTTP client interface for more information. +* Numerous bug fixes from v0.9.0. +* Google, Inc. contributions. + +v0.9.0 +~~~~~~ +* **IMPORTANT BREAKING CHANGE**: By default all compile-time heavy parser + implementations are now compiled to external static libraries. In order to use + :mod:`cpp-netlib` in header-only mode, users must define the preprocessor + macro ``BOOST_NETWORK_NO_LIB`` before including any :mod:`cpp-netlib` header. + This breaks code that relied on the version 0.8.x line where the library is + strictly header-only. +* Fix issue #41: Introduce a macro ``BOOST_NETWORK_HTTP_CLIENT_DEFAULT_TAG`` + which makes the default HTTP client use ``tags::http_async_8bit_udp_resolve`` + as the tag. +* Fix issue #40: Write the status line and headers in a single buffer write + instead of two writes. +* More consistent message API for client and server messages (request and + response objects). +* Refactoring of internal implementations to allow better separation of concerns + and more manageable coding/documentation. +* Client and server constructors that support Boost.Parameter named parameters. +* Client and server constructors now take in an optional reference to a Boost.Asio + ``io_service`` to use internally. +* Documentation updates to reflect new APIs. + +:mod:`cpp-netlib` 0.8 +--------------------- + +* Updates to URI unit tests and documentation. +* More documentation, covering the HTTP Client and HTTP Server APIs +* Asynchronous HTTP Server that now supports running request handlers on a + different thread pool. +* An initial thread pool implementation, using Boost.Asio underneath. +* Adding a ready(...) wrapper to check whether a response object returned by + the asynchronous client in 0.7 already has all the parts available. +* Some attempts at lowering compile time costs. + +:mod:`cpp-netlib` 0.7 +--------------------- + +* Radical documentation overhaul +* Asynchronous HTTP client +* Tag dispatch overhaul, using Boost.MPL +* HTTP Client Facade refactoring +* Bug fixes for HTTP 1.1 response parsing +* Minimized code repetition with some header macro's +* Configurable HTTPS support in the library with ``BOOST_NETWORK_ENABLE_HTTPS`` + + +:mod:`cpp-netlib` 0.6 +--------------------- + +* Many fixes for MSVC compiler + +:mod:`cpp-netlib` 0.5 +--------------------- + +* An embeddable HTTP 1.1 server +* An HTTP 1.1 client upgraded to support HTTPS +* An updated URI parser implementation +* An asynchronous HTTP 1.1 client +* An HTTP 1.1 client that supports streaming function handlers diff --git a/libs/network/doc/html/_static/basic.css b/libs/network/doc/html/_static/basic.css index c89fc7e92..dc88b5a2d 100644 --- a/libs/network/doc/html/_static/basic.css +++ b/libs/network/doc/html/_static/basic.css @@ -4,7 +4,7 @@ * * Sphinx stylesheet -- basic theme. * - * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS. + * :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */ @@ -52,6 +52,8 @@ div.sphinxsidebar { width: 230px; margin-left: -100%; font-size: 90%; + word-wrap: break-word; + overflow-wrap : break-word; } div.sphinxsidebar ul { @@ -83,10 +85,6 @@ div.sphinxsidebar #searchbox input[type="text"] { width: 170px; } -div.sphinxsidebar #searchbox input[type="submit"] { - width: 30px; -} - img { border: 0; max-width: 100%; @@ -124,6 +122,8 @@ ul.keywordmatches li.goodmatch a { table.contentstable { width: 90%; + margin-left: auto; + margin-right: auto; } table.contentstable p.biglink { @@ -151,9 +151,14 @@ table.indextable td { vertical-align: top; } -table.indextable dl, table.indextable dd { +table.indextable ul { margin-top: 0; margin-bottom: 0; + list-style-type: none; +} + +table.indextable > tbody > tr > td > ul { + padding-left: 0em; } table.indextable tr.pcap { @@ -185,8 +190,22 @@ div.genindex-jumpbox { padding: 0.4em; } +/* -- domain module index --------------------------------------------------- */ + +table.modindextable td { + padding: 2px; + border-collapse: collapse; +} + /* -- general body styles --------------------------------------------------- */ +div.body p, div.body dd, div.body li, div.body blockquote { + -moz-hyphens: auto; + -ms-hyphens: auto; + -webkit-hyphens: auto; + hyphens: auto; +} + a.headerlink { visibility: hidden; } @@ -212,10 +231,6 @@ div.body td { text-align: left; } -.field-list ul { - padding-left: 1em; -} - .first { margin-top: 0 !important; } @@ -332,10 +347,6 @@ table.docutils td, table.docutils th { border-bottom: 1px solid #aaa; } -table.field-list td, table.field-list th { - border: 0 !important; -} - table.footnote td, table.footnote th { border: 0 !important; } @@ -372,6 +383,20 @@ div.figure p.caption span.caption-number { div.figure p.caption span.caption-text { } +/* -- field list styles ----------------------------------------------------- */ + +table.field-list td, table.field-list th { + border: 0 !important; +} + +.field-list ul { + margin: 0; + padding-left: 1em; +} + +.field-list p { + margin: 0; +} /* -- other body styles ----------------------------------------------------- */ @@ -422,15 +447,6 @@ dl.glossary dt { font-size: 1.1em; } -.field-list ul { - margin: 0; - padding-left: 1em; -} - -.field-list p { - margin: 0; -} - .optional { font-size: 1.3em; } @@ -489,6 +505,13 @@ pre { overflow-y: hidden; /* fixes display issues on Chrome browsers */ } +span.pre { + -moz-hyphens: none; + -ms-hyphens: none; + -webkit-hyphens: none; + hyphens: none; +} + td.linenos pre { padding: 5px 0px; border: 0; @@ -580,6 +603,16 @@ span.eqno { float: right; } +span.eqno a.headerlink { + position: relative; + left: 0px; + z-index: 1; +} + +div.math:hover a.headerlink { + visibility: visible; +} + /* -- printout stylesheet --------------------------------------------------- */ @media print { diff --git a/libs/network/doc/html/_static/comment-bright.png b/libs/network/doc/html/_static/comment-bright.png index 551517b8c..15e27edb1 100644 Binary files a/libs/network/doc/html/_static/comment-bright.png and b/libs/network/doc/html/_static/comment-bright.png differ diff --git a/libs/network/doc/html/_static/comment-close.png b/libs/network/doc/html/_static/comment-close.png index 09b54be46..4d91bcf57 100644 Binary files a/libs/network/doc/html/_static/comment-close.png and b/libs/network/doc/html/_static/comment-close.png differ diff --git a/libs/network/doc/html/_static/comment.png b/libs/network/doc/html/_static/comment.png index 92feb52b8..dfbc0cbd5 100644 Binary files a/libs/network/doc/html/_static/comment.png and b/libs/network/doc/html/_static/comment.png differ diff --git a/libs/network/doc/html/_static/dialog-note.png b/libs/network/doc/html/_static/dialog-note.png index 708682114..5a6336d11 100644 Binary files a/libs/network/doc/html/_static/dialog-note.png and b/libs/network/doc/html/_static/dialog-note.png differ diff --git a/libs/network/doc/html/_static/dialog-seealso.png b/libs/network/doc/html/_static/dialog-seealso.png index a27a0fcba..97553a8b7 100644 Binary files a/libs/network/doc/html/_static/dialog-seealso.png and b/libs/network/doc/html/_static/dialog-seealso.png differ diff --git a/libs/network/doc/html/_static/dialog-todo.png b/libs/network/doc/html/_static/dialog-todo.png index 9caa91e8a..cfbc28088 100644 Binary files a/libs/network/doc/html/_static/dialog-todo.png and b/libs/network/doc/html/_static/dialog-todo.png differ diff --git a/libs/network/doc/html/_static/dialog-topic.png b/libs/network/doc/html/_static/dialog-topic.png index 2ac57475c..a75afeaaf 100644 Binary files a/libs/network/doc/html/_static/dialog-topic.png and b/libs/network/doc/html/_static/dialog-topic.png differ diff --git a/libs/network/doc/html/_static/dialog-warning.png b/libs/network/doc/html/_static/dialog-warning.png index 4f598b12b..8bb7d8d35 100644 Binary files a/libs/network/doc/html/_static/dialog-warning.png and b/libs/network/doc/html/_static/dialog-warning.png differ diff --git a/libs/network/doc/html/_static/doctools.js b/libs/network/doc/html/_static/doctools.js index 816349563..565497723 100644 --- a/libs/network/doc/html/_static/doctools.js +++ b/libs/network/doc/html/_static/doctools.js @@ -4,7 +4,7 @@ * * Sphinx JavaScript utilities for all documentation. * - * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS. + * :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */ diff --git a/libs/network/doc/html/_static/down-pressed.png b/libs/network/doc/html/_static/down-pressed.png index 7c30d004b..5756c8cad 100644 Binary files a/libs/network/doc/html/_static/down-pressed.png and b/libs/network/doc/html/_static/down-pressed.png differ diff --git a/libs/network/doc/html/_static/down.png b/libs/network/doc/html/_static/down.png index f48098a43..1b3bdad2c 100644 Binary files a/libs/network/doc/html/_static/down.png and b/libs/network/doc/html/_static/down.png differ diff --git a/libs/network/doc/html/_static/epub.css b/libs/network/doc/html/_static/epub.css index 6fdf47704..a0cffc066 100644 --- a/libs/network/doc/html/_static/epub.css +++ b/libs/network/doc/html/_static/epub.css @@ -4,7 +4,7 @@ * * Sphinx stylesheet -- default theme. * - * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS. + * :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */ diff --git a/libs/network/doc/html/_static/file.png b/libs/network/doc/html/_static/file.png index 254c60bfb..a858a410e 100644 Binary files a/libs/network/doc/html/_static/file.png and b/libs/network/doc/html/_static/file.png differ diff --git a/libs/network/doc/html/_static/headerbg.png b/libs/network/doc/html/_static/headerbg.png index 0596f2020..e1051af48 100644 Binary files a/libs/network/doc/html/_static/headerbg.png and b/libs/network/doc/html/_static/headerbg.png differ diff --git a/libs/network/doc/html/_static/jquery.js b/libs/network/doc/html/_static/jquery.js index ab28a2472..25a72c959 100644 --- a/libs/network/doc/html/_static/jquery.js +++ b/libs/network/doc/html/_static/jquery.js @@ -1,4 +1,10219 @@ -/*! jQuery v1.11.1 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */ -!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l="1.11.1",m=function(a,b){return new m.fn.init(a,b)},n=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,o=/^-ms-/,p=/-([\da-z])/gi,q=function(a,b){return b.toUpperCase()};m.fn=m.prototype={jquery:l,constructor:m,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=m.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return m.each(this,a,b)},map:function(a){return this.pushStack(m.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},m.extend=m.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||m.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(e=arguments[h]))for(d in e)a=g[d],c=e[d],g!==c&&(j&&c&&(m.isPlainObject(c)||(b=m.isArray(c)))?(b?(b=!1,f=a&&m.isArray(a)?a:[]):f=a&&m.isPlainObject(a)?a:{},g[d]=m.extend(j,f,c)):void 0!==c&&(g[d]=c));return g},m.extend({expando:"jQuery"+(l+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===m.type(a)},isArray:Array.isArray||function(a){return"array"===m.type(a)},isWindow:function(a){return null!=a&&a==a.window},isNumeric:function(a){return!m.isArray(a)&&a-parseFloat(a)>=0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},isPlainObject:function(a){var b;if(!a||"object"!==m.type(a)||a.nodeType||m.isWindow(a))return!1;try{if(a.constructor&&!j.call(a,"constructor")&&!j.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}if(k.ownLast)for(b in a)return j.call(a,b);for(b in a);return void 0===b||j.call(a,b)},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(b){b&&m.trim(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(o,"ms-").replace(p,q)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=r(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(n,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(r(Object(a))?m.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){var d;if(b){if(g)return g.call(b,a,c);for(d=b.length,c=c?0>c?Math.max(0,d+c):c:0;d>c;c++)if(c in b&&b[c]===a)return c}return-1},merge:function(a,b){var c=+b.length,d=0,e=a.length;while(c>d)a[e++]=b[d++];if(c!==c)while(void 0!==b[d])a[e++]=b[d++];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=r(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(f=a[b],b=a,a=f),m.isFunction(a)?(c=d.call(arguments,2),e=function(){return a.apply(b||this,c.concat(d.call(arguments)))},e.guid=a.guid=a.guid||m.guid++,e):void 0},now:function(){return+new Date},support:k}),m.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function r(a){var b=a.length,c=m.type(a);return"function"===c||m.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var s=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+-new Date,v=a.document,w=0,x=0,y=gb(),z=gb(),A=gb(),B=function(a,b){return a===b&&(l=!0),0},C="undefined",D=1<<31,E={}.hasOwnProperty,F=[],G=F.pop,H=F.push,I=F.push,J=F.slice,K=F.indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(this[b]===a)return b;return-1},L="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",M="[\\x20\\t\\r\\n\\f]",N="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",O=N.replace("w","w#"),P="\\["+M+"*("+N+")(?:"+M+"*([*^$|!~]?=)"+M+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+O+"))|)"+M+"*\\]",Q=":("+N+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+P+")*)|.*)\\)|)",R=new RegExp("^"+M+"+|((?:^|[^\\\\])(?:\\\\.)*)"+M+"+$","g"),S=new RegExp("^"+M+"*,"+M+"*"),T=new RegExp("^"+M+"*([>+~]|"+M+")"+M+"*"),U=new RegExp("="+M+"*([^\\]'\"]*?)"+M+"*\\]","g"),V=new RegExp(Q),W=new RegExp("^"+O+"$"),X={ID:new RegExp("^#("+N+")"),CLASS:new RegExp("^\\.("+N+")"),TAG:new RegExp("^("+N.replace("w","w*")+")"),ATTR:new RegExp("^"+P),PSEUDO:new RegExp("^"+Q),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+L+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ab=/[+~]/,bb=/'|\\/g,cb=new RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),db=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)};try{I.apply(F=J.call(v.childNodes),v.childNodes),F[v.childNodes.length].nodeType}catch(eb){I={apply:F.length?function(a,b){H.apply(a,J.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function fb(a,b,d,e){var f,h,j,k,l,o,r,s,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],!a||"string"!=typeof a)return d;if(1!==(k=b.nodeType)&&9!==k)return[];if(p&&!e){if(f=_.exec(a))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return I.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName&&b.getElementsByClassName)return I.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=9===k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(bb,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+qb(o[l]);w=ab.test(a)&&ob(b.parentNode)||b,x=o.join(",")}if(x)try{return I.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function gb(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function hb(a){return a[u]=!0,a}function ib(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function jb(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function kb(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||D)-(~a.sourceIndex||D);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function lb(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function mb(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function nb(a){return hb(function(b){return b=+b,hb(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function ob(a){return a&&typeof a.getElementsByTagName!==C&&a}c=fb.support={},f=fb.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=fb.setDocument=function(a){var b,e=a?a.ownerDocument||a:v,g=e.defaultView;return e!==n&&9===e.nodeType&&e.documentElement?(n=e,o=e.documentElement,p=!f(e),g&&g!==g.top&&(g.addEventListener?g.addEventListener("unload",function(){m()},!1):g.attachEvent&&g.attachEvent("onunload",function(){m()})),c.attributes=ib(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ib(function(a){return a.appendChild(e.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(e.getElementsByClassName)&&ib(function(a){return a.innerHTML="
",a.firstChild.className="i",2===a.getElementsByClassName("i").length}),c.getById=ib(function(a){return o.appendChild(a).id=u,!e.getElementsByName||!e.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if(typeof b.getElementById!==C&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){var c=typeof a.getAttributeNode!==C&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return typeof b.getElementsByTagName!==C?b.getElementsByTagName(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return typeof b.getElementsByClassName!==C&&p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(e.querySelectorAll))&&(ib(function(a){a.innerHTML="",a.querySelectorAll("[msallowclip^='']").length&&q.push("[*^$]="+M+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+M+"*(?:value|"+L+")"),a.querySelectorAll(":checked").length||q.push(":checked")}),ib(function(a){var b=e.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+M+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ib(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",Q)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===e||a.ownerDocument===v&&t(v,a)?-1:b===e||b.ownerDocument===v&&t(v,b)?1:k?K.call(k,a)-K.call(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,f=a.parentNode,g=b.parentNode,h=[a],i=[b];if(!f||!g)return a===e?-1:b===e?1:f?-1:g?1:k?K.call(k,a)-K.call(k,b):0;if(f===g)return kb(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?kb(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},e):n},fb.matches=function(a,b){return fb(a,null,null,b)},fb.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(U,"='$1']"),!(!c.matchesSelector||!p||r&&r.test(b)||q&&q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return fb(b,n,null,[a]).length>0},fb.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},fb.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&E.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},fb.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},fb.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=fb.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=fb.selectors={cacheLength:50,createPseudo:hb,match:X,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(cb,db),a[3]=(a[3]||a[4]||a[5]||"").replace(cb,db),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||fb.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&fb.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(cb,db).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+M+")"+a+"("+M+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||typeof a.getAttribute!==C&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=fb.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||fb.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?hb(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=K.call(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:hb(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?hb(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),!c.pop()}}),has:hb(function(a){return function(b){return fb(a,b).length>0}}),contains:hb(function(a){return function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:hb(function(a){return W.test(a||"")||fb.error("unsupported lang: "+a),a=a.replace(cb,db).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return Z.test(a.nodeName)},input:function(a){return Y.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:nb(function(){return[0]}),last:nb(function(a,b){return[b-1]}),eq:nb(function(a,b,c){return[0>c?c+b:c]}),even:nb(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:nb(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:nb(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:nb(function(a,b,c){for(var d=0>c?c+b:c;++db;b++)d+=a[b].value;return d}function rb(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function sb(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function tb(a,b,c){for(var d=0,e=b.length;e>d;d++)fb(a,b[d],c);return c}function ub(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function vb(a,b,c,d,e,f){return d&&!d[u]&&(d=vb(d)),e&&!e[u]&&(e=vb(e,f)),hb(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||tb(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:ub(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=ub(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?K.call(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=ub(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):I.apply(g,r)})}function wb(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=rb(function(a){return a===b},h,!0),l=rb(function(a){return K.call(b,a)>-1},h,!0),m=[function(a,c,d){return!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d))}];f>i;i++)if(c=d.relative[a[i].type])m=[rb(sb(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return vb(i>1&&sb(m),i>1&&qb(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&wb(a.slice(i,e)),f>e&&wb(a=a.slice(e)),f>e&&qb(a))}m.push(c)}return sb(m)}function xb(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=G.call(i));s=ub(s)}I.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&fb.uniqueSort(i)}return k&&(w=v,j=t),r};return c?hb(f):f}return h=fb.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=wb(b[c]),f[u]?d.push(f):e.push(f);f=A(a,xb(e,d)),f.selector=a}return f},i=fb.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(cb,db),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(cb,db),ab.test(j[0].type)&&ob(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&qb(j),!a)return I.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,ab.test(a)&&ob(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ib(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),ib(function(a){return a.innerHTML="","#"===a.firstChild.getAttribute("href")})||jb("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&ib(function(a){return a.innerHTML="",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||jb("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),ib(function(a){return null==a.getAttribute("disabled")})||jb(L,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),fb}(a);m.find=s,m.expr=s.selectors,m.expr[":"]=m.expr.pseudos,m.unique=s.uniqueSort,m.text=s.getText,m.isXMLDoc=s.isXML,m.contains=s.contains;var t=m.expr.match.needsContext,u=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,v=/^.[^:#\[\.,]*$/;function w(a,b,c){if(m.isFunction(b))return m.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return m.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(v.test(b))return m.filter(b,a,c);b=m.filter(b,a)}return m.grep(a,function(a){return m.inArray(a,b)>=0!==c})}m.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?m.find.matchesSelector(d,a)?[d]:[]:m.find.matches(a,m.grep(b,function(a){return 1===a.nodeType}))},m.fn.extend({find:function(a){var b,c=[],d=this,e=d.length;if("string"!=typeof a)return this.pushStack(m(a).filter(function(){for(b=0;e>b;b++)if(m.contains(d[b],this))return!0}));for(b=0;e>b;b++)m.find(a,d[b],c);return c=this.pushStack(e>1?m.unique(c):c),c.selector=this.selector?this.selector+" "+a:a,c},filter:function(a){return this.pushStack(w(this,a||[],!1))},not:function(a){return this.pushStack(w(this,a||[],!0))},is:function(a){return!!w(this,"string"==typeof a&&t.test(a)?m(a):a||[],!1).length}});var x,y=a.document,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=m.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a.charAt(0)&&">"===a.charAt(a.length-1)&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||x).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof m?b[0]:b,m.merge(this,m.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:y,!0)),u.test(c[1])&&m.isPlainObject(b))for(c in b)m.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}if(d=y.getElementById(c[2]),d&&d.parentNode){if(d.id!==c[2])return x.find(a);this.length=1,this[0]=d}return this.context=y,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):m.isFunction(a)?"undefined"!=typeof x.ready?x.ready(a):a(m):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),m.makeArray(a,this))};A.prototype=m.fn,x=m(y);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};m.extend({dir:function(a,b,c){var d=[],e=a[b];while(e&&9!==e.nodeType&&(void 0===c||1!==e.nodeType||!m(e).is(c)))1===e.nodeType&&d.push(e),e=e[b];return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),m.fn.extend({has:function(a){var b,c=m(a,this),d=c.length;return this.filter(function(){for(b=0;d>b;b++)if(m.contains(this,c[b]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=t.test(a)||"string"!=typeof a?m(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&m.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?m.unique(f):f)},index:function(a){return a?"string"==typeof a?m.inArray(this[0],m(a)):m.inArray(a.jquery?a[0]:a,this):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(m.unique(m.merge(this.get(),m(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){do a=a[b];while(a&&1!==a.nodeType);return a}m.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return m.dir(a,"parentNode")},parentsUntil:function(a,b,c){return m.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return m.dir(a,"nextSibling")},prevAll:function(a){return m.dir(a,"previousSibling")},nextUntil:function(a,b,c){return m.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return m.dir(a,"previousSibling",c)},siblings:function(a){return m.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return m.sibling(a.firstChild)},contents:function(a){return m.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:m.merge([],a.childNodes)}},function(a,b){m.fn[a]=function(c,d){var e=m.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=m.filter(d,e)),this.length>1&&(C[a]||(e=m.unique(e)),B.test(a)&&(e=e.reverse())),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return m.each(a.match(E)||[],function(a,c){b[c]=!0}),b}m.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):m.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(c=a.memory&&l,d=!0,f=g||0,g=0,e=h.length,b=!0;h&&e>f;f++)if(h[f].apply(l[0],l[1])===!1&&a.stopOnFalse){c=!1;break}b=!1,h&&(i?i.length&&j(i.shift()):c?h=[]:k.disable())},k={add:function(){if(h){var d=h.length;!function f(b){m.each(b,function(b,c){var d=m.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&f(c)})}(arguments),b?e=h.length:c&&(g=d,j(c))}return this},remove:function(){return h&&m.each(arguments,function(a,c){var d;while((d=m.inArray(c,h,d))>-1)h.splice(d,1),b&&(e>=d&&e--,f>=d&&f--)}),this},has:function(a){return a?m.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],e=0,this},disable:function(){return h=i=c=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,c||k.disable(),this},locked:function(){return!i},fireWith:function(a,c){return!h||d&&!i||(c=c||[],c=[a,c.slice?c.slice():c],b?i.push(c):j(c)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!d}};return k},m.extend({Deferred:function(a){var b=[["resolve","done",m.Callbacks("once memory"),"resolved"],["reject","fail",m.Callbacks("once memory"),"rejected"],["notify","progress",m.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return m.Deferred(function(c){m.each(b,function(b,f){var g=m.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&m.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?m.extend(a,d):d}},e={};return d.pipe=d.then,m.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&m.isFunction(a.promise)?e:0,g=1===f?a:m.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&m.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;m.fn.ready=function(a){return m.ready.promise().done(a),this},m.extend({isReady:!1,readyWait:1,holdReady:function(a){a?m.readyWait++:m.ready(!0)},ready:function(a){if(a===!0?!--m.readyWait:!m.isReady){if(!y.body)return setTimeout(m.ready);m.isReady=!0,a!==!0&&--m.readyWait>0||(H.resolveWith(y,[m]),m.fn.triggerHandler&&(m(y).triggerHandler("ready"),m(y).off("ready")))}}});function I(){y.addEventListener?(y.removeEventListener("DOMContentLoaded",J,!1),a.removeEventListener("load",J,!1)):(y.detachEvent("onreadystatechange",J),a.detachEvent("onload",J))}function J(){(y.addEventListener||"load"===event.type||"complete"===y.readyState)&&(I(),m.ready())}m.ready.promise=function(b){if(!H)if(H=m.Deferred(),"complete"===y.readyState)setTimeout(m.ready);else if(y.addEventListener)y.addEventListener("DOMContentLoaded",J,!1),a.addEventListener("load",J,!1);else{y.attachEvent("onreadystatechange",J),a.attachEvent("onload",J);var c=!1;try{c=null==a.frameElement&&y.documentElement}catch(d){}c&&c.doScroll&&!function e(){if(!m.isReady){try{c.doScroll("left")}catch(a){return setTimeout(e,50)}I(),m.ready()}}()}return H.promise(b)};var K="undefined",L;for(L in m(k))break;k.ownLast="0"!==L,k.inlineBlockNeedsLayout=!1,m(function(){var a,b,c,d;c=y.getElementsByTagName("body")[0],c&&c.style&&(b=y.createElement("div"),d=y.createElement("div"),d.style.cssText="position:absolute;border:0;width:0;height:0;top:0;left:-9999px",c.appendChild(d).appendChild(b),typeof b.style.zoom!==K&&(b.style.cssText="display:inline;margin:0;border:0;padding:1px;width:1px;zoom:1",k.inlineBlockNeedsLayout=a=3===b.offsetWidth,a&&(c.style.zoom=1)),c.removeChild(d))}),function(){var a=y.createElement("div");if(null==k.deleteExpando){k.deleteExpando=!0;try{delete a.test}catch(b){k.deleteExpando=!1}}a=null}(),m.acceptData=function(a){var b=m.noData[(a.nodeName+" ").toLowerCase()],c=+a.nodeType||1;return 1!==c&&9!==c?!1:!b||b!==!0&&a.getAttribute("classid")===b};var M=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,N=/([A-Z])/g;function O(a,b,c){if(void 0===c&&1===a.nodeType){var d="data-"+b.replace(N,"-$1").toLowerCase();if(c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:M.test(c)?m.parseJSON(c):c}catch(e){}m.data(a,b,c)}else c=void 0}return c}function P(a){var b;for(b in a)if(("data"!==b||!m.isEmptyObject(a[b]))&&"toJSON"!==b)return!1;return!0}function Q(a,b,d,e){if(m.acceptData(a)){var f,g,h=m.expando,i=a.nodeType,j=i?m.cache:a,k=i?a[h]:a[h]&&h; -if(k&&j[k]&&(e||j[k].data)||void 0!==d||"string"!=typeof b)return k||(k=i?a[h]=c.pop()||m.guid++:h),j[k]||(j[k]=i?{}:{toJSON:m.noop}),("object"==typeof b||"function"==typeof b)&&(e?j[k]=m.extend(j[k],b):j[k].data=m.extend(j[k].data,b)),g=j[k],e||(g.data||(g.data={}),g=g.data),void 0!==d&&(g[m.camelCase(b)]=d),"string"==typeof b?(f=g[b],null==f&&(f=g[m.camelCase(b)])):f=g,f}}function R(a,b,c){if(m.acceptData(a)){var d,e,f=a.nodeType,g=f?m.cache:a,h=f?a[m.expando]:m.expando;if(g[h]){if(b&&(d=c?g[h]:g[h].data)){m.isArray(b)?b=b.concat(m.map(b,m.camelCase)):b in d?b=[b]:(b=m.camelCase(b),b=b in d?[b]:b.split(" ")),e=b.length;while(e--)delete d[b[e]];if(c?!P(d):!m.isEmptyObject(d))return}(c||(delete g[h].data,P(g[h])))&&(f?m.cleanData([a],!0):k.deleteExpando||g!=g.window?delete g[h]:g[h]=null)}}}m.extend({cache:{},noData:{"applet ":!0,"embed ":!0,"object ":"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"},hasData:function(a){return a=a.nodeType?m.cache[a[m.expando]]:a[m.expando],!!a&&!P(a)},data:function(a,b,c){return Q(a,b,c)},removeData:function(a,b){return R(a,b)},_data:function(a,b,c){return Q(a,b,c,!0)},_removeData:function(a,b){return R(a,b,!0)}}),m.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=m.data(f),1===f.nodeType&&!m._data(f,"parsedAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=m.camelCase(d.slice(5)),O(f,d,e[d])));m._data(f,"parsedAttrs",!0)}return e}return"object"==typeof a?this.each(function(){m.data(this,a)}):arguments.length>1?this.each(function(){m.data(this,a,b)}):f?O(f,a,m.data(f,a)):void 0},removeData:function(a){return this.each(function(){m.removeData(this,a)})}}),m.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=m._data(a,b),c&&(!d||m.isArray(c)?d=m._data(a,b,m.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=m.queue(a,b),d=c.length,e=c.shift(),f=m._queueHooks(a,b),g=function(){m.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return m._data(a,c)||m._data(a,c,{empty:m.Callbacks("once memory").add(function(){m._removeData(a,b+"queue"),m._removeData(a,c)})})}}),m.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.lengthh;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f},W=/^(?:checkbox|radio)$/i;!function(){var a=y.createElement("input"),b=y.createElement("div"),c=y.createDocumentFragment();if(b.innerHTML="
a",k.leadingWhitespace=3===b.firstChild.nodeType,k.tbody=!b.getElementsByTagName("tbody").length,k.htmlSerialize=!!b.getElementsByTagName("link").length,k.html5Clone="<:nav>"!==y.createElement("nav").cloneNode(!0).outerHTML,a.type="checkbox",a.checked=!0,c.appendChild(a),k.appendChecked=a.checked,b.innerHTML="",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue,c.appendChild(b),b.innerHTML="",k.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,k.noCloneEvent=!0,b.attachEvent&&(b.attachEvent("onclick",function(){k.noCloneEvent=!1}),b.cloneNode(!0).click()),null==k.deleteExpando){k.deleteExpando=!0;try{delete b.test}catch(d){k.deleteExpando=!1}}}(),function(){var b,c,d=y.createElement("div");for(b in{submit:!0,change:!0,focusin:!0})c="on"+b,(k[b+"Bubbles"]=c in a)||(d.setAttribute(c,"t"),k[b+"Bubbles"]=d.attributes[c].expando===!1);d=null}();var X=/^(?:input|select|textarea)$/i,Y=/^key/,Z=/^(?:mouse|pointer|contextmenu)|click/,$=/^(?:focusinfocus|focusoutblur)$/,_=/^([^.]*)(?:\.(.+)|)$/;function ab(){return!0}function bb(){return!1}function cb(){try{return y.activeElement}catch(a){}}m.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,n,o,p,q,r=m._data(a);if(r){c.handler&&(i=c,c=i.handler,e=i.selector),c.guid||(c.guid=m.guid++),(g=r.events)||(g=r.events={}),(k=r.handle)||(k=r.handle=function(a){return typeof m===K||a&&m.event.triggered===a.type?void 0:m.event.dispatch.apply(k.elem,arguments)},k.elem=a),b=(b||"").match(E)||[""],h=b.length;while(h--)f=_.exec(b[h])||[],o=q=f[1],p=(f[2]||"").split(".").sort(),o&&(j=m.event.special[o]||{},o=(e?j.delegateType:j.bindType)||o,j=m.event.special[o]||{},l=m.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&m.expr.match.needsContext.test(e),namespace:p.join(".")},i),(n=g[o])||(n=g[o]=[],n.delegateCount=0,j.setup&&j.setup.call(a,d,p,k)!==!1||(a.addEventListener?a.addEventListener(o,k,!1):a.attachEvent&&a.attachEvent("on"+o,k))),j.add&&(j.add.call(a,l),l.handler.guid||(l.handler.guid=c.guid)),e?n.splice(n.delegateCount++,0,l):n.push(l),m.event.global[o]=!0);a=null}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,n,o,p,q,r=m.hasData(a)&&m._data(a);if(r&&(k=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=_.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=m.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,n=k[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),i=f=n.length;while(f--)g=n[f],!e&&q!==g.origType||c&&c.guid!==g.guid||h&&!h.test(g.namespace)||d&&d!==g.selector&&("**"!==d||!g.selector)||(n.splice(f,1),g.selector&&n.delegateCount--,l.remove&&l.remove.call(a,g));i&&!n.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||m.removeEvent(a,o,r.handle),delete k[o])}else for(o in k)m.event.remove(a,o+b[j],c,d,!0);m.isEmptyObject(k)&&(delete r.handle,m._removeData(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,l,n,o=[d||y],p=j.call(b,"type")?b.type:b,q=j.call(b,"namespace")?b.namespace.split("."):[];if(h=l=d=d||y,3!==d.nodeType&&8!==d.nodeType&&!$.test(p+m.event.triggered)&&(p.indexOf(".")>=0&&(q=p.split("."),p=q.shift(),q.sort()),g=p.indexOf(":")<0&&"on"+p,b=b[m.expando]?b:new m.Event(p,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=q.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+q.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:m.makeArray(c,[b]),k=m.event.special[p]||{},e||!k.trigger||k.trigger.apply(d,c)!==!1)){if(!e&&!k.noBubble&&!m.isWindow(d)){for(i=k.delegateType||p,$.test(i+p)||(h=h.parentNode);h;h=h.parentNode)o.push(h),l=h;l===(d.ownerDocument||y)&&o.push(l.defaultView||l.parentWindow||a)}n=0;while((h=o[n++])&&!b.isPropagationStopped())b.type=n>1?i:k.bindType||p,f=(m._data(h,"events")||{})[b.type]&&m._data(h,"handle"),f&&f.apply(h,c),f=g&&h[g],f&&f.apply&&m.acceptData(h)&&(b.result=f.apply(h,c),b.result===!1&&b.preventDefault());if(b.type=p,!e&&!b.isDefaultPrevented()&&(!k._default||k._default.apply(o.pop(),c)===!1)&&m.acceptData(d)&&g&&d[p]&&!m.isWindow(d)){l=d[g],l&&(d[g]=null),m.event.triggered=p;try{d[p]()}catch(r){}m.event.triggered=void 0,l&&(d[g]=l)}return b.result}},dispatch:function(a){a=m.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(m._data(this,"events")||{})[a.type]||[],k=m.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=m.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,g=0;while((e=f.handlers[g++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(e.namespace))&&(a.handleObj=e,a.data=e.data,c=((m.event.special[e.origType]||{}).handle||e.handler).apply(f.elem,i),void 0!==c&&(a.result=c)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!=this;i=i.parentNode||this)if(1===i.nodeType&&(i.disabled!==!0||"click"!==a.type)){for(e=[],f=0;h>f;f++)d=b[f],c=d.selector+" ",void 0===e[c]&&(e[c]=d.needsContext?m(c,this).index(i)>=0:m.find(c,this,null,[i]).length),e[c]&&e.push(d);e.length&&g.push({elem:i,handlers:e})}return h]","i"),hb=/^\s+/,ib=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,jb=/<([\w:]+)/,kb=/\s*$/g,rb={option:[1,""],legend:[1,"
","
"],area:[1,"",""],param:[1,"",""],thead:[1,"","
"],tr:[2,"","
"],col:[2,"","
"],td:[3,"","
"],_default:k.htmlSerialize?[0,"",""]:[1,"X
","
"]},sb=db(y),tb=sb.appendChild(y.createElement("div"));rb.optgroup=rb.option,rb.tbody=rb.tfoot=rb.colgroup=rb.caption=rb.thead,rb.th=rb.td;function ub(a,b){var c,d,e=0,f=typeof a.getElementsByTagName!==K?a.getElementsByTagName(b||"*"):typeof a.querySelectorAll!==K?a.querySelectorAll(b||"*"):void 0;if(!f)for(f=[],c=a.childNodes||a;null!=(d=c[e]);e++)!b||m.nodeName(d,b)?f.push(d):m.merge(f,ub(d,b));return void 0===b||b&&m.nodeName(a,b)?m.merge([a],f):f}function vb(a){W.test(a.type)&&(a.defaultChecked=a.checked)}function wb(a,b){return m.nodeName(a,"table")&&m.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function xb(a){return a.type=(null!==m.find.attr(a,"type"))+"/"+a.type,a}function yb(a){var b=pb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function zb(a,b){for(var c,d=0;null!=(c=a[d]);d++)m._data(c,"globalEval",!b||m._data(b[d],"globalEval"))}function Ab(a,b){if(1===b.nodeType&&m.hasData(a)){var c,d,e,f=m._data(a),g=m._data(b,f),h=f.events;if(h){delete g.handle,g.events={};for(c in h)for(d=0,e=h[c].length;e>d;d++)m.event.add(b,c,h[c][d])}g.data&&(g.data=m.extend({},g.data))}}function Bb(a,b){var c,d,e;if(1===b.nodeType){if(c=b.nodeName.toLowerCase(),!k.noCloneEvent&&b[m.expando]){e=m._data(b);for(d in e.events)m.removeEvent(b,d,e.handle);b.removeAttribute(m.expando)}"script"===c&&b.text!==a.text?(xb(b).text=a.text,yb(b)):"object"===c?(b.parentNode&&(b.outerHTML=a.outerHTML),k.html5Clone&&a.innerHTML&&!m.trim(b.innerHTML)&&(b.innerHTML=a.innerHTML)):"input"===c&&W.test(a.type)?(b.defaultChecked=b.checked=a.checked,b.value!==a.value&&(b.value=a.value)):"option"===c?b.defaultSelected=b.selected=a.defaultSelected:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}}m.extend({clone:function(a,b,c){var d,e,f,g,h,i=m.contains(a.ownerDocument,a);if(k.html5Clone||m.isXMLDoc(a)||!gb.test("<"+a.nodeName+">")?f=a.cloneNode(!0):(tb.innerHTML=a.outerHTML,tb.removeChild(f=tb.firstChild)),!(k.noCloneEvent&&k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||m.isXMLDoc(a)))for(d=ub(f),h=ub(a),g=0;null!=(e=h[g]);++g)d[g]&&Bb(e,d[g]);if(b)if(c)for(h=h||ub(a),d=d||ub(f),g=0;null!=(e=h[g]);g++)Ab(e,d[g]);else Ab(a,f);return d=ub(f,"script"),d.length>0&&zb(d,!i&&ub(a,"script")),d=h=e=null,f},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,l,n=a.length,o=db(b),p=[],q=0;n>q;q++)if(f=a[q],f||0===f)if("object"===m.type(f))m.merge(p,f.nodeType?[f]:f);else if(lb.test(f)){h=h||o.appendChild(b.createElement("div")),i=(jb.exec(f)||["",""])[1].toLowerCase(),l=rb[i]||rb._default,h.innerHTML=l[1]+f.replace(ib,"<$1>")+l[2],e=l[0];while(e--)h=h.lastChild;if(!k.leadingWhitespace&&hb.test(f)&&p.push(b.createTextNode(hb.exec(f)[0])),!k.tbody){f="table"!==i||kb.test(f)?""!==l[1]||kb.test(f)?0:h:h.firstChild,e=f&&f.childNodes.length;while(e--)m.nodeName(j=f.childNodes[e],"tbody")&&!j.childNodes.length&&f.removeChild(j)}m.merge(p,h.childNodes),h.textContent="";while(h.firstChild)h.removeChild(h.firstChild);h=o.lastChild}else p.push(b.createTextNode(f));h&&o.removeChild(h),k.appendChecked||m.grep(ub(p,"input"),vb),q=0;while(f=p[q++])if((!d||-1===m.inArray(f,d))&&(g=m.contains(f.ownerDocument,f),h=ub(o.appendChild(f),"script"),g&&zb(h),c)){e=0;while(f=h[e++])ob.test(f.type||"")&&c.push(f)}return h=null,o},cleanData:function(a,b){for(var d,e,f,g,h=0,i=m.expando,j=m.cache,l=k.deleteExpando,n=m.event.special;null!=(d=a[h]);h++)if((b||m.acceptData(d))&&(f=d[i],g=f&&j[f])){if(g.events)for(e in g.events)n[e]?m.event.remove(d,e):m.removeEvent(d,e,g.handle);j[f]&&(delete j[f],l?delete d[i]:typeof d.removeAttribute!==K?d.removeAttribute(i):d[i]=null,c.push(f))}}}),m.fn.extend({text:function(a){return V(this,function(a){return void 0===a?m.text(this):this.empty().append((this[0]&&this[0].ownerDocument||y).createTextNode(a))},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=wb(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=wb(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?m.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||m.cleanData(ub(c)),c.parentNode&&(b&&m.contains(c.ownerDocument,c)&&zb(ub(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++){1===a.nodeType&&m.cleanData(ub(a,!1));while(a.firstChild)a.removeChild(a.firstChild);a.options&&m.nodeName(a,"select")&&(a.options.length=0)}return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return m.clone(this,a,b)})},html:function(a){return V(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a)return 1===b.nodeType?b.innerHTML.replace(fb,""):void 0;if(!("string"!=typeof a||mb.test(a)||!k.htmlSerialize&&gb.test(a)||!k.leadingWhitespace&&hb.test(a)||rb[(jb.exec(a)||["",""])[1].toLowerCase()])){a=a.replace(ib,"<$1>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(m.cleanData(ub(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,m.cleanData(ub(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,n=this,o=l-1,p=a[0],q=m.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&nb.test(p))return this.each(function(c){var d=n.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(i=m.buildFragment(a,this[0].ownerDocument,!1,this),c=i.firstChild,1===i.childNodes.length&&(i=c),c)){for(g=m.map(ub(i,"script"),xb),f=g.length;l>j;j++)d=i,j!==o&&(d=m.clone(d,!0,!0),f&&m.merge(g,ub(d,"script"))),b.call(this[j],d,j);if(f)for(h=g[g.length-1].ownerDocument,m.map(g,yb),j=0;f>j;j++)d=g[j],ob.test(d.type||"")&&!m._data(d,"globalEval")&&m.contains(h,d)&&(d.src?m._evalUrl&&m._evalUrl(d.src):m.globalEval((d.text||d.textContent||d.innerHTML||"").replace(qb,"")));i=c=null}return this}}),m.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){m.fn[a]=function(a){for(var c,d=0,e=[],g=m(a),h=g.length-1;h>=d;d++)c=d===h?this:this.clone(!0),m(g[d])[b](c),f.apply(e,c.get());return this.pushStack(e)}});var Cb,Db={};function Eb(b,c){var d,e=m(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:m.css(e[0],"display");return e.detach(),f}function Fb(a){var b=y,c=Db[a];return c||(c=Eb(a,b),"none"!==c&&c||(Cb=(Cb||m("