Skip to content

Integrate uri #654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "deps/asio"]
path = deps/asio
url = https://github.com/chriskohlhoff/asio.git
[submodule "deps/uri"]
path = deps/uri
url = https://github.com/cpp-netlib/uri.git
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ compiler:
- g++
- clang
env:
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="ON"
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="OFF"
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="ON"
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="OFF"
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="ON"
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="OFF"
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="ON"
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="OFF"
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="ON" Uri_BUILD_TESTS=OFF Uri_DISABLE_LIBCXX=YES
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="OFF" Uri_BUILD_TESTS=OFF Uri_DISABLE_LIBCXX=YES
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="ON" Uri_BUILD_TESTS=OFF Uri_DISABLE_LIBCXX=YES
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="OFF" Uri_BUILD_TESTS=OFF Uri_DISABLE_LIBCXX=YES
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="ON" Uri_BUILD_TESTS=OFF Uri_DISABLE_LIBCXX=YES
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="OFF" Uri_BUILD_TESTS=OFF Uri_DISABLE_LIBCXX=YES
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="ON" Uri_BUILD_TESTS=OFF Uri_DISABLE_LIBCXX=YES
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="OFF" Uri_BUILD_TESTS=OFF Uri_DISABLE_LIBCXX=YES
# Support the sanitizers in clang only
# - BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="ON" CMAKE_CXX_FLAGS="-fsanitize=thread"
# - BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="ON" CMAKE_CXX_FLAGS="-fsanitize=address"
Expand Down
89 changes: 45 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ project(CPP-NETLIB)

option( CPP-NETLIB_BUILD_SHARED_LIBS "Build cpp-netlib as shared libraries." OFF )
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)

Expand Down Expand Up @@ -49,7 +48,7 @@ set(Boost_USE_MULTI_THREADED ON)
find_package(Boost 1.57.0 REQUIRED)

if (CPP-NETLIB_ENABLE_HTTPS)
find_package( OpenSSL )
find_package( OpenSSL )
endif()

