Skip to content

Commit 9cd77a7

Browse files
committed
Merge pull request #654 from glynos/integrate_uri
Integrate uri
2 parents 9c332f1 + 5877db3 commit 9cd77a7

Some content is hidden

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

45 files changed

+122
-2858
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
[submodule "deps/asio"]
1414
path = deps/asio
1515
url = https://github.com/chriskohlhoff/asio.git
16+
[submodule "deps/uri"]
17+
path = deps/uri
18+
url = https://github.com/cpp-netlib/uri.git

.travis.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ compiler:
44
- g++
55
- clang
66
env:
7-
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="ON"
8-
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="OFF"
9-
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="ON"
10-
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="OFF"
11-
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="ON"
12-
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="OFF"
13-
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="ON"
14-
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="OFF"
7+
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="ON" Uri_BUILD_TESTS=OFF Uri_DISABLE_LIBCXX=YES
8+
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="OFF" Uri_BUILD_TESTS=OFF Uri_DISABLE_LIBCXX=YES
9+
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="ON" Uri_BUILD_TESTS=OFF Uri_DISABLE_LIBCXX=YES
10+
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="OFF" Uri_BUILD_TESTS=OFF Uri_DISABLE_LIBCXX=YES
11+
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="ON" Uri_BUILD_TESTS=OFF Uri_DISABLE_LIBCXX=YES
12+
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="OFF" Uri_BUILD_TESTS=OFF Uri_DISABLE_LIBCXX=YES
13+
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="ON" Uri_BUILD_TESTS=OFF Uri_DISABLE_LIBCXX=YES
14+
- BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="OFF" Uri_BUILD_TESTS=OFF Uri_DISABLE_LIBCXX=YES
1515
# Support the sanitizers in clang only
1616
# - BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="ON" CMAKE_CXX_FLAGS="-fsanitize=thread"
1717
# - BOOST_VER=1.59.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="ON" CMAKE_CXX_FLAGS="-fsanitize=address"

CMakeLists.txt

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ project(CPP-NETLIB)
99

1010
option( CPP-NETLIB_BUILD_SHARED_LIBS "Build cpp-netlib as shared libraries." OFF )
1111
option( CPP-NETLIB_BUILD_TESTS "Build the cpp-netlib project tests." ON)
12-
# option( CPP-NETLIB_BUILD_EXPERIMENTS "Build the cpp-netlib project experiments." ON)
1312
option( CPP-NETLIB_BUILD_EXAMPLES "Build the cpp-netlib project examples." ON)
1413
option( CPP-NETLIB_ENABLE_HTTPS "Build cpp-netlib with support for https if OpenSSL is found." ON)
1514

@@ -49,7 +48,7 @@ set(Boost_USE_MULTI_THREADED ON)
4948
find_package(Boost 1.57.0 REQUIRED)
5049

5150
if (CPP-NETLIB_ENABLE_HTTPS)
52-
find_package( OpenSSL )
51+
find_package( OpenSSL )
5352
endif()
5453

