C# Class HttpServer.HttpResponse

Response that is sent back to the web browser / client.

A response can be sent if different ways. The easiest one is to just fill the Body stream with content, everything else will then be taken care of by the framework. The default content-type is text/html, you should change it if you send anything else.

The second and slightly more complex way is to send the response as parts. Start with sending the header using the SendHeaders method and then you can send the body using SendBody method, but do not forget to set ContentType and ContentLength before doing so.

Show file Open project: 3di/3di-viewer-rei-libs Class Usage Examples

Private Properties

Property Type Description
HttpResponse System

Public Methods

Method Description
AddHeader ( string name, string value ) : void

Add another header to the document.

Adding any header will override the default ones and those specified by properties.

HttpResponse ( IHttpClientContext context, IHttpRequest request ) : System

Initializes a new instance of the IHttpResponse class.

Redirect ( Uri uri ) : void

Redirect client to somewhere else using the 302 status code.

You can not do anything more with the request when a redirect have been done. This should be your last action.

Redirect ( string url ) : void

redirect to somewhere

No body are allowed when doing redirects.

Send ( ) : void

Send headers and body to the browser.

SendBody ( byte buffer ) : void

Make sure that you have specified ContentLength and sent the headers first.

This method can be used if you want to send body contents without caching them first. This is recommended for larger files to keep the memory usage low.

SendBody ( byte buffer, int offset, int count ) : void

Make sure that you have specified ContentLength and sent the headers first.

This method can be used if you want to send body contents without caching them first. This is recommended for larger files to keep the memory usage low.

SendHeaders ( ) : void

Send headers to the client.

Private Methods

Method Description
HttpResponse ( IHttpClientContext context, string httpVersion, ConnectionType connectionType ) : System

Initializes a new instance of the IHttpResponse class.

Method Details

AddHeader() public method

Add another header to the document.
Adding any header will override the default ones and those specified by properties.
If headers already been sent. If value conditions have not been met.
public AddHeader ( string name, string value ) : void
name string Name of the header, case sensitive, use lower cases.
value string Header values can span over multiple lines as long as each line starts with a white space. New line chars should be \r\n
return void

HttpResponse() public method

Initializes a new instance of the IHttpResponse class.
public HttpResponse ( IHttpClientContext context, IHttpRequest request ) : System
context IHttpClientContext Client that send the .
request IHttpRequest Contains information of what the client want to receive.
return System

Redirect() public method

Redirect client to somewhere else using the 302 status code.
You can not do anything more with the request when a redirect have been done. This should be your last action.
If headers already been sent.
public Redirect ( Uri uri ) : void
uri System.Uri Destination of the redirect
return void

Redirect() public method

redirect to somewhere
No body are allowed when doing redirects.
public Redirect ( string url ) : void
url string where the redirect should go
return void

Send() public method

Send headers and body to the browser.
If content have already been sent.
public Send ( ) : void
return void

SendBody() public method

Make sure that you have specified ContentLength and sent the headers first.
This method can be used if you want to send body contents without caching them first. This is recommended for larger files to keep the memory usage low.
If headers have not been sent.
public SendBody ( byte buffer ) : void
buffer byte
return void

SendBody() public method

Make sure that you have specified ContentLength and sent the headers first.
This method can be used if you want to send body contents without caching them first. This is recommended for larger files to keep the memory usage low.
If headers have not been sent.
public SendBody ( byte buffer, int offset, int count ) : void
buffer byte
offset int offest of first byte to send
count int number of bytes to send.
return void

SendHeaders() public method

Send headers to the client.
If headers already been sent.
public SendHeaders ( ) : void
return void