|
PeanutButter
|
Provides the simple HTTP server you may use ad-hoc. More...
Public Member Functions | |||||||
| HttpServer (int port, bool autoStart, Action< string > logAction) | |||||||
| HttpServer (int port, Action< string > logAction) | |||||||
| Constructs an HttpServer listening on the configured port with the given logAction. | |||||||
| HttpServer () | |||||||
| Constructs an HttpServer with autoStart true and no logAction. | |||||||
| HttpServer (Action< string > logAction) | |||||||
| Constructs an HttpServer with autoStart true and provided logAction. | |||||||
| HttpServer (bool autoStart) | |||||||
| Constructs an HttpServer based on passed in autoStart, with no logAction. | |||||||
| HttpServer (bool autoStart, Action< string > logAction) | |||||||
| Constructs an HttpServer. | |||||||
| 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. | |||||||
| override void | HandleRequestWithoutBody (HttpProcessor p, string method) | ||||||
Handles a request that does not contain a body (as of the HTTP spec).
| |||||||
| override void | HandleRequestWithBody (HttpProcessor p, MemoryStream inputData, string method) | ||||||
Handles a general request with a request body.
| |||||||
| 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. | |||||||
| bool | RemoveHandler (Guid identifier) | ||||||
| Removes a previously-registered handler by it's id. | |||||||
| Public Member Functions inherited from PeanutButter.SimpleHTTPServer.HttpServerBase | |||||||
| 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.
| |||||||
| Public Member Functions inherited from PeanutButter.SimpleTcpServer.TcpServer | |||||||
| void | Start () | ||||||
| Start the server. | |||||||
| void | Stop () | ||||||
| Stop the server. | |||||||
| virtual void | Dispose () | ||||||
| Disposes the server (stops it if it is running) | |||||||
| Public Member Functions inherited from PeanutButter.SimpleHTTPServer.IHttpServerBase | |||||||
| void | Start () | ||||||
| Start the server. | |||||||
| void | Stop () | ||||||
| Stop the server. | |||||||
Protected Member Functions | |
| override void | Init () |
| Protected Member Functions inherited from PeanutButter.SimpleHTTPServer.HttpServerBase | |
| HttpServerBase (int port) | |
| HttpServerBase () | |
| override IProcessor | CreateProcessorFor (TcpClient client) |
| Protected Member Functions inherited from PeanutButter.SimpleTcpServer.TcpServer | |
| TcpServer (int minPort=5000, int maxPort=32000) | |
| Construct the server with a random port within the provided range. | |
| TcpServer (int port) | |
| Construct the server with the explicitly-provided port. | |
| void | Init () |
| Override in derived classes: this initializes the server system. | |
| void | Log (string message, params object[] parameters) |
| Provides a convenience logging mechanism which outputs via the established LogAction. | |
| IProcessor | CreateProcessorFor (TcpClient client) |
| Create a processor for a particular TCP client. | |
| virtual int | NextRandomPort () |
| Guesses the next random port to attempt to bind to. | |
Properties | |
| int | HandlerCount [get] |
| Used in debug display. | |
| Properties inherited from PeanutButter.SimpleHTTPServer.HttpServerBase | |
| Action< RequestLogItem > | RequestLogAction = null [get, set] |
| Log action used for requests. | |
| 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. | |
| string | BaseUrl [get] |
| Provides the base url from which the server serves. | |
| Properties inherited from PeanutButter.SimpleTcpServer.TcpServer | |
| bool | Disposed [get] |
| Flag: when true, this server has been disposed. | |
| int | MaxShutDownTime = 1000 [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 = Console.WriteLine [get, set] |
| Action to employ when logging (defaults to logging to the console) | |
| int | Port [get, protected set] |
| Port which this server has bound to. | |
| bool | IsListening [get] |
| Flag exposing listening state. | |
| Properties inherited from PeanutButter.SimpleHTTPServer.IHttpServerBase | |
| 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. | |
Provides the simple HTTP server you may use ad-hoc.
| PeanutButter.SimpleHTTPServer.HttpServer.HttpServer | ( | int | port, |
| Action< string > | logAction ) |
Constructs an HttpServer listening on the configured port with the given logAction.
| port | |
| logAction |
| PeanutButter.SimpleHTTPServer.HttpServer.HttpServer | ( | Action< string > | logAction | ) |
Constructs an HttpServer with autoStart true and provided logAction.
| logAction | Action to log messages with |
| PeanutButter.SimpleHTTPServer.HttpServer.HttpServer | ( | bool | autoStart | ) |
Constructs an HttpServer based on passed in autoStart, with no logAction.
| autoStart | Start immediately? |
| PeanutButter.SimpleHTTPServer.HttpServer.HttpServer | ( | bool | autoStart, |
| Action< string > | logAction ) |
Constructs an HttpServer.
| autoStart | Start immediately? |
| logAction | Action to log messages |
| Guid PeanutButter.SimpleHTTPServer.HttpServer.AddDocumentHandler | ( | Func< HttpProcessor, Stream, string > | handler | ) |
Adds a handler to serve a text document, with (limited) automatic content-type detection.
| handler |
Implements PeanutButter.SimpleHTTPServer.IHttpServer.
| Guid PeanutButter.SimpleHTTPServer.HttpServer.AddFileHandler | ( | Func< HttpProcessor, Stream, byte[]> | handler, |
| string | contentType = HttpConstants::MimeTypes::BYTES ) |
Adds a handler for providing a file download.
| handler | |
| contentType |
Implements PeanutButter.SimpleHTTPServer.IHttpServer.
| Guid PeanutButter.SimpleHTTPServer.HttpServer.AddHandler | ( | Func< HttpProcessor, Stream, HttpServerPipelineResult > | handler | ) |
Adds a handler to the pipeline.
| handler |
Implements PeanutButter.SimpleHTTPServer.IHttpServer.
| Guid PeanutButter.SimpleHTTPServer.HttpServer.AddHtmlDocumentHandler | ( | Func< HttpProcessor, Stream, string > | handler | ) |
Specifically add a handler to serve an HTML document.
| handler |
Implements PeanutButter.SimpleHTTPServer.IHttpServer.
| Guid PeanutButter.SimpleHTTPServer.HttpServer.AddJsonDocumentHandler | ( | Func< HttpProcessor, Stream, object > | handler | ) |
Specifically add a handler to serve a JSON document.
| handler |
Implements PeanutButter.SimpleHTTPServer.IHttpServer.
| override void PeanutButter.SimpleHTTPServer.HttpServer.HandleRequestWithBody | ( | HttpProcessor | p, |
| MemoryStream | inputData, | ||
| string | method ) |
Handles a general request with a request body.
| p | The HTTP processor. |
| inputData | The stream to read the request body from. |
| method | The HTTP method. |
Implements PeanutButter.SimpleHTTPServer.IHttpServerBase.
| override void PeanutButter.SimpleHTTPServer.HttpServer.HandleRequestWithoutBody | ( | HttpProcessor | p, |
| string | method ) |
Handles a request that does not contain a body (as of the HTTP spec).
| p | The HTTP processor. |
| method | The HTTP method. |
Implements PeanutButter.SimpleHTTPServer.IHttpServerBase.
| bool PeanutButter.SimpleHTTPServer.HttpServer.RemoveHandler | ( | Guid | identifier | ) |
Removes a previously-registered handler by it's id.
| identifier |
| NotImplementedException |
| void PeanutButter.SimpleHTTPServer.HttpServer.Reset | ( | ) |
Clears any registered handlers & log actions so the server can be re-used with completely different logic / handlers.
Implements PeanutButter.SimpleHTTPServer.IHttpServer.
| Guid PeanutButter.SimpleHTTPServer.HttpServer.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 |
Implements PeanutButter.SimpleHTTPServer.IHttpServer.
| Guid PeanutButter.SimpleHTTPServer.HttpServer.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 |
Implements PeanutButter.SimpleHTTPServer.IHttpServer.
| void PeanutButter.SimpleHTTPServer.HttpServer.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 |
Implements PeanutButter.SimpleHTTPServer.IHttpServer.
| void PeanutButter.SimpleHTTPServer.HttpServer.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 |
Implements PeanutButter.SimpleHTTPServer.IHttpServer.
| Guid PeanutButter.SimpleHTTPServer.HttpServer.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 |
Implements PeanutButter.SimpleHTTPServer.IHttpServer.
| Guid PeanutButter.SimpleHTTPServer.HttpServer.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 |
Implements PeanutButter.SimpleHTTPServer.IHttpServer.
| Guid PeanutButter.SimpleHTTPServer.HttpServer.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 |
Implements PeanutButter.SimpleHTTPServer.IHttpServer.
| Guid PeanutButter.SimpleHTTPServer.HttpServer.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 |
Implements PeanutButter.SimpleHTTPServer.IHttpServer.