Every example is a standalone program built from a single .cpp. To
build the suite locally:
./bootstrap && mkdir build && cd build && ../configure && make
Each binary lands in build/examples/. To verify that an example also
compiles against an installed libhttpserver (the consumer view), run
scripts/verify-installed-examples.sh after make install. To enforce
the structural invariants on hello_world.cpp and shared_state.cpp
(LOC budget, lambda-only form, mutex usage), run
scripts/check-examples.sh.
hello_world.cpp— ten lines, no subclassing, no raw pointers. The canonical "hello world" demo and the PRD §3.4 acceptance fixture for the v2.0 lambda idiom.shared_state.cpp— the canonical example of when the class form is the right shape: anhttp_resourcesubclass that shares astd::mutex- guarded counter betweenrender_getandrender_post.
setting_headers.cpp— attach response headers fluently withwith_header.hello_with_get_arg.cpp— read a query-string parameter fromhttp_request::get_arg.args_processing.cpp— iterate every form/query argument.custom_error.cpp— install customnot_found_handlerandmethod_not_allowed_handlerand letset_allowingrestrict methods on a resource.allowing_disallowing_methods.cpp— narrow a resource to a single HTTP method via the allow mask.url_registration.cpp— exact paths, prefix matches, regex paths, and parametric segments (with optional per-segment regex).handlers.cpp— register distinct lambdas for GET and POST on the same path; the dispatcher composes them.
minimal_file_response.cpp— stream a file from disk.binary_buffer_response.cpp— return a binary buffer (e.g. a PNG).iovec_response_example.cpp— gather a response body from multiple borrowed buffers without copying.pipe_response_example.cpp— stream from a pipe filled by a background thread.empty_response_example.cpp— bodyless responses for DELETE / HEAD.minimal_deferred.cpp— deferred response: the body is produced asynchronously by a callback.deferred_with_accumulator.cpp— deferred response that mutates shared state across calls.
minimal_https.cpp— enable TLS with PEM key/cert files.minimal_https_psk.cpp— TLS with pre-shared keys.basic_authentication.cpp— per-request HTTP Basic auth inside the handler.centralized_authentication.cpp— server-wideauth_handlerandauth_skip_paths.digest_authentication.cpp— per-request HTTP Digest auth viahttp_request::check_digest_auth.client_cert_auth.cpp— mutual TLS with X.509 client certificates. Ships as a documentation artifact; not wired intonoinst_PROGRAMS.
daemon_info.cpp— introspect the running daemon (bound port, listen FD, active connections).external_event_loop.cpp— driveEXTERNAL_SELECTfrom the application's loop viarun_wait.custom_access_log.cpp— server-wide access-log callback.minimal_ip_ban.cpp—block_ip/unblock_ipunder the default ACCEPT policy.turbo_mode.cpp— turbo, suppressed Date header, fastopen queue, listen backlog.service.cpp— the kitchen-sink reference example: CLI args, optional TLS, allrender_*overrides.
benchmark_select.cpp,benchmark_threads.cpp,benchmark_nodelay.cpp— micro-benchmarks. Seetest/v1_baseline/for v1.x reference numbers.
websocket_echo.cpp—websocket_handlersubclass registered viaregister_ws_resourcewithstd::make_unique.
file_upload.cpp,file_upload_with_callback.cpp— multipart upload, GET serves the HTML form and POST processes the parts.
Self-signed certificates can be created using OpenSSL using the following steps:
$ openssl genrsa -des3 -passout pass:x -out server.pass.key 2048
$ openssl rsa -passin pass:x -in server.pass.key -out server.key
$ openssl req -new -key server.key -out server.csr
$ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
On the last step when prompted for a challenge password it can be left empty.
Thanks to https://devcenter.heroku.com/articles/ssl-certificate-self for these instructions.