Micro http server and client written in C++

Overview

Build Status Coverity Status

httpp

Micro http server and client written in C++

The motivation behind this little piece of code is to provide a really simple, yet efficient HTTP server to implement in-app webservice easily.

The HttpServer will take care of the connections, request parsing and response generation. The handler on another hand is reponsible for implementing the "logic" behind the service. For example, the server has a very limited knowledge of the HTTP protocol…

The HttpClient has been implemented using curl and its multi interface.

See an exampe here or here.

REQUIREMENTS

Boost is required, version >= 1.54 and libcurl. HTTPP has a dependency on CommonPP since the version 0.7. CommonPP has a dependency on Boost and TBB. The TBB dependency will become optional.

A C++14 compliant compiler is also required.

BUILD

$> mkdir -p $HTTPP_PATH && cd $HTTPP_PATH
$> git clone https://github.com/daedric/httpp.git .
$> git submodule update --init
$> mkdir -p $HTTPP_BUILD_PATH && cd $HTTPP_BUILD_PATH
$> cmake $HTTPP_PATH
$> make

A debian package can be generated running:

$> make package

To build tests:

$> cmake $HTTPP_PATH -DBUILD_TESTS=ON

Examples:

$> cmake $HTTPP_PATH -DBUILD_EXAMPLES=ON

To build the shared library version:

$> cmake $HTTPP_PATH -DBUILD_SHARED_LIBS=ON

By default the build is in release mode, to change that you can:

$> cmake $HTTPP_PATH -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=DEBUG

The compilation and tests have been run on Mac OS X (curl and openssl from homebrew seems to be required to have all tests passing, I don't know why yet), and GNU/Linux distro (Ubuntu, ArchLinux).

Current stable

The current stable is the v0.7.0. There are still some things missing:

  • Optional commonpp dependencies;
  • Probes in the server.

Design choices

This section is only about the server.

Since the 0.7 version, HTTPP is trying to allocate as few memory as possible. Each connection is associated with some buffers that are never released to the system. This this might create a memory overhead, this allows to achieve a better performance.

The HTTP parser has been ported to Ragel to generate a faster parser than the one based on stream. I found out after having finished that Mongel did the same way before me, so I might try to import it if it makes sense.

At the same time, the parser avoids as much as possible copies by using boost::string_ref.

One of the reason is that HTTPP is designed to be used in a REST server exposing an API and developed for RTB platform, each request is relatively similar to the previous one in size. Second reason, it makes everything simpler (no buffer management, no release, no cache needed, etc).

Performances

This section is only about the server.

On a Dell 3800 with an Intel(R) Core(TM) i7-4702HQ CPU @ 2.20GHz, I was able to achieve between 160K and 180K request per second with the ping program (against 70 to 90K with the 0.6.2) and ab with -k -c 8 options on the same machine, this means that HTTPP overhead is about 5 to 6 micro seconds.

With a slightly more complex server that decoded the request, performed some string manipulation and returned a predefined json payload, we have seen approximately 220K requests per second on identical hardware, using wrk to drive the load testing. 5 threads were allocated to the httpp server, and 3 to wrk (with 500 concurrent connections).

This is scaling as threads are added but I don't have enough proper machine to do a real benchmark.

Comments
  • Case insensitive lookup for SortedVectorKP

    Case insensitive lookup for SortedVectorKP

    I was thinking of having two overloads in the comparator vs a template, since the implementation assumes either std::string or boost::string_ref types, but it would be identical code and I doubt you are going to add another type for the keys.

    opened by mlove-au 4
  • Fix header in ReadWholeRequest.hpp

    Fix header in ReadWholeRequest.hpp

    Hi @daedric :) I experienced a compiler error on OSX where the <vector> header was missing. Also removed the unused <cstring> header. Isn't <algorithm> unused as well?

    opened by 0x7f 4
  • Server-side Chunked Transfer Encoding

    Server-side Chunked Transfer Encoding

    hi @daedric,

    This pull-request adds chunked Transfer Encoding on the server side only. It currently doesn't allow sending of additional headers during the response, as I didn't think that would be an immediate use-case opposed to streaming just the content.

    I've also removed the minor_, and major_ version members from the Response class as they were not being exposed/used in client code. I can't think of a client that would require HTTP 1.0 these days, but it would be easy to add back in if required.

    Cheers Matt

    opened by mlove-au 4
  • Do not destroy connection when endpoint cannot be found

    Do not destroy connection when endpoint cannot be found

    A failure in retrieving the remote endpoint causes httpp to destroy the connection, which makes the connection invalid and causes use after free errors in downstream code. Prevent this by just returning the error message.

    @daedric Nice greetings! And yes: We are still using this library.

    opened by dohse 1
  • Improve performance of Response::setBody

    Improve performance of Response::setBody

    We should probably checkin some better performance test application and scripts. I'll need to modify what I tested this change against, since it's very specific to the task I need. Also I'd suggest using wrk for your perf tests, wrk seems to give better throughput than ab, esp when using on a single machine.

    opened by mlove-au 1
  • Allow using external ThreadPool in HttpServer.

    Allow using external ThreadPool in HttpServer.

    This way, one has direct access to the main thread pool and can schedule additional tasks.

    Note: I chose to implement it so that the HttpServer owns the ThreadPool in respect to starting/stopping it (not memory-management-wise) as it was the least intrusive implementation.

    opened by 0x7f 1
  • Add Connection::read() which read a fixed sized body into a given buffer

    Add Connection::read() which read a fixed sized body into a given buffer

    Also migrate ReadWholeRequest to use it. Connection::readBody is dedicated when one wants to read a not-fixed size request or if one does not want to keep a big request in memory.

    opened by daedric 0
  • Fix timeouts when using keepalive in apache bench.

    Fix timeouts when using keepalive in apache bench.

    Set Connection: Keep-Alive header in response when keepalive connection requested. According to HTTP 1.1 it is not required, because keepalive is the default, but ab does not comply to the standard here. So lets set it explicitly.

    opened by 0x7f 0
  • Add support for WebDAV http methods

    Add support for WebDAV http methods

    I just wanted to do a small WebDAV test based on httpp. Found out that the methods defined in the WebDAV http extension are not supported by httpp atm, so I added them. Don't know whether you want them in the code base in the first place?

    For details about the methods see: http://www.webdav.org/specs/rfc2518.html https://en.wikipedia.org/wiki/WebDAV

    opened by 0x7f 2
  • Port to windows

    Port to windows

    This patch makes httpp compile on Windows 10 with Visual Studio 2017 Community edition (VC 14.0).

    The according commonpp patch can be found here https://github.com/daedric/commonpp/pull/7. The same issue about static linking of TBB and HWLOC applies to this as well.

    opened by 0x7f 4
Owner
Thomas Sanchez
Thomas Sanchez
Pushpin is a reverse proxy server written in C++ that makes it easy to implement WebSocket, HTTP streaming, and HTTP long-polling services.

Pushpin is a reverse proxy server written in C++ that makes it easy to implement WebSocket, HTTP streaming, and HTTP long-polling services. The project is unique among realtime push solutions in that it is designed to address the needs of API creators. Pushpin is transparent to clients and integrates easily into an API stack.

Fanout 3.2k Jan 2, 2023
LAppS - Lua Application Server for micro-services with default communication over WebSockets. The fastest and most vertically scalable WebSockets server implementation ever. Low latency C++ <-> Lua stack roundtrip.

LAppS - Lua Application Server This is an attempt to provide very easy to use Lua Application Server working over WebSockets protocol (RFC 6455). LApp

null 48 Oct 13, 2022
Gromox - Groupware server backend with MAPI/HTTP, RPC/HTTP, IMAP, POP3 and PHP-MAPI support for grommunio

Gromox is the central groupware server component of grommunio. It is capable of serving as a replacement for Microsoft Exchange and compatibles. Conne

grommunio 139 Dec 26, 2022
A collection of C++ HTTP libraries including an easy to use HTTP server.

