PeanutButter
|
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...
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< RequestLogItem > | RequestLogAction [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. |
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.
Guid PeanutButter.SimpleHTTPServer.IHttpServer.AddDocumentHandler | ( | Func< HttpProcessor, Stream, string > | handler | ) |
Adds a handler to serve a text document, with (limited) automatic content-type detection.
handler |
Implemented in PeanutButter.SimpleHTTPServer.HttpServer.
Guid PeanutButter.SimpleHTTPServer.IHttpServer.AddFileHandler | ( | Func< HttpProcessor, Stream, byte[]> | handler, |
string | contentType = HttpConstants.MimeTypes.BYTES ) |
Adds a handler for providing a file download.
handler | |
contentType |
Implemented in PeanutButter.SimpleHTTPServer.HttpServer.
Guid PeanutButter.SimpleHTTPServer.IHttpServer.AddHandler | ( | Func< HttpProcessor, Stream, HttpServerPipelineResult > | handler | ) |
Adds a handler to the pipeline.
handler |
Implemented in PeanutButter.SimpleHTTPServer.HttpServer.
Guid PeanutButter.SimpleHTTPServer.IHttpServer.AddHtmlDocumentHandler | ( | Func< HttpProcessor, Stream, string > | handler | ) |
Specifically add a handler to serve an HTML document.
handler |
Implemented in PeanutButter.SimpleHTTPServer.HttpServer.
Guid PeanutButter.SimpleHTTPServer.IHttpServer.AddJsonDocumentHandler | ( | Func< HttpProcessor, Stream, object > | handler | ) |
Specifically add a handler to serve a JSON document.
handler |
Implemented in PeanutButter.SimpleHTTPServer.HttpServer.
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.
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.
queryPath | Absolute path to serve the document for |
doc | XDocument to serve |
method | Which http method to respond to |
Implemented in PeanutButter.SimpleHTTPServer.HttpServer.
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.
queryPath | Absolute path to serve the document for |
docFactory | Factory function to get the document contents |
method | Which http method to respond to |
Implemented in PeanutButter.SimpleHTTPServer.HttpServer.
void PeanutButter.SimpleHTTPServer.IHttpServer.ServeDocument | ( | string | queryPath, |
string | doc, | ||
HttpMethods | method = HttpMethods.Any ) |
Serves an XDocument from the provided path, for the provided method.
queryPath | Absolute path to serve the document for |
doc | XDocument to serve |
method | Which http method to respond to |
Implemented in PeanutButter.SimpleHTTPServer.HttpServer.
void PeanutButter.SimpleHTTPServer.IHttpServer.ServeDocument | ( | string | queryPath, |
XDocument | doc, | ||
HttpMethods | method = HttpMethods.Any ) |
Serves an XDocument from the provided path, for the provided method.
queryPath | Absolute path to serve the document for |
doc | XDocument to serve |
method | Which http method to respond to |
Implemented in PeanutButter.SimpleHTTPServer.HttpServer.
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)
path | Absolute path matched for this file |
data | Data to provide |
contentType | Content type of the data |
Implemented in PeanutButter.SimpleHTTPServer.HttpServer.
Guid PeanutButter.SimpleHTTPServer.IHttpServer.ServeFile | ( | string | path, |
Func< byte[]> | dataFactory, | ||
string | contentType = HttpConstants.MimeTypes.BYTES ) |
Serves a file via a factory Func.
path | Absolute path matched for this file |
dataFactory | Factory for the data |
contentType | Content type |
Implemented in PeanutButter.SimpleHTTPServer.HttpServer.
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.
path | Absolute path matched for this document |
dataFactory | Factory function returning any object which will be serialized into JSON for you |
method | Which http method to respond to |
Implemented in PeanutButter.SimpleHTTPServer.HttpServer.
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.
path | Absolute path matched for this document |
data | Any object which will be serialized into JSON for you |
method | Which http method to respond to |
Implemented in PeanutButter.SimpleHTTPServer.HttpServer.