5554
find_package( Threads )
@@ -83,6 +82,13 @@ elseif (${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
8382
endif()
8483
endif()
8584

85+
if (NOT MSVC)
86+
set(Uri_BUILD_TESTS OFF)
87+
set(Uri_BUILD_DOCS OFF)
88+
set(Uri_DISABLE_LIBCXX ON)
89+
add_subdirectory(deps/uri)
90+
include_directories(deps/uri/include)
91+
endif()
8692

8793
if (Boost_FOUND)
8894
if (MSVC)
@@ -101,14 +107,9 @@ if (Boost_FOUND)
101107
add_subdirectory(libs/network/src)
102108
if (CPP-NETLIB_BUILD_TESTS)
103109
add_subdirectory(deps/googletest)
110+
add_subdirectory(deps/uri/test)
104111
add_subdirectory(libs/network/test)
105112
endif (CPP-NETLIB_BUILD_TESTS)
106-
# if (CPP-NETLIB_BUILD_EXPERIMENTS)
107-
# add_subdirectory(libs/network/experiment)
108-
# endif (CPP-NETLIB_BUILD_EXPERIMENTS)
109-
# if (NOT MSVC AND CPP-NETLIB_BUILD_TESTS)
110-
# add_subdirectory(libs/mime/test)
111-
# endif(NOT MSVC AND CPP-NETLIB_BUILD_TESTS)
112113
if (CPP-NETLIB_BUILD_EXAMPLES)
113114
add_subdirectory(libs/network/example)
114115
endif (CPP-NETLIB_BUILD_EXAMPLES)
@@ -122,39 +123,39 @@ enable_testing()
122123

123124
install(DIRECTORY boost DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
124125

125-
###
126-
## Export Targets
127-
# (so cpp-netlib can be easily used by other CMake projects)
128-
# [see http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file]
129-
130-
# Add all targets to the build-tree export set
131-
export(TARGETS cppnetlib-client-connections cppnetlib-server-parsers cppnetlib-uri
132-
FILE "${PROJECT_BINARY_DIR}/cppnetlibTargets.cmake")
133-
# Export the package for use from the build-tree
134-
# (this registers the build-tree with a global CMake-registry)
135-
export(PACKAGE cppnetlib)
136-
# Create the cppnetlibConfig.cmake and cppnetlibConfigVersion files
137-
file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}"
138-
"${CMAKE_INSTALL_FULL_INCLUDEDIR}")
139-
# ... for the build tree
140-
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" ${Boost_INCLUDE_DIRS})
141-
configure_file(cppnetlibConfig.cmake.in
142-
"${PROJECT_BINARY_DIR}/cppnetlibConfig.cmake" @ONLY)
143-
# ... for the install tree
144-
set(CONF_INCLUDE_DIRS "\${CPPNETLIB_CMAKE_DIR}/${REL_INCLUDE_DIR}")
145-
set(CONF_INCLUDE_DIRS ${CONF_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
146-
configure_file(cppnetlibConfig.cmake.in
147-
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cppnetlibConfig.cmake" @ONLY)
148-
# ... for both
149-
configure_file(cppnetlibConfigVersion.cmake.in
150-
"${PROJECT_BINARY_DIR}/cppnetlibConfigVersion.cmake" @ONLY)
151-
# Install the cppnetlibConfig.cmake and cppnetlibConfigVersion.cmake
152-
install(FILES
153-
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cppnetlibConfig.cmake"
154-
"${PROJECT_BINARY_DIR}/cppnetlibConfigVersion.cmake"
155-
DESTINATION "${INSTALL_CMAKE_DIR}"
156-
COMPONENT dev)
157-
# Install the export set for use with the install-tree
158-
install(EXPORT cppnetlibTargets
159-
DESTINATION "${INSTALL_CMAKE_DIR}"
160-
COMPONENT dev)
126+
# ###
127+
# ## Export Targets
128+
# # (so cpp-netlib can be easily used by other CMake projects)
129+
# # [see http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file]
130+
#
131+
# # Add all targets to the build-tree export set
132+
# export(TARGETS cppnetlib-client-connections cppnetlib-server-parsers cppnetlib-uri
133+
# FILE "${PROJECT_BINARY_DIR}/cppnetlibTargets.cmake")
134+
# # Export the package for use from the build-tree
135+
# # (this registers the build-tree with a global CMake-registry)
136+
# export(PACKAGE cppnetlib)
137+
# # Create the cppnetlibConfig.cmake and cppnetlibConfigVersion files
138+
# file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}"
139+
# "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
140+
# # ... for the build tree
141+
# set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" ${Boost_INCLUDE_DIRS})
142+
# configure_file(cppnetlibConfig.cmake.in
143+
# "${PROJECT_BINARY_DIR}/cppnetlibConfig.cmake" @ONLY)
144+
# # ... for the install tree
145+
# set(CONF_INCLUDE_DIRS "\${CPPNETLIB_CMAKE_DIR}/${REL_INCLUDE_DIR}")
146+
# set(CONF_INCLUDE_DIRS ${CONF_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
147+
# configure_file(cppnetlibConfig.cmake.in
148+
# "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cppnetlibConfig.cmake" @ONLY)
149+
# # ... for both
150+
# configure_file(cppnetlibConfigVersion.cmake.in
151+
# "${PROJECT_BINARY_DIR}/cppnetlibConfigVersion.cmake" @ONLY)
152+
# # Install the cppnetlibConfig.cmake and cppnetlibConfigVersion.cmake
153+
# install(FILES
154+
# "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cppnetlibConfig.cmake"
155+
# "${PROJECT_BINARY_DIR}/cppnetlibConfigVersion.cmake"
156+
# DESTINATION "${INSTALL_CMAKE_DIR}"
157+
# COMPONENT dev)
158+
# # Install the export set for use with the install-tree
159+
# install(EXPORT cppnetlibTargets
160+
# DESTINATION "${INSTALL_CMAKE_DIR}"
161+
# COMPONENT dev)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
// http://www.boost.org/LICENSE_1_0.txt)
1010

1111
#include <functional>
12+
#include <array>
1213
#include <boost/network/protocol/http/client/connection/connection_delegate_factory.hpp>
1314
#include <boost/network/protocol/http/response.hpp>
1415
#include <boost/network/protocol/http/traits/delegate_factory.hpp>
1516
#include <boost/network/protocol/http/client/connection/async_normal.hpp>
1617
#include <boost/network/protocol/http/traits/resolver_policy.hpp>
18+
#include <boost/network/traits/string.hpp>
1719

1820
namespace boost {
1921
namespace network {
@@ -29,7 +31,8 @@ struct async_connection_base {
2931
typedef typename string<Tag>::type string_type;
3032
typedef basic_request<Tag> request;
3133
typedef basic_response<Tag> response;
32-
typedef iterator_range<char const *> char_const_range;
34+
typedef typename std::array<typename char_<Tag>::type, 1024>::const_iterator const_iterator;
35+
typedef iterator_range<const_iterator> char_const_range;
3336
typedef std::function<void(char_const_range const &, std::error_code const &)>
3437
body_callback_function_type;
3538
typedef std::function<bool(string_type &)> body_generator_function_type;

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include <cstdint>
20+
#include <network/uri/uri.hpp>
2021
#include <boost/algorithm/string.hpp>
2122
#include <boost/fusion/container/map.hpp>
2223
#include <boost/fusion/sequence/intrinsic/at_key.hpp>
@@ -29,7 +30,6 @@
2930
#include <boost/network/protocol/http/message/wrappers/headers.hpp>
3031
#include <boost/network/support/is_async.hpp>
3132
#include <boost/network/traits/vector.hpp>
32-
#include <boost/network/uri/uri.hpp>
3333

3434
namespace boost {
3535
namespace network {
@@ -50,7 +50,7 @@ namespace http {
5050
*/
5151
template <class Tag>
5252
struct basic_request : public basic_message<Tag> {
53-
boost::network::uri::uri uri_;
53+
::network::uri uri_;
5454
std::uint16_t source_port_;
5555
typedef basic_message<Tag> base_type;
5656

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

65-
explicit basic_request(boost::network::uri::uri const& uri_)
65+
explicit basic_request(::network::uri const& uri_)
6666
: uri_(uri_), source_port_(0) {}
6767

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

86-
string_type const host() const { return uri_.host(); }
86+
string_type const host() const { return uri_.host().to_string(); }
8787

8888
port_type port() const {
89-
boost::optional<port_type> port = uri::port_us(uri_);
90-
if (!port) {
89+
if (uri_.has_port()) {
90+
return uri_.port<std::uint16_t>();
91+
}
92+
else {
9193
typedef constants<Tag> consts;
92-
return boost::iequals(uri_.scheme(), string_type(consts::https())) ? 443
93-
: 80;
94+
return boost::iequals(uri_.scheme(), string_type(consts::https())) ? 443 : 80;
9495
}
95-
return *port;
9696
}
9797

98-
string_type const path() const { return uri_.path(); }
98+
string_type const path() const { return uri_.path().to_string(); }
9999

100-
string_type const query() const { return uri_.query(); }
100+
string_type const query() const { return uri_.query().to_string(); }
101101

102-
string_type const anchor() const { return uri_.fragment(); }
102+
string_type const anchor() const { return uri_.fragment().to_string(); }
103103

104-
string_type const protocol() const { return uri_.scheme(); }
104+
string_type const protocol() const { return uri_.scheme().to_string(); }
105105

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

108-
boost::network::uri::uri const& uri() const { return uri_; }
108+
::network::uri const& uri() const { return uri_; }
109109

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

boost/network/protocol/http/message/wrappers/port.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// http://www.boost.org/LICENSE_1_0.txt)
1111

1212
#include <cstdint>
13-
#include <boost/network/uri/accessors.hpp>
13+
#include <network/uri/uri.hpp>
1414
#include <boost/optional.hpp>
1515
#include <boost/version.hpp>
1616

@@ -38,13 +38,14 @@ struct port_wrapper {
3838
// conversions no longer work correctly with MSVC. The conversion therefore
3939
// has to be done explicitly with as_optional().
4040
boost::optional<std::uint16_t> as_optional() const {
41-
return uri::port_us(message_.uri());
42-
}
4341
#else
4442
operator boost::optional<std::uint16_t>() const {
45-
return uri::port_us(message_.uri());
46-
}
4743
#endif
44+
if (message_.uri().has_port()) {
45+
return message_.uri().template port<std::uint16_t>();
46+
}
47+
return boost::optional<std::uint16_t>();
48+
}
4849

4950
};
5051

boost/network/protocol/http/message/wrappers/uri.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// (See accompanying file LICENSE_1_0.txt or copy at
88
// http://www.boost.org/LICENSE_1_0.txt)
99

10-
#include <boost/network/uri/uri.hpp>
10+
#include <network/uri/uri.hpp>
1111

1212
namespace boost {
1313
namespace network {
@@ -22,8 +22,8 @@ struct uri_wrapper {
2222
basic_request<Tag> const& message_;
2323
explicit uri_wrapper(basic_request<Tag> const& message) : message_(message) {}
2424
typedef typename basic_request<Tag>::string_type string_type;
25-
operator string_type() { return message_.uri().raw(); }
26-
operator boost::network::uri::uri() { return message_.uri(); }
25+
operator string_type() { return message_.uri().to_string(); }
26+
operator ::network::uri() { return message_.uri(); }
2727
};
2828
} // namespace impl
2929

boost/network/protocol/stream_handler.hpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,8 @@ struct stream_handler {
7373
tcp_sock_->async_write_some(buffers, handler);
7474
}
7575
}
76-
catch (const std::error_code& e) {
77-
std::cerr << e.message() << std::endl;
78-
}
79-
catch (const std::system_error& e) {
80-
std::cerr << e.code() << ": " << e.what() << std::endl;
76+
catch (const std::system_error&) {
77+
// print system error
8178
}
8279
}
8380

@@ -93,11 +90,8 @@ struct stream_handler {
9390
tcp_sock_->async_read_some(buffers, handler);
9491
}
9592
}
96-
catch (const std::error_code& e) {
97-
std::cerr << e.message() << std::endl;
98-
}
9993
catch (const std::system_error& e) {
100-
std::cerr << e.code() << ": " << e.what() << std::endl;
94+
// print system error
10195
}
10296
}
10397

@@ -126,11 +120,8 @@ struct stream_handler {
126120
tcp_sock_->shutdown(::asio::ip::tcp::socket::shutdown_send, e);
127121
}
128122
}
129-
catch (const std::error_code& e) {
130-
std::cerr << e.message() << std::endl;
131-
}
132123
catch (const std::system_error& e) {
133-
std::cerr << e.code() << ": " << e.what() << std::endl;
124+
134125
}
135126
}
136127

@@ -162,11 +153,8 @@ struct stream_handler {
162153
// NOOP
163154
}
164155
}
165-
catch (const std::error_code& e) {
166-
std::cerr << e.message() << std::endl;
167-
}
168156
catch (const std::system_error& e) {
169-
std::cerr << e.code() << ": " << e.what() << std::endl;
157+
170158
}
171159
}
172160
std::shared_ptr<tcp_socket> get_tcp_socket() { return tcp_sock_; }

boost/network/uri.hpp

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)