Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
SC::HttpWebServer Struct Reference

Http web server helps statically serves files from a directory. More...

#include <HttpWebServer.h>

Public Member Functions

Result init (StringView directoryToServe)
 Initialize the web server on the given file system directory to serve.
 
Result stopAsync ()
 Release all resources allocated by this web server.
 
void serveFile (HttpRequest &request, HttpResponse &response)
 Serve the file requested by this Http Client on its channel Call this method in response to HttpServer::onRequest to serve a file.
 

Detailed Description

Http web server helps statically serves files from a directory.


It can be used in conjunction with SC::HttpServer, by calling SC::HttpWebServer::serveFile inside the SC::HttpServer::onRequest callback to statically serve files.

See also
SC::HttpServer
// Creates an HttpServer that serves files from application root directory
HttpServer server;
HttpWebServer webServer;
SC_TEST_EXPECT(server.start(eventLoop, 16, "127.0.0.1", 8090));
SC_TEST_EXPECT(webServer.init(report.applicationRootDirectory));
server.onRequest = [&](HttpRequest& req, HttpResponse& res) { webServer.serveFile(req, res); };

Member Function Documentation

◆ init()

Result SC::HttpWebServer::init ( StringView directoryToServe)

Initialize the web server on the given file system directory to serve.

◆ serveFile()

void SC::HttpWebServer::serveFile ( HttpRequest & request,
HttpResponse & response )

Serve the file requested by this Http Client on its channel Call this method in response to HttpServer::onRequest to serve a file.

◆ stopAsync()

Result SC::HttpWebServer::stopAsync ( )

Release all resources allocated by this web server.


The documentation for this struct was generated from the following file: