Skip to content
This repository was archived by the owner on Jun 12, 2018. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: eidheim/Simple-Web-Server
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.4.2
Choose a base ref
...
head repository: eidheim/Simple-Web-Server
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 3,795 additions and 1,205 deletions.
  1. +9 −0 .clang-format
  2. +11 −1 .gitignore
  3. +22 −0 .travis.yml
  4. +58 −33 CMakeLists.txt
  5. +1 −1 LICENSE
  6. +16 −12 README.md
  7. +684 −237 client_http.hpp
  8. +135 −46 client_https.hpp
  9. +227 −0 crypto.hpp
  10. +225 −142 http_examples.cpp
  11. +224 −143 https_examples.cpp
  12. +712 −402 server_http.hpp
  13. +75 −50 server_https.hpp
  14. +167 −0 status_code.hpp
  15. +0 −11 test/CMakeLists.txt
  16. +0 −127 test/parse_test.cpp
  17. +21 −0 tests/CMakeLists.txt
  18. +74 −0 tests/crypto_test.cpp
  19. +454 −0 tests/io_test.cpp
  20. +301 −0 tests/parse_test.cpp
  21. +26 −0 tests/status_code_test.cpp
  22. +353 −0 utility.hpp
9 changes: 9 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
IndentWidth: 2
AccessModifierOffset: -2
UseTab: Never
ColumnLimit: 0
MaxEmptyLinesToKeep: 2
SpaceBeforeParens: Never
BreakBeforeBraces: Custom
BraceWrapping: {BeforeElse: true, BeforeCatch: true}
NamespaceIndentation: All
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -9,8 +9,18 @@ install_manifest.txt
#Additions to https://github.com/github/gitignore/blob/master/CMake.gitignore
Testing
compile_commands.json
.usages_clang

*.crt
*.key

# executables
http_examples
https_examples
parse_test
io_test
parse_test
crypto_test
status_code_test

# Visual Studio 2015/2017 cache/options directory
.vs
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
sudo: required

services:
- docker

script:
- sudo docker run -it -v "$PWD:/repository" eidheim/testing sh -c "
cd /repository && mkdir build && cd build &&
scan-build cmake -DCMAKE_CXX_FLAGS=-Werror .. &&
scan-build --status-bugs make &&
rm -r * &&
CXX=clang++ cmake -DCMAKE_CXX_FLAGS=-Werror .. &&
make &&
rm -r * &&
CXX=g++ cmake -DCMAKE_CXX_FLAGS=-Werror .. &&
make &&
CTEST_OUTPUT_ON_FAILURE=1 make test &&
rm -r * &&
CXX=g++ cmake -DUSE_STANDALONE_ASIO=ON -DCMAKE_CXX_FLAGS=\"-Werror -O3\" .. &&
make &&
CTEST_OUTPUT_ON_FAILURE=1 make test
"
91 changes: 58 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,52 +1,77 @@
cmake_minimum_required (VERSION 2.8)
cmake_minimum_required (VERSION 3.0)

project (Simple-Web-Server)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -Wall")

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
message(FATAL_ERROR "GCC version >=4.8 required.")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3)
message(FATAL_ERROR "Clang version >=3.3 required.")
endif()
elseif (MSVC14) #TODO: What about other MSVC versions?
option(USE_STANDALONE_ASIO "set ON to use standalone Asio instead of Boost.Asio" OFF)
option(BUILD_TESTING "set ON to build library tests" OFF)

if(NOT MSVC)
add_compile_options(-std=c++11 -Wall -Wextra -Wsign-conversion)
else()
message(WARNING "Your compiler (${CMAKE_CXX_COMPILER_ID}) has not been tested on this project. Only Clang and GCC has been tested. Please report any problems at the project page on GitHub.")
add_compile_options(/W1)
endif()

add_library(simple-web-server INTERFACE)

include_directories(.)
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})

find_package(Boost 1.54.0 COMPONENTS regex system thread coroutine context filesystem date_time REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
# 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 USE_STANDALONE_ASIO)
include(CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX(asio.hpp HAVE_ASIO)
if(NOT HAVE_ASIO)
message(FATAL_ERROR "Standalone Asio not found")
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()

if(APPLE)
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
endif()

#TODO: add requirement for version 1.0.1g (can it be done in one line?)
find_package(OpenSSL)

if(OPENSSL_FOUND)
include_directories(${OPENSSL_INCLUDE_DIR})

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})
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})

if(MSYS) #TODO: Is MSYS true when MSVC is true?
target_link_libraries(http_examples ws2_32 wsock32)
target_link_libraries(https_examples ws2_32 wsock32)
# If Simple-Web-Server is not a sub-project:
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(http_examples http_examples.cpp)
target_link_libraries(http_examples simple-web-server)
find_package(Boost 1.53.0 COMPONENTS system thread filesystem REQUIRED)
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()

set(BUILD_TESTING ON)

install(FILES server_http.hpp client_http.hpp server_https.hpp client_https.hpp crypto.hpp utility.hpp status_code.hpp DESTINATION include/simple-web-server)
endif()

enable_testing()
add_subdirectory(test)
if(BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Ole Christian Eidheim
Copyright (c) 2014-2018 Ole Christian Eidheim

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@
**_This project has moved to https://gitlab.com/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

* Thread pool
* 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
* Possibility to flush response to clients synchronously (Server::Response::flush).

###Usage
### Usage

See http_examples.cpp or https_examples.cpp for example usage.

See particularly the JSON-POST (using Boost.PropertyTree) and the GET /match/[number] examples, which are most relevant.

The default_resource includes example use of Server::Response::flush.

### Dependencies

* Boost C++ libraries
* Boost.Asio or standalone Asio
* Boost is required to compile the examples
* For HTTPS: OpenSSL libraries

### Compile and run

Compile with a C++11 compliant compiler:
```
cmake .
```sh
mkdir build
cd build
cmake ..
make
cd ..
```

#### HTTP

Run the server and client examples: `./http_examples`
Run the server and client examples: `./build/http_examples`

Direct your favorite browser to for instance http://localhost:8080/

#### 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

Run the server and client examples: `./https_examples`
Run the server and client examples: `./build/https_examples`

Direct your favorite browser to for instance https://localhost:8080/

Loading