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
파일 보기 프로젝트 열기: woopsa-protocol/Woopsa 1 사용 예제들

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