C# Class HttpServer.WebServer

HTTP server with regular expression path matching, client and server SSL certificates, and a simplified request callback
显示文件 Open project: 3di/3di-viewer-rei-libs Class Usage Examples

Public Methods

Method Description
AddHandler ( HttpRequestHandler handler ) : void

Add a request handler

AddHandler ( string method, string contentType, string path, HttpRequestCallback callback ) : void

Add a request handler

RemoveHandler ( HttpRequestHandler handler ) : void

Remove a request handler

Set404Handler ( HttpRequestCallback callback ) : void

Set a callback to override the default 404 (Not Found) response

Start ( ) : void

Start the server

Stop ( ) : void

Stop the server

WebServer ( IPAddress address, int port ) : System

Initialize the server in HTTP mode

WebServer ( IPAddress address, int port, X509Certificate certificate, X509Certificate rootCA, bool requireClientCerts ) : System

Initialize the server in HTTPS (TLS 1.0) mode

Private Methods

Method Description
FireRequestCallback ( IHttpClientContext client, IHttpRequest request, IHttpResponse response, HttpRequestCallback callback ) : void
RequestHandler ( IHttpClientContext client, IHttpRequest request ) : void

Method Details

AddHandler() public method

Add a request handler
public AddHandler ( HttpRequestHandler handler ) : void
handler HttpRequestHandler Request handler to add
return void

AddHandler() public method

Add a request handler
public AddHandler ( string method, string contentType, string path, HttpRequestCallback callback ) : void
method string HTTP verb to match, or null to skip verb matching
contentType string Content-Type header to match, or null to skip Content-Type matching
path string Request URI path regular expression to match, or null to skip URI path matching
callback HttpRequestCallback Callback to fire when an incoming request matches the given pattern
return void

RemoveHandler() public method

Remove a request handler
public RemoveHandler ( HttpRequestHandler handler ) : void
handler HttpRequestHandler Request handler to remove
return void

Set404Handler() public method

Set a callback to override the default 404 (Not Found) response
public Set404Handler ( HttpRequestCallback callback ) : void
callback HttpRequestCallback Callback that will be fired when an unhandled /// request is received, or null to reset to the default handler
return void

Start() public method

Start the server
public Start ( ) : void
return void

Stop() public method

Stop the server
public Stop ( ) : void
return void

WebServer() public method

Initialize the server in HTTP mode
public WebServer ( IPAddress address, int port ) : System
address System.Net.IPAddress IP address to bind to
port int Port number to bind to
return System

WebServer() public method

Initialize the server in HTTPS (TLS 1.0) mode
public WebServer ( IPAddress address, int port, X509Certificate certificate, X509Certificate rootCA, bool requireClientCerts ) : System
address System.Net.IPAddress IP address to bind to
port int Port number to bind to
certificate System.Security.Cryptography.X509Certificates.X509Certificate X.509 server certificate for SSL
rootCA System.Security.Cryptography.X509Certificates.X509Certificate X.509 certificate for the root certificate authority /// that signed the server certificate and/or any client certificates
requireClientCerts bool True if client SSL certificates are /// required, otherwise false
return System