PeanutButter
Loading...
Searching...
No Matches
PeanutButter.SimpleHTTPServer.IHttpServer Interface Reference

Provides a simple way to run an in-memory http server situations like testing or where a small, very simple http server might be useful. More...

Inheritance diagram for PeanutButter.SimpleHTTPServer.IHttpServer:
PeanutButter.SimpleHTTPServer.IHttpServerBase PeanutButter.SimpleHTTPServer.HttpServer

Public Member Functions

Guid AddHandler (Func< HttpProcessor, Stream, HttpServerPipelineResult > handler)
 Adds a handler to the pipeline.
Guid AddFileHandler (Func< HttpProcessor, Stream, byte[]> handler, string contentType=HttpConstants.MimeTypes.BYTES)
 Adds a handler for providing a file download.
Guid AddDocumentHandler (Func< HttpProcessor, Stream, string > handler)
 Adds a handler to serve a text document, with (limited) automatic content-type detection.
Guid AddHtmlDocumentHandler (Func< HttpProcessor, Stream, string > handler)
 Specifically add a handler to serve an HTML document.
Guid AddJsonDocumentHandler (Func< HttpProcessor, Stream, object > handler)
 Specifically add a handler to serve a JSON document.
void ServeDocument (string queryPath, XDocument doc, HttpMethods method=HttpMethods.Any)
 Serves an XDocument from the provided path, for the provided method.
void ServeDocument (string queryPath, string doc, HttpMethods method=HttpMethods.Any)
 Serves an XDocument from the provided path, for the provided method.
Guid ServeDocument (string queryPath, Func< string > doc, HttpMethods method=HttpMethods.Any)
 Serves an XDocument from the provided path, for the provided method.
Guid ServeDocument (string queryPath, Func< XDocument > docFactory, HttpMethods method=HttpMethods.Any)
 Serves an XDocument from the provided path, for the provided method.
Guid ServeJsonDocument (string path, object data, HttpMethods method=HttpMethods.Any)
 Serves a JSON document with the provided data at the provided path for the provided method.
Guid ServeJsonDocument (string path, Func< object > dataFactory, HttpMethods method=HttpMethods.Any)
 Serves a JSON document with the provided data at the provided path for the provided method.
Guid ServeFile (string path, byte[] data, string contentType=HttpConstants.MimeTypes.BYTES)
 Serves an arbitrary file from the provided path for the provided content type (defaults to application/octet-stream)
Guid ServeFile (string path, Func< byte[]> dataFactory, string contentType=HttpConstants.MimeTypes.BYTES)
 Serves a file via a factory Func.
void Reset ()
 Clears any registered handlers & log actions so the server can be re-used with completely different logic / handlers.
Public Member Functions inherited from PeanutButter.SimpleHTTPServer.IHttpServerBase
void HandleRequestWithoutBody (HttpProcessor p, string method)
 Handles a request that does not contain a body (as of the HTTP spec).
void HandleRequestWithBody (HttpProcessor p, MemoryStream inputData, string method)
 Handles a general request with a request body.
string GetFullUrlFor (string relativeUrl)
 Resolves the full url to the provided path on the current server.
void Start ()
 Start the server.
void Stop ()
 Stop the server.

Additional Inherited Members

Properties inherited from PeanutButter.SimpleHTTPServer.IHttpServerBase
Action< RequestLogItemRequestLogAction [get, set]
 Log action used for requests.
string BaseUrl [get]
 Provides the base url from which the server serves.
bool Disposed [get]
 Flag: when true, this server has been disposed.
int MaxShutDownTime [get, set]
 Maximum time, in milliseconds, to wait on the listener task when shutting down.
bool LogRandomPortDiscovery [get, set]
 Whether or not to log random port discovery processes.
Action< string > LogAction [get, set]
 Action to employ when logging (defaults to logging to the console)
int Port [get]
 Port which this server has bound to.
bool IsListening [get]
 Flag exposing listening state.
HttpVersion Version [get, set]
 HTTP version reported by the server in responses Note that this does not change behavior of the server, only the exact format of the response.

Detailed Description

Provides a simple way to run an in-memory http server situations like testing or where a small, very simple http server might be useful.

Member Function Documentation

◆ AddDocumentHandler()

Guid PeanutButter.SimpleHTTPServer.IHttpServer.AddDocumentHandler ( Func< HttpProcessor, Stream, string > handler)

Adds a handler to serve a text document, with (limited) automatic content-type detection.

Parameters
handler

Implemented in PeanutButter.SimpleHTTPServer.HttpServer.

◆ AddFileHandler()

Guid PeanutButter.SimpleHTTPServer.IHttpServer.AddFileHandler ( Func< HttpProcessor, Stream, byte[]> handler,
string contentType = HttpConstants.MimeTypes.BYTES )

Adds a handler for providing a file download.

Parameters
handler
contentType

Implemented in PeanutButter.SimpleHTTPServer.HttpServer.

◆ AddHandler()

Guid PeanutButter.SimpleHTTPServer.IHttpServer.AddHandler ( Func< HttpProcessor, Stream, HttpServerPipelineResult > handler)

