forked from openthread/ot-br-posix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[web] bump to latest Simple-Web-Server version (openthread#1667)
Bump Simple-Web-Server to the latest git commit. This fixes a compile issue seen with GCC 12.2.0: In file included from /home/sag/projects/openthread/ot-br-posix/src/web/web-service/web_server.cpp:42: /home/sag/projects/openthread/ot-br-posix/third_party/Simple-web-server/repo/server_http.hpp: In instantiation of ‘SimpleWeb::ServerBase<socket_type>::Request::Request(const socket_type&) [with socket_type = boost::asio::basic_stream_socket<boost::asio::ip::tcp>]’: /home/sag/projects/openthread/ot-br-posix/third_party/Simple-web-server/repo/server_http.hpp:460:74: required from here /home/sag/projects/openthread/ot-br-posix/third_party/Simple-web-server/repo/server_http.hpp:119:57: error: member ‘SimpleWeb::ServerBase<boost::asio::basic_stream_socket<boost::asio::ip::tcp> >::Request::streambuf’ is used uninitialized [-Werror=uninitialized] 119 | Request(const socket_type &socket): content(streambuf) { | ^~~~~~~~~ (cherry picked from commit e4a428f)
- Loading branch information
Showing
34 changed files
with
7,786 additions
and
1,963 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,95 @@ | ||
cmake_minimum_required (VERSION 2.8.8) | ||
project (Simple-Web-Server) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra") | ||
cmake_minimum_required(VERSION 3.0) | ||
|
||
include_directories(.) | ||
project(Simple-Web-Server) | ||
|
||
option(USE_STANDALONE_ASIO "set ON to use standalone Asio instead of Boost.Asio" OFF) | ||
if(CMAKE_SOURCE_DIR STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") | ||
option(BUILD_TESTING "set ON to build library tests" ON) | ||
else() | ||
option(BUILD_TESTING "set ON to build library tests" OFF) | ||
endif() | ||
option(BUILD_FUZZING "set ON to build library fuzzers" OFF) | ||
option(USE_OPENSSL "set OFF to build without OpenSSL" ON) | ||
|
||
add_library(simple-web-server INTERFACE) | ||
|
||
target_include_directories(simple-web-server INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
find_package(Threads REQUIRED) | ||
target_link_libraries(simple-web-server INTERFACE ${CMAKE_THREAD_LIBS_INIT}) | ||
|
||
set(BOOST_COMPONENTS system thread filesystem date_time) | ||
# Late 2017 TODO: remove the following checks and always use std::regex | ||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") | ||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) | ||
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} regex) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST_REGEX") | ||
# TODO 2020 when Debian Jessie LTS ends: | ||
# Remove Boost system, thread, regex components; use Boost::<component> aliases; remove Boost target_include_directories | ||
if(USE_STANDALONE_ASIO) | ||
target_compile_definitions(simple-web-server INTERFACE ASIO_STANDALONE) | ||
find_path(ASIO_PATH asio.hpp) | ||
if(NOT ASIO_PATH) | ||
message(FATAL_ERROR "Standalone Asio not found") | ||
else() | ||
target_include_directories(simple-web-server INTERFACE ${ASIO_PATH}) | ||
endif() | ||
else() | ||
find_package(Boost 1.53.0 COMPONENTS system thread REQUIRED) | ||
target_link_libraries(simple-web-server INTERFACE ${Boost_LIBRARIES}) | ||
target_include_directories(simple-web-server INTERFACE ${Boost_INCLUDE_DIR}) | ||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) | ||
target_compile_definitions(simple-web-server INTERFACE USE_BOOST_REGEX) | ||
find_package(Boost 1.53.0 COMPONENTS regex REQUIRED) | ||
target_link_libraries(simple-web-server INTERFACE ${Boost_LIBRARIES}) | ||
target_include_directories(simple-web-server INTERFACE ${Boost_INCLUDE_DIR}) | ||
endif() | ||
endif() | ||
if(WIN32) | ||
target_link_libraries(simple-web-server INTERFACE ws2_32 wsock32) | ||
endif() | ||
find_package(Boost 1.53.0 COMPONENTS ${BOOST_COMPONENTS} REQUIRED) | ||
include_directories(SYSTEM ${Boost_INCLUDE_DIR}) | ||
|
||
if(APPLE) | ||
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl") | ||
if(EXISTS /usr/local/opt/openssl) | ||
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl) | ||
elseif(EXISTS /opt/homebrew/opt/openssl) | ||
set(OPENSSL_ROOT_DIR /opt/homebrew/opt/openssl) | ||
endif() | ||
endif() | ||
if(USE_OPENSSL) | ||
find_package(OpenSSL) | ||
endif() | ||
if(OPENSSL_FOUND) | ||
target_compile_definitions(simple-web-server INTERFACE HAVE_OPENSSL) | ||
target_link_libraries(simple-web-server INTERFACE ${OPENSSL_LIBRARIES}) | ||
target_include_directories(simple-web-server INTERFACE ${OPENSSL_INCLUDE_DIR}) | ||
endif() | ||
|
||
add_executable(http_examples http_examples.cpp) | ||
target_link_libraries(http_examples ${Boost_LIBRARIES}) | ||
target_link_libraries(http_examples ${CMAKE_THREAD_LIBS_INIT}) | ||
|
||
#TODO: add requirement for version 1.0.1g (can it be done in one line?) | ||
find_package(OpenSSL) | ||
# If Simple-Web-Server is not a sub-project: | ||
if(CMAKE_SOURCE_DIR STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") | ||
if(NOT MSVC) | ||
add_compile_options(-std=c++11 -Wall -Wextra) | ||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
add_compile_options(-Wthread-safety) | ||
endif() | ||
else() | ||
add_compile_options(/W1) | ||
endif() | ||
|
||
if(OPENSSL_FOUND) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_OPENSSL") | ||
target_link_libraries(http_examples ${OPENSSL_LIBRARIES}) | ||
include_directories(SYSTEM ${OPENSSL_INCLUDE_DIR}) | ||
find_package(Boost 1.53.0 COMPONENTS system thread filesystem) | ||
if(Boost_FOUND) | ||
add_executable(http_examples http_examples.cpp) | ||
target_link_libraries(http_examples simple-web-server) | ||
target_link_libraries(http_examples ${Boost_LIBRARIES}) | ||
target_include_directories(http_examples PRIVATE ${Boost_INCLUDE_DIR}) | ||
if(OPENSSL_FOUND) | ||
add_executable(https_examples https_examples.cpp) | ||
target_link_libraries(https_examples simple-web-server) | ||
target_link_libraries(https_examples ${Boost_LIBRARIES}) | ||
target_include_directories(https_examples PRIVATE ${Boost_INCLUDE_DIR}) | ||
endif() | ||
endif() | ||
|
||
add_executable(https_examples https_examples.cpp) | ||
target_link_libraries(https_examples ${Boost_LIBRARIES}) | ||
target_link_libraries(https_examples ${OPENSSL_LIBRARIES}) | ||
target_link_libraries(https_examples ${CMAKE_THREAD_LIBS_INIT}) | ||
install(FILES asio_compatibility.hpp server_http.hpp client_http.hpp server_https.hpp client_https.hpp crypto.hpp utility.hpp status_code.hpp mutex.hpp DESTINATION include/simple-web-server) | ||
endif() | ||
|
||
if(MSYS) #TODO: Is MSYS true when MSVC is true? | ||
target_link_libraries(http_examples ws2_32 wsock32) | ||
if(OPENSSL_FOUND) | ||
target_link_libraries(https_examples ws2_32 wsock32) | ||
if(BUILD_TESTING OR BUILD_FUZZING) | ||
if(BUILD_TESTING) | ||
enable_testing() | ||
endif() | ||
add_subdirectory(tests) | ||
endif() | ||
|
||
enable_testing() | ||
add_subdirectory(tests) | ||
|
||
install(FILES server_http.hpp client_http.hpp server_https.hpp client_https.hpp DESTINATION include/simple-web-server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,90 @@ | ||
Simple-Web-Server [![Build Status](https://travis-ci.org/eidheim/Simple-Web-Server.svg?branch=master)](https://travis-ci.org/eidheim/Simple-Web-Server) | ||
================= | ||
# Simple-Web-Server | ||
|
||
A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications. | ||
A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Asio (both Boost.Asio and standalone Asio can be used). Created to be an easy way to make REST resources available from C++ applications. | ||
|
||
See https://github.com/eidheim/Simple-WebSocket-Server for an easy way to make WebSocket/WebSocket Secure endpoints in C++. Also, feel free to check out the new C++ IDE supporting C++11/14/17: https://github.com/cppit/jucipp. | ||
See https://gitlab.com/eidheim/Simple-WebSocket-Server for an easy way to make WebSocket/WebSocket Secure endpoints in C++. Also, feel free to check out the new C++ IDE supporting C++11/14/17: https://gitlab.com/cppit/jucipp. | ||
|
||
### Features | ||
## Features | ||
|
||
* Asynchronous request handling | ||
* Thread pool if needed | ||
* Platform independent | ||
* HTTPS support | ||
* HTTP persistent connection (for HTTP/1.1) | ||
* Client supports chunked transfer encoding | ||
* Timeouts, if any of Server::timeout_request and Server::timeout_content are >0 (default: Server::timeout_request=5 seconds, and Server::timeout_content=300 seconds) | ||
* Simple way to add REST resources using regex for path, and anonymous functions | ||
* HTTP/1.1 supported, including persistent connections | ||
* HTTPS supported | ||
* Chunked transfer encoding and server-sent events | ||
* Can set timeouts for request/response and content | ||
* Can set max request/response size | ||
* Sending outgoing messages is thread safe | ||
* Client creates necessary connections and perform reconnects when needed | ||
|
||
### Usage | ||
See also [benchmarks](https://gitlab.com/eidheim/Simple-Web-Server/blob/master/docs/benchmarks.md) for a performance comparisons to a few other HTTP libraries. | ||
|
||
See http_examples.cpp or https_examples.cpp for example usage. | ||
## Usage | ||
|
||
See particularly the JSON-POST (using Boost.PropertyTree) and the GET /match/[number] examples, which are most relevant. | ||
See [http_examples.cpp](https://gitlab.com/eidheim/Simple-Web-Server/blob/master/http_examples.cpp) or | ||
[https_examples.cpp](https://gitlab.com/eidheim/Simple-Web-Server/blob/master/https_examples.cpp) for example usage. | ||
The following server resources are setup using regular expressions to match request paths: | ||
* `POST /string` - responds with the posted string. | ||
* `POST /json` - parses the request content as JSON, and responds with some of the parsed values. | ||
* `GET /info` - responds with information extracted from the request. | ||
* `GET /match/([0-9]+)` - matches for instance `/match/123` and responds with the matched number `123`. | ||
* `GET /work` - starts a thread, simulating heavy work, and responds when the work is done. | ||
* `GET` - a special default_resource handler is called when a request path does not match any of the above resources. | ||
This resource responds with the content of files in the `web/`-folder if the request path identifies one of these files. | ||
|
||
### Dependencies | ||
[Documentation](https://eidheim.gitlab.io/Simple-Web-Server/annotated.html) is also available, generated from the master branch. | ||
|
||
* Boost C++ libraries | ||
* For HTTPS: OpenSSL libraries | ||
## Dependencies | ||
|
||
### Compile and run | ||
* Boost.Asio or standalone Asio | ||
* Boost is required to compile the examples | ||
* For HTTPS: OpenSSL libraries | ||
|
||
Installation instructions for the dependencies needed to compile the examples on a selection of platforms can be seen below. | ||
Default build with Boost.Asio is assumed. Turn on CMake option `USE_STANDALONE_ASIO` to instead use standalone Asio. | ||
|
||
### Debian based distributions | ||
|
||
```sh | ||
sudo apt-get install libssl-dev libboost-filesystem-dev libboost-thread-dev | ||
``` | ||
|
||
### Arch Linux based distributions | ||
|
||
```sh | ||
sudo pacman -S boost | ||
``` | ||
|
||
### MacOS | ||
|
||
```sh | ||
brew install openssl boost | ||
``` | ||
|
||
## Compile and run | ||
|
||
Compile with a C++11 compliant compiler: | ||
```sh | ||
mkdir build | ||
cd build | ||
cmake .. | ||
make | ||
cd .. | ||
cmake -H. -Bbuild | ||
cmake --build build | ||
``` | ||
|
||
#### HTTP | ||
### HTTP | ||
|
||
Run the server and client examples: `./build/http_examples` | ||
|
||
Direct your favorite browser to for instance http://localhost:8080/ | ||
|
||
#### HTTPS | ||
### HTTPS | ||
|
||
Before running the server, an RSA private key (server.key) and an SSL certificate (server.crt) must be created. Follow, for instance, the instructions given here (for a self-signed certificate): http://www.akadia.com/services/ssh_test_certificate.html | ||
Before running the server, an RSA private key (server.key) and an SSL certificate (server.crt) must be created. | ||
|
||
Run the server and client examples: `./build/https_examples` | ||
|
||
Direct your favorite browser to for instance https://localhost:8080/ | ||
|
||
## Contributing | ||
|
||
Contributions are welcome, either by creating an issue or a merge request. | ||
However, before you create a new issue or merge request, please search for previous similar issues or requests. | ||
A response will normally be given within a few days. |
112 changes: 112 additions & 0 deletions
112
third_party/Simple-web-server/repo/asio_compatibility.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#ifndef SIMPLE_WEB_ASIO_COMPATIBILITY_HPP | ||
#define SIMPLE_WEB_ASIO_COMPATIBILITY_HPP | ||
|
||
#include <memory> | ||
|
||
#ifdef ASIO_STANDALONE | ||
#include <asio.hpp> | ||
#include <asio/steady_timer.hpp> | ||
namespace SimpleWeb { | ||
namespace error = asio::error; | ||
using error_code = std::error_code; | ||
using errc = std::errc; | ||
using system_error = std::system_error; | ||
namespace make_error_code = std; | ||
} // namespace SimpleWeb | ||
#else | ||
#include <boost/asio.hpp> | ||
#include <boost/asio/steady_timer.hpp> | ||
namespace SimpleWeb { | ||
namespace asio = boost::asio; | ||
namespace error = asio::error; | ||
using error_code = boost::system::error_code; | ||
namespace errc = boost::system::errc; | ||
using system_error = boost::system::system_error; | ||
namespace make_error_code = boost::system::errc; | ||
} // namespace SimpleWeb | ||
#endif | ||
|
||
namespace SimpleWeb { | ||
#if(ASIO_STANDALONE && ASIO_VERSION >= 101300) || BOOST_ASIO_VERSION >= 101300 | ||
using io_context = asio::io_context; | ||
using resolver_results = asio::ip::tcp::resolver::results_type; | ||
using async_connect_endpoint = asio::ip::tcp::endpoint; | ||
|
||
#if(ASIO_STANDALONE && ASIO_VERSION >= 101800) || BOOST_ASIO_VERSION >= 101800 | ||
using strand = asio::strand<asio::any_io_executor>; | ||
#else | ||
using strand = asio::strand<asio::executor>; | ||
#endif | ||
|
||
template <typename handler_type> | ||
inline void post(io_context &context, handler_type &&handler) { | ||
asio::post(context, std::forward<handler_type>(handler)); | ||
} | ||
inline void restart(io_context &context) noexcept { | ||
context.restart(); | ||
} | ||
inline asio::ip::address make_address(const std::string &str) noexcept { | ||
return asio::ip::make_address(str); | ||
} | ||
template <typename socket_type, typename duration_type> | ||
inline std::unique_ptr<asio::steady_timer> make_steady_timer(socket_type &socket, std::chrono::duration<duration_type> duration) { | ||
return std::unique_ptr<asio::steady_timer>(new asio::steady_timer(socket.get_executor(), duration)); | ||
} | ||
template <typename handler_type> | ||
inline void async_resolve(asio::ip::tcp::resolver &resolver, const std::pair<std::string, std::string> &host_port, handler_type &&handler) { | ||
resolver.async_resolve(host_port.first, host_port.second, std::forward<handler_type>(handler)); | ||
} | ||
inline asio::executor_work_guard<io_context::executor_type> make_work_guard(io_context &context) { | ||
return asio::make_work_guard(context); | ||
} | ||
template <typename socket_type> | ||
inline asio::basic_socket<asio::ip::tcp>::executor_type get_executor(socket_type &socket) { | ||
return socket.get_executor(); | ||
} | ||
template <typename execution_context, typename handler_type> | ||
inline asio::executor_binder<typename asio::decay<handler_type>::type, typename execution_context::executor_type> bind_executor(strand &strand, handler_type &&handler) { | ||
return asio::bind_executor(strand, std::forward<handler_type>(handler)); | ||
} | ||
#else | ||
using io_context = asio::io_service; | ||
using resolver_results = asio::ip::tcp::resolver::iterator; | ||
using async_connect_endpoint = asio::ip::tcp::resolver::iterator; | ||
using strand = asio::io_service::strand; | ||
|
||
template <typename handler_type> | ||
inline void post(io_context &context, handler_type &&handler) { | ||
context.post(std::forward<handler_type>(handler)); | ||
} | ||
template <typename handler_type> | ||
inline void post(strand &strand, handler_type &&handler) { | ||
strand.post(std::forward<handler_type>(handler)); | ||
} | ||
inline void restart(io_context &context) noexcept { | ||
context.reset(); | ||
} | ||
inline asio::ip::address make_address(const std::string &str) noexcept { | ||
return asio::ip::address::from_string(str); | ||
} | ||
template <typename socket_type, typename duration_type> | ||
inline std::unique_ptr<asio::steady_timer> make_steady_timer(socket_type &socket, std::chrono::duration<duration_type> duration) { | ||
return std::unique_ptr<asio::steady_timer>(new asio::steady_timer(socket.get_io_service(), duration)); | ||
} | ||
template <typename handler_type> | ||
inline void async_resolve(asio::ip::tcp::resolver &resolver, const std::pair<std::string, std::string> &host_port, handler_type &&handler) { | ||
resolver.async_resolve(asio::ip::tcp::resolver::query(host_port.first, host_port.second), std::forward<handler_type>(handler)); | ||
} | ||
inline io_context::work make_work_guard(io_context &context) { | ||
return io_context::work(context); | ||
} | ||
template <typename socket_type> | ||
inline io_context &get_executor(socket_type &socket) { | ||
return socket.get_io_service(); | ||
} | ||
template <typename handler_type> | ||
inline asio::detail::wrapped_handler<strand, handler_type, asio::detail::is_continuation_if_running> bind_executor(strand &strand, handler_type &&handler) { | ||
return strand.wrap(std::forward<handler_type>(handler)); | ||
} | ||
#endif | ||
} // namespace SimpleWeb | ||
|
||
#endif /* SIMPLE_WEB_ASIO_COMPATIBILITY_HPP */ |
Oops, something went wrong.