Proxygen: Facebook's C++ HTTP Libraries This project comprises the core C++ HTTP abstractions used at Facebook. Internally, it is used as the basis fo

Facebook 7.7k Jan 4, 2023
A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio.

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.

Ole Christian Eidheim 2.4k Dec 23, 2022
Ultra fast and low latency asynchronous socket server & client C++ library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution

CppServer Ultra fast and low latency asynchronous socket server & client C++ library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and

Ivan Shynkarenka 958 Jan 3, 2023
websocket and http client and server library, coming with ws, a command line swiss army knife utility

Hello world IXWebSocket is a C++ library for WebSocket client and server development. It has minimal dependencies (no boost), is very simple to use an

Machine Zone, Inc. 369 Jan 5, 2023
A C++ header-only HTTP/HTTPS server and client library

cpp-httplib A C++11 single-file header-only cross platform HTTP/HTTPS library. It's extremely easy to setup. Just include the httplib.h file in your c

null 8.3k Dec 31, 2022
tiny HTTP parser written in C (used in HTTP::Parser::XS et al.)

PicoHTTPParser Copyright (c) 2009-2014 Kazuho Oku, Tokuhiro Matsuno, Daisuke Murase, Shigeo Mitsunari PicoHTTPParser is a tiny, primitive, fast HTTP r

H2O 1.6k Jan 1, 2023
A project designed for the esp8266 D1 Mini or the esp8266 D1 Mini PRO to provide a wifi http server and dns server.

PS4 Server 9.00 This is a project designed for the esp8266 D1 Mini or the esp8266 D1 Mini PRO to provide a wifi http server and dns server. this is fo

null 14 Nov 28, 2022
Minimalistic server (written in C) and a python3 client to allow calling C function on a remote host

Minimalistic server (written in C) and a python3 client to allow calling C function on a remote host

null 18 Dec 30, 2022
cuehttp is a modern c++ middleware framework for http(http/https)/websocket(ws/wss).

cuehttp 简介 cuehttp是一个使用Modern C++(C++17)编写的跨平台、高性能、易用的HTTP/WebSocket框架。基于中间件模式可以方便、高效、优雅的增加功能。cuehttp基于boost.asio开发,使用picohttpparser进行HTTP协议解析。内部依赖了nl

xcyl 29 Dec 17, 2022
A network library for client/server games written in C++

yojimbo yojimbo is a network library for client/server games written in C++. It's designed around the networking requirements of competitive multiplay

The Network Protocol Company 2.2k Jan 1, 2023
Simple Tcp Chat Client / Server written in C++

What this TcpXat TcpXat Is A Simple Tcp Chat Setup TcpXat sudo apt install make;make client;make serv;echo "done by FuryM3m0ry"; How To Run TcpXat Ter

sami 1 Dec 28, 2021
Cross-platform, efficient, customizable, and robust asynchronous HTTP/WebSocket server C++14 library with the right balance between performance and ease of use

What Is RESTinio? RESTinio is a header-only C++14 library that gives you an embedded HTTP/Websocket server. It is based on standalone version of ASIO

Stiffstream 924 Jan 6, 2023
Phorklift is an HTTP server and proxy daemon, with clear, powerful and dynamic configuration.

Phorklift is an HTTP server and proxy daemon, with clear, powerful and dynamic configuration.

null 43 Mar 1, 2022
A cross-platform HTTP client library with a focus on usability and speed

EasyHttp A cross-platform HTTP client library with a focus on usability and speed. Under its hood, EasyHttp uses POCO C++ Libraries and derives many o

Sony 148 Dec 30, 2022
Graphical small-internet client for windows, linux, MacOS X and BSDs. Supports gemini, http, https, gopher, finger.

Graphical small-internet client for windows, linux, MacOS X and BSDs. Supports gemini, http, https, gopher, finger.

Felix Queißner 569 Dec 30, 2022
Neon - neon - an HTTP/1.1 and WebDAV client library with a C API

neon neon is an HTTP and WebDAV client library, with a C language API. Mailing list: n[email protected] || Web site: https://notroj.github.io/n

Joe Orton 88 Dec 31, 2022