find_package( Threads )
Expand Down Expand Up @@ -83,6 +82,13 @@ elseif (${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
endif()
endif()

if (NOT MSVC)
set(Uri_BUILD_TESTS OFF)
set(Uri_BUILD_DOCS OFF)
set(Uri_DISABLE_LIBCXX ON)
add_subdirectory(deps/uri)
include_directories(deps/uri/include)
endif()

if (Boost_FOUND)
if (MSVC)
Expand All @@ -101,14 +107,9 @@ if (Boost_FOUND)
add_subdirectory(libs/network/src)
if (CPP-NETLIB_BUILD_TESTS)
add_subdirectory(deps/googletest)
add_subdirectory(deps/uri/test)
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)
Expand All @@ -122,39 +123,39 @@ enable_testing()

install(DIRECTORY boost DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

###
## Export Targets
# (so cpp-netlib can be easily used by other CMake projects)
# [see http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file]

# Add all targets to the build-tree export set
export(TARGETS cppnetlib-client-connections cppnetlib-server-parsers cppnetlib-uri
FILE "${PROJECT_BINARY_DIR}/cppnetlibTargets.cmake")
# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
export(PACKAGE cppnetlib)
# Create the cppnetlibConfig.cmake and cppnetlibConfigVersion files
file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}"
"${CMAKE_INSTALL_FULL_INCLUDEDIR}")
# ... for the build tree
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" ${Boost_INCLUDE_DIRS})
configure_file(cppnetlibConfig.cmake.in
"${PROJECT_BINARY_DIR}/cppnetlibConfig.cmake" @ONLY)
# ... for the install tree
set(CONF_INCLUDE_DIRS "\${CPPNETLIB_CMAKE_DIR}/${REL_INCLUDE_DIR}")
set(CONF_INCLUDE_DIRS ${CONF_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
configure_file(cppnetlibConfig.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cppnetlibConfig.cmake" @ONLY)
# ... for both
configure_file(cppnetlibConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/cppnetlibConfigVersion.cmake" @ONLY)
# Install the cppnetlibConfig.cmake and cppnetlibConfigVersion.cmake
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cppnetlibConfig.cmake"
"${PROJECT_BINARY_DIR}/cppnetlibConfigVersion.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}"
COMPONENT dev)
# Install the export set for use with the install-tree
install(EXPORT cppnetlibTargets
DESTINATION "${INSTALL_CMAKE_DIR}"
COMPONENT dev)
# ###
# ## Export Targets
# # (so cpp-netlib can be easily used by other CMake projects)
# # [see http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file]
#
# # Add all targets to the build-tree export set
# export(TARGETS cppnetlib-client-connections cppnetlib-server-parsers cppnetlib-uri
# FILE "${PROJECT_BINARY_DIR}/cppnetlibTargets.cmake")
# # Export the package for use from the build-tree
# # (this registers the build-tree with a global CMake-registry)
# export(PACKAGE cppnetlib)
# # Create the cppnetlibConfig.cmake and cppnetlibConfigVersion files
# file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}"
# "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
# # ... for the build tree
# set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" ${Boost_INCLUDE_DIRS})
# configure_file(cppnetlibConfig.cmake.in
# "${PROJECT_BINARY_DIR}/cppnetlibConfig.cmake" @ONLY)
# # ... for the install tree
# set(CONF_INCLUDE_DIRS "\${CPPNETLIB_CMAKE_DIR}/${REL_INCLUDE_DIR}")
# set(CONF_INCLUDE_DIRS ${CONF_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
# configure_file(cppnetlibConfig.cmake.in
# "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cppnetlibConfig.cmake" @ONLY)
# # ... for both
# configure_file(cppnetlibConfigVersion.cmake.in
# "${PROJECT_BINARY_DIR}/cppnetlibConfigVersion.cmake" @ONLY)
# # Install the cppnetlibConfig.cmake and cppnetlibConfigVersion.cmake
# install(FILES
# "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cppnetlibConfig.cmake"
# "${PROJECT_BINARY_DIR}/cppnetlibConfigVersion.cmake"
# DESTINATION "${INSTALL_CMAKE_DIR}"
# COMPONENT dev)
# # Install the export set for use with the install-tree
# install(EXPORT cppnetlibTargets
# DESTINATION "${INSTALL_CMAKE_DIR}"
# COMPONENT dev)
5 changes: 4 additions & 1 deletion boost/network/protocol/http/client/connection/async_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
// http://www.boost.org/LICENSE_1_0.txt)

#include <functional>
#include <array>
#include <boost/network/protocol/http/client/connection/connection_delegate_factory.hpp>
#include <boost/network/protocol/http/response.hpp>
#include <boost/network/protocol/http/traits/delegate_factory.hpp>
#include <boost/network/protocol/http/client/connection/async_normal.hpp>
#include <boost/network/protocol/http/traits/resolver_policy.hpp>
#include <boost/network/traits/string.hpp>

namespace boost {
namespace network {
Expand All @@ -29,7 +31,8 @@ struct async_connection_base {
typedef typename string<Tag>::type string_type;
typedef basic_request<Tag> request;
typedef basic_response<Tag> response;
typedef iterator_range<char const *> char_const_range;
typedef typename std::array<typename char_<Tag>::type, 1024>::const_iterator const_iterator;
typedef iterator_range<const_iterator> char_const_range;
typedef std::function<void(char_const_range const &, std::error_code const &)>
body_callback_function_type;
typedef std::function<bool(string_type &)> body_generator_function_type;
Expand Down
28 changes: 14 additions & 14 deletions boost/network/protocol/http/impl/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include <cstdint>
#include <network/uri/uri.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/fusion/container/map.hpp>
#include <boost/fusion/sequence/intrinsic/at_key.hpp>
Expand All @@ -29,7 +30,6 @@
#include <boost/network/protocol/http/message/wrappers/headers.hpp>
#include <boost/network/support/is_async.hpp>
#include <boost/network/traits/vector.hpp>
#include <boost/network/uri/uri.hpp>

namespace boost {
namespace network {
Expand All @@ -50,7 +50,7 @@ namespace http {
*/
template <class Tag>
struct basic_request : public basic_message<Tag> {
boost::network::uri::uri uri_;
::network::uri uri_;
std::uint16_t source_port_;
typedef basic_message<Tag> base_type;

Expand All @@ -62,7 +62,7 @@ struct basic_request : public basic_message<Tag> {
explicit basic_request(string_type const& uri_)
: uri_(uri_), source_port_(0) {}

explicit basic_request(boost::network::uri::uri const& uri_)
explicit basic_request(::network::uri const& uri_)
: uri_(uri_), source_port_(0) {}

basic_request() : base_type(), source_port_(0) {}
Expand All @@ -83,29 +83,29 @@ struct basic_request : public basic_message<Tag> {
boost::swap(other.source_port_, this->source_port_);
}

string_type const host() const { return uri_.host(); }
string_type const host() const { return uri_.host().to_string(); }

port_type port() const {
boost::optional<port_type> port = uri::port_us(uri_);
if (!port) {
if (uri_.has_port()) {
return uri_.port<std::uint16_t>();
}
else {
typedef constants<Tag> consts;
return boost::iequals(uri_.scheme(), string_type(consts::https())) ? 443
: 80;
return boost::iequals(uri_.scheme(), string_type(consts::https())) ? 443 : 80;
}
return *port;
}

string_type const path() const { return uri_.path(); }
string_type const path() const { return uri_.path().to_string(); }

string_type const query() const { return uri_.query(); }
string_type const query() const { return uri_.query().to_string(); }

string_type const anchor() const { return uri_.fragment(); }
string_type const anchor() const { return uri_.fragment().to_string(); }

string_type const protocol() const { return uri_.scheme(); }
string_type const protocol() const { return uri_.scheme().to_string(); }

void uri(string_type const& new_uri) const { uri_ = new_uri; }

boost::network::uri::uri const& uri() const { return uri_; }
::network::uri const& uri() const { return uri_; }

void source_port(const std::uint16_t port) { source_port_ = port; }

Expand Down
11 changes: 6 additions & 5 deletions boost/network/protocol/http/message/wrappers/port.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// http://www.boost.org/LICENSE_1_0.txt)

#include <cstdint>
#include <boost/network/uri/accessors.hpp>
#include <network/uri/uri.hpp>
#include <boost/optional.hpp>
#include <boost/version.hpp>

Expand Down Expand Up @@ -38,13 +38,14 @@ struct port_wrapper {
// conversions no longer work correctly with MSVC. The conversion therefore
// has to be done explicitly with as_optional().
boost::optional<std::uint16_t> as_optional() const {
return uri::port_us(message_.uri());
}
#else
operator boost::optional<std::uint16_t>() const {
return uri::port_us(message_.uri());
}
#endif
if (message_.uri().has_port()) {
return message_.uri().template port<std::uint16_t>();
}
return boost::optional<std::uint16_t>();
}

};

Expand Down
6 changes: 3 additions & 3 deletions boost/network/protocol/http/message/wrappers/uri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <boost/network/uri/uri.hpp>
#include <network/uri/uri.hpp>

namespace boost {
namespace network {
Expand All @@ -22,8 +22,8 @@ struct uri_wrapper {
basic_request<Tag> const& message_;
explicit uri_wrapper(basic_request<Tag> const& message) : message_(message) {}
typedef typename basic_request<Tag>::string_type string_type;
operator string_type() { return message_.uri().raw(); }
operator boost::network::uri::uri() { return message_.uri(); }
operator string_type() { return message_.uri().to_string(); }
operator ::network::uri() { return message_.uri(); }
};
} // namespace impl

Expand Down
22 changes: 5 additions & 17 deletions boost/network/protocol/stream_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ 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 std::system_error&) {
// print system error
}
}

Expand All @@ -93,11 +90,8 @@ 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;
// print system error
}
}

Expand Down Expand Up @@ -126,11 +120,8 @@ struct stream_handler {
tcp_sock_->shutdown(::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;

}
}

Expand Down Expand Up @@ -162,11 +153,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;

}
}
std::shared_ptr<tcp_socket> get_tcp_socket() { return tcp_sock_; }
Expand Down
11 changes: 0 additions & 11 deletions boost/network/uri.hpp

This file was deleted.

Loading