ProtonNet Server 1.0
An Open Solution for all your socket or web api needs.
Loading...
Searching...
No Matches
XmobiTea.ProtonNetCommon.HttpResponse Class Reference

Represents an HTTP response, encapsulating the protocol, status, headers, cookies, and body of the response. More...

Inheritance diagram for XmobiTea.ProtonNetCommon.HttpResponse:
XmobiTea.ProtonNet.Server.WebApi.Models.ViewResult

Public Member Functions

 HttpResponse ()
 Initializes a new instance of the HttpResponse class.
 
HttpResponse(StatusCode status, string protocol=Constance.DefaultHttpProtocol) Tuple< string, string > GetHeader (int i)
 Initializes a new instance of the HttpResponse class with the specified status and protocol.
 
string GetHeader (string key)
 Gets the value of the specified header.
 
Tuple< string, string > GetCookie (int i)
 Gets the cookie at the specified index.
 
string GetCookie (string name)
 Gets the value of the specified cookie.
 
void Clear ()
 Clears the current response, resetting all properties.
 
HttpResponse SetBegin (StatusCode status, string protocol=Constance.DefaultHttpProtocol)
 Sets the beginning of the response with the specified status and protocol.
 
HttpResponse SetContentType (string extension)
 Sets the Content-Type header for the response based on the file extension.
 
HttpResponse SetHeader (string key, string value)
 Sets a header with the specified key and value.
 
HttpResponse SetCookie (string name, string value, int maxAge=86400, string path="", string domain="", bool secure=true, bool strict=true, bool httpOnly=true)
 Sets a cookie with the specified name, value, and optional parameters.
 
HttpResponse SetBody (string body="")
 Sets the body of the response with the specified string content.
 
HttpResponse SetBody (byte[] body)
 Sets the body of the response with the specified byte array content.
 
bool IsPendingHeader ()
 Indicates whether the response is pending header processing.
 
bool IsPendingBody ()
 Indicates whether the response is pending body processing.
 
bool SetHeaderBuffer (byte[] buffer, int position, int length)
 Sets the header buffer with the specified byte array data.
 
bool SetBodyBuffer (byte[] buffer, int position, int length)
 Sets the body buffer with the specified byte array data.
 

Properties

string Protocol [get]
 Gets the HTTP protocol used in the response.
 
long HeaderCount [get]
 Gets the count of headers in the response.
 
int CookieCount [get]
 Gets the count of cookies in the response.
 
IMemoryBuffer Cache [get]
 Gets the memory buffer that stores the response data.
 
bool IsEmpty [get]
 Indicates whether the response body is empty.
 
bool IsErrorSet [get]
 Indicates whether an error has been set in the response.
 
StatusCode Status [get]
 Gets the HTTP status code of the response.
 
string BodyAsString [get]
 Gets the body of the response as a string.
 
byte[] BodyAsBytes [get]
 Gets the body of the response as a byte array.
 

Detailed Description

Represents an HTTP response, encapsulating the protocol, status, headers, cookies, and body of the response.

Member Function Documentation

◆ GetCookie() [1/2]

Tuple< string, string > XmobiTea.ProtonNetCommon.HttpResponse.GetCookie ( int i)

Gets the cookie at the specified index.

Parameters
iThe index of the cookie.
Returns
A tuple containing the cookie name and value.

◆ GetCookie() [2/2]

string XmobiTea.ProtonNetCommon.HttpResponse.GetCookie ( string name)

Gets the value of the specified cookie.

Parameters
nameThe name of the cookie.
Returns
The value of the cookie, or null if not found.

◆ GetHeader() [1/2]

HttpResponse(StatusCode status, string protocol=Constance.DefaultHttpProtocol) Tuple< string, string > XmobiTea.ProtonNetCommon.HttpResponse.GetHeader ( int i)

Initializes a new instance of the HttpResponse class with the specified status and protocol.

Parameters
statusThe HTTP status code.
protocolThe HTTP protocol (default is Constance.DefaultHttpProtocol).

Gets the header at the specified index.

Parameters
iThe index of the header.
Returns
A tuple containing the header name and value.

◆ GetHeader() [2/2]

string XmobiTea.ProtonNetCommon.HttpResponse.GetHeader ( string key)

Gets the value of the specified header.

Parameters
keyThe name of the header.
Returns
The value of the header, or null if not found.

◆ IsPendingBody()

bool XmobiTea.ProtonNetCommon.HttpResponse.IsPendingBody ( )

Indicates whether the response is pending body processing.

Returns
True if the response is pending body processing, otherwise false.

◆ IsPendingHeader()

bool XmobiTea.ProtonNetCommon.HttpResponse.IsPendingHeader ( )

Indicates whether the response is pending header processing.

Returns
True if the response is pending header processing, otherwise false.

◆ SetBegin()

HttpResponse XmobiTea.ProtonNetCommon.HttpResponse.SetBegin ( StatusCode status,
string protocol = Constance::DefaultHttpProtocol )

Sets the beginning of the response with the specified status and protocol.

Parameters
statusThe HTTP status code.
protocolThe HTTP protocol (default is Constance.DefaultHttpProtocol).
Returns
The current HttpResponse instance.

◆ SetBody() [1/2]

HttpResponse XmobiTea.ProtonNetCommon.HttpResponse.SetBody ( byte[] body)

Sets the body of the response with the specified byte array content.

Parameters
bodyThe body content as a byte array.
Returns
The current HttpResponse instance.

◆ SetBody() [2/2]

HttpResponse XmobiTea.ProtonNetCommon.HttpResponse.SetBody ( string body = "")

Sets the body of the response with the specified string content.

Parameters
bodyThe body content as a string.
Returns
The current HttpResponse instance.

◆ SetBodyBuffer()

bool XmobiTea.ProtonNetCommon.HttpResponse.SetBodyBuffer ( byte[] buffer,
int position,
int length )

Sets the body buffer with the specified byte array data.

Parameters
bufferThe byte array containing body data.
positionThe starting position in the buffer.
lengthThe length of the data to write.
Returns
True if the body processing is complete, otherwise false.

◆ SetContentType()

HttpResponse XmobiTea.ProtonNetCommon.HttpResponse.SetContentType ( string extension)

Sets the Content-Type header for the response based on the file extension.

Parameters
extensionThe file extension.
Returns
The current HttpResponse instance.

◆ SetCookie()

HttpResponse XmobiTea.ProtonNetCommon.HttpResponse.SetCookie ( string name,
string value,
int maxAge = 86400,
string path = "",
string domain = "",
bool secure = true,
bool strict = true,
bool httpOnly = true )

Sets a cookie with the specified name, value, and optional parameters.

Parameters
nameThe name of the cookie.
valueThe value of the cookie.
maxAgeThe maximum age of the cookie in seconds (default is 86400 seconds).
pathThe path where the cookie is valid.
domainThe domain where the cookie is valid.
secureIndicates whether the cookie is secure (default is true).
strictIndicates whether the cookie should be SameSite=Strict (default is true).
httpOnlyIndicates whether the cookie is HttpOnly (default is true).
Returns
The current HttpResponse instance.

◆ SetHeader()

HttpResponse XmobiTea.ProtonNetCommon.HttpResponse.SetHeader ( string key,
string value )

Sets a header with the specified key and value.

Parameters
keyThe name of the header.
valueThe value of the header.
Returns
The current HttpResponse instance.

◆ SetHeaderBuffer()

bool XmobiTea.ProtonNetCommon.HttpResponse.SetHeaderBuffer ( byte[] buffer,
int position,
int length )

Sets the header buffer with the specified byte array data.

Parameters
bufferThe byte array containing header data.
positionThe starting position in the buffer.
lengthThe length of the data to write.
Returns
True if the header processing is complete, otherwise false.

The documentation for this class was generated from the following file: