C# Класс 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.

Наследование: IDisposable
Показать файл Открыть проект Примеры использования класса

Private Properties

Свойство Тип Описание
HTTPResponse System
SendError void
SendError void
SetHeaderIfNotExists void

Открытые методы

Метод Описание
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

Защищенные методы

Метод Описание
Dispose ( bool disposing ) : void
DoError ( HTTPResponse response, Exception exception ) : void

Приватные методы

Метод Описание
HTTPResponse ( ) : System
SendError ( int errorCode, string errorMessage ) : void
SendError ( int errorCode, string errorMessage, string responseContent, string mimeType ) : void
SetHeaderIfNotExists ( string header, string value ) : void

Описание методов

Dispose() публичный Метод

public Dispose ( ) : void
Результат void

Dispose() защищенный Метод

protected Dispose ( bool disposing ) : void
disposing bool
Результат void

DoError() защищенный статический Метод

protected static DoError ( HTTPResponse response, Exception exception ) : void
response HTTPResponse
exception System.Exception
Результат void

Respond() публичный Метод

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
Результат void

SetHeader() публичный Метод

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. ///
Результат void

SetStatusCode() публичный Метод

Set the status and message code of the response
public SetStatusCode ( int responseCode, string responseMessage ) : void
responseCode int
responseMessage string
Результат void

WriteError() публичный Метод

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"
Результат void

WriteError() публичный Метод

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
Результат void

WriteHTML() публичный Метод

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. ///
Результат void

WriteStream() публичный Метод

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
Результат void

WriteString() публичный Метод

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. ///
Результат void