dot-xx
A personal collection of small C++ modules
Loading...
Searching...
No Matches
dxx::http::Server Class Referenceexport
module dxx.http

A simple HTTP server. More...

Public Types

using DispatcherImmediate = std::function<void(const Request&, Response&)>
 A callback type for requests that return their response immediately.
using DispatcherDelayed
 A callback type for requests that assume ownership over the connection to be processed later.
using Dispatcher = std::variant<DispatcherImmediate, DispatcherDelayed>
 A generalized response callback type.

Public Member Functions

SimpleTask listen_and_wait (const std::string &ip, u16 port)
 Run the server life cycle as a coroutine.
void listen (const std::string &ip, u16 port)
 Run the server life cycle. Self-explanatory.
void request_stop ()
 Interrupt the server listen loop on the next iteration.
void bind (Method method, const std::filesystem::path &path, const Dispatcher &cb)
 Bind a callback to process the request.

Detailed Description

A simple HTTP server.

Member Typedef Documentation

◆ DispatcherDelayed

Initial value:
std::function<
void(
const Request&,
const Response&,
)
>
An awaitable object that allows the handler code to respond to the request at a later point in time.
Definition coro.xx:94
HTTP request structure. Also used for multipart request data.
Definition message.xx:101
Server's response to the client.
Definition message.xx:209

A callback type for requests that assume ownership over the connection to be processed later.

Member Function Documentation

◆ listen()

void dxx::http::Server::listen ( const std::string & ip,
u16 port )

Run the server life cycle. Self-explanatory.

Parameters
ipIP to bind to, uses std::string instead of std::string_view because we want to ensure it is null-terminated (couldn't find it in the man, just to be safe)
portserver port

◆ listen_and_wait()

SimpleTask dxx::http::Server::listen_and_wait ( const std::string & ip,
u16 port )

Run the server life cycle as a coroutine.

Before serving each next connection, is suspends to allow the program to do some other work or to allow to gracefully shut down the server

Parameters
ipIP to bind to, uses std::string instead of std::string_view because we want to ensure it is null-terminated (couldn't find it in the man, just to be safe)
portserver port

The documentation for this class was generated from the following file:
  • /build-llvm-libcpp/_deps/dot-xx-http-src/src/server.xx