C# Class Woopsa.HTTPResponse

Provides a mechanism to send a response to a request.

This class is created internally by the Web Server and thus cannot be created from outside code. To handle requestsList and response, the WebServer.IHTTPRouteHandler interface or the delegate methods in RouteSolver which is available from the WebServer.WebServer.Routes property.

When using a method such as WriteString, WriteHTML, SetHeader, etc., no data is actually sent to the client. Instead, data is buffered until the RouteSolver is done processing, which will automatically send the response to the client.

Inheritance: IDisposable
Afficher le fichier Open project: woopsa-protocol/Woopsa Class Usage Examples

Private Properties

Свойство Type Description
HTTPResponse System
SendError void
SendError void
SetHeaderIfNotExists void

Méthodes publiques

Méthode Description
Dispose ( ) : void
Respond ( Stream outputStream ) : void

Writes the response to the output stream.

This method should only be called in certain special cases where the route solving system is being short-circuited somehow, because the route solving system is usually in charge of calling this method.

SetHeader ( string header, string value ) : void

Sets the value of an HTTP Response Header. Many standard headers are defined in WebServer.HTTPHeader, but custom headers can always be manually set in case this is desired.

Headers are sent in the Header: Value format in the HTTP protocol.

SetStatusCode ( int responseCode, string responseMessage ) : void

Set the status and message code of the response

WriteError ( HTTPStatusCode errorCode, string errorMessage ) : void

Sends a nicely-formatted error with specified HTTP Error Code and Error Message to the client. This response is not buffered and thus calling this method will immediately send the response to the client.

WriteError ( HTTPStatusCode errorCode, string errorMessage, string errorContent, string mimeType ) : void

Sends a custom-formatted error with specified HTTP Error Code, Error Message Response Content and mime type to the client. This response is not buffered and thus calling this method will immediately send the response to the client.

WriteHTML ( string html ) : void

Writes a specified string to the response buffer and sets the Content-Type header to be text/html, allowing browsers to render the string as HTML.

WriteStream ( Stream stream ) : void

Writes a stream to the response buffer. This method is used mainly when serving files in a more efficient way. This method does not modify the Content-Type header and if nothing is done, the default value of text/plain will thus be used.

WriteString ( string text ) : void

Writes a specified string to the response buffer. Does not modify the Content-Type header. Default Content-Type is text/plain

Méthodes protégées

Méthode Description
Dispose ( bool disposing ) : void
DoError ( HTTPResponse response, Exception exception ) : void

Private Methods

Méthode Description
HTTPResponse ( ) : System
SendError ( int errorCode, string errorMessage ) : void
SendError ( int errorCode, string errorMessage, string responseContent, string mimeType ) : void
SetHeaderIfNotExists ( string header, string value ) : void

Method Details

Dispose() public méthode

public Dispose ( ) : void
Résultat void

Dispose() protected méthode

protected Dispose ( bool disposing ) : void
disposing bool
Résultat void

DoError() protected static méthode

protected static DoError ( HTTPResponse response, Exception exception ) : void
response HTTPResponse
exception System.Exception
Résultat void

Respond() public méthode

Writes the response to the output stream.

This method should only be called in certain special cases where the route solving system is being short-circuited somehow, because the route solving system is usually in charge of calling this method.

public Respond ( Stream outputStream ) : void
outputStream Stream The stream in which to copy the output. Does not close the stream
Résultat void

SetHeader() public méthode

Sets the value of an HTTP Response Header. Many standard headers are defined in WebServer.HTTPHeader, but custom headers can always be manually set in case this is desired.

Headers are sent in the Header: Value format in the HTTP protocol.

public SetHeader ( string header, string value ) : void
header string /// The name of the header, for example: /// /// /// "My-Custom-Header" /// ///
value string /// The value of the header. ///
Résultat void

SetStatusCode() public méthode

Set the status and message code of the response
public SetStatusCode ( int responseCode, string responseMessage ) : void
responseCode int
responseMessage string
Résultat void

WriteError() public méthode

Sends a nicely-formatted error with specified HTTP Error Code and Error Message to the client. This response is not buffered and thus calling this method will immediately send the response to the client.
public WriteError ( HTTPStatusCode errorCode, string errorMessage ) : void
errorCode HTTPStatusCode The HTTP Status Code to send
errorMessage string The Error Message to send. For example "Not Found" or "Not Supported"
Résultat void

WriteError() public méthode

Sends a custom-formatted error with specified HTTP Error Code, Error Message Response Content and mime type to the client. This response is not buffered and thus calling this method will immediately send the response to the client.
public WriteError ( HTTPStatusCode errorCode, string errorMessage, string errorContent, string mimeType ) : void
errorCode HTTPStatusCode The HTTP Status Code to send
errorMessage string The Error Message to send. For example "Not Found" or "Not Supported"
errorContent string
mimeType string
Résultat void

WriteHTML() public méthode

Writes a specified string to the response buffer and sets the Content-Type header to be text/html, allowing browsers to render the string as HTML.
public WriteHTML ( string html ) : void
html string /// The text to write. Encoding will be solved automatically. ///
Résultat void

WriteStream() public méthode

Writes a stream to the response buffer. This method is used mainly when serving files in a more efficient way. This method does not modify the Content-Type header and if nothing is done, the default value of text/plain will thus be used.
public WriteStream ( Stream stream ) : void
stream Stream
Résultat void

WriteString() public méthode

Writes a specified string to the response buffer. Does not modify the Content-Type header. Default Content-Type is text/plain
public WriteString ( string text ) : void
text string /// The text to write. Encoding will be solved automatically. ///
Résultat void