Adds a handler to the pipeline.

Parameters
handler

Implemented in PeanutButter.SimpleHTTPServer.HttpServer.

◆ AddHtmlDocumentHandler()

Guid PeanutButter.SimpleHTTPServer.IHttpServer.AddHtmlDocumentHandler ( Func< HttpProcessor, Stream, string > handler)

Specifically add a handler to serve an HTML document.

Parameters
handler

Implemented in PeanutButter.SimpleHTTPServer.HttpServer.

◆ AddJsonDocumentHandler()

Guid PeanutButter.SimpleHTTPServer.IHttpServer.AddJsonDocumentHandler ( Func< HttpProcessor, Stream, object > handler)

Specifically add a handler to serve a JSON document.

Parameters
handler

Implemented in PeanutButter.SimpleHTTPServer.HttpServer.

◆ Reset()

void PeanutButter.SimpleHTTPServer.IHttpServer.Reset ( )

Clears any registered handlers & log actions so the server can be re-used with completely different logic / handlers.

Implemented in PeanutButter.SimpleHTTPServer.HttpServer.

◆ ServeDocument() [1/4]

Guid PeanutButter.SimpleHTTPServer.IHttpServer.ServeDocument ( string queryPath,
Func< string > doc,
HttpMethods method = HttpMethods.Any )

Serves an XDocument from the provided path, for the provided method.

Parameters
queryPathAbsolute path to serve the document for
docXDocument to serve
methodWhich http method to respond to

Implemented in PeanutButter.SimpleHTTPServer.HttpServer.

◆ ServeDocument() [2/4]

Guid PeanutButter.SimpleHTTPServer.IHttpServer.ServeDocument ( string queryPath,
Func< XDocument > docFactory,
HttpMethods method = HttpMethods.Any )

Serves an XDocument from the provided path, for the provided method.

Parameters
queryPathAbsolute path to serve the document for
docFactoryFactory function to get the document contents
methodWhich http method to respond to

Implemented in PeanutButter.SimpleHTTPServer.HttpServer.

◆ ServeDocument() [3/4]

void PeanutButter.SimpleHTTPServer.IHttpServer.ServeDocument ( string queryPath,
string doc,
HttpMethods method = HttpMethods.Any )

Serves an XDocument from the provided path, for the provided method.

Parameters
queryPathAbsolute path to serve the document for
docXDocument to serve
methodWhich http method to respond to

Implemented in PeanutButter.SimpleHTTPServer.HttpServer.

◆ ServeDocument() [4/4]

void PeanutButter.SimpleHTTPServer.IHttpServer.ServeDocument ( string queryPath,
XDocument doc,
HttpMethods method = HttpMethods.Any )

Serves an XDocument from the provided path, for the provided method.

Parameters
queryPathAbsolute path to serve the document for
docXDocument to serve
methodWhich http method to respond to

Implemented in PeanutButter.SimpleHTTPServer.HttpServer.

◆ ServeFile() [1/2]

Guid PeanutButter.SimpleHTTPServer.IHttpServer.ServeFile ( string path,
byte[] data,
string contentType = HttpConstants.MimeTypes.BYTES )

Serves an arbitrary file from the provided path for the provided content type (defaults to application/octet-stream)

Parameters
pathAbsolute path matched for this file
dataData to provide
contentTypeContent type of the data

Implemented in PeanutButter.SimpleHTTPServer.HttpServer.

◆ ServeFile() [2/2]

Guid PeanutButter.SimpleHTTPServer.IHttpServer.ServeFile ( string path,
Func< byte[]> dataFactory,
string contentType = HttpConstants.MimeTypes.BYTES )

Serves a file via a factory Func.

Parameters
pathAbsolute path matched for this file
dataFactoryFactory for the data
contentTypeContent type

Implemented in PeanutButter.SimpleHTTPServer.HttpServer.

◆ ServeJsonDocument() [1/2]

Guid PeanutButter.SimpleHTTPServer.IHttpServer.ServeJsonDocument ( string path,
Func< object > dataFactory,
HttpMethods method = HttpMethods.Any )

Serves a JSON document with the provided data at the provided path for the provided method.

Parameters
pathAbsolute path matched for this document
dataFactoryFactory function returning any object which will be serialized into JSON for you
methodWhich http method to respond to

Implemented in PeanutButter.SimpleHTTPServer.HttpServer.

◆ ServeJsonDocument() [2/2]

Guid PeanutButter.SimpleHTTPServer.IHttpServer.ServeJsonDocument ( string path,
object data,
HttpMethods method = HttpMethods.Any )

Serves a JSON document with the provided data at the provided path for the provided method.

Parameters
pathAbsolute path matched for this document
dataAny object which will be serialized into JSON for you
methodWhich http method to respond to

Implemented in PeanutButter.SimpleHTTPServer.HttpServer.


The documentation for this interface was generated from the following file:
  • source/SimpleServers/PeanutButter.SimpleHTTPServer/HttpServer.cs