Sane C++ Libraries
C++ Platform Abstraction Libraries
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
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. More...
 
Result stopAsync ()
 Release all resources allocated by this web server. More...
 
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. More...
 

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); };
#define SC_TEST_EXPECT(e)
Records a test expectation (eventually aborting or breaking o n failed test)
Definition: Testing.h:116

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: