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

Represents an HTTP request with properties for the method, URL, protocol, headers, cookies, and body. More...

Inheritance diagram for XmobiTea.ProtonNetCommon.HttpRequest:
XmobiTea.ProtonNet.Server.WebApi.Models.HttpRequest

Public Member Functions

 HttpRequest ()
 Initializes a new instance of the HttpRequest class.
 
HttpRequest(string method, string url, string protocol=Constance.DefaultHttpProtocol) Tuple< string, string > GetHeader (int i)
 Initializes a new instance of the HttpRequest class with the specified method, URL, and protocol.
 
string GetHeader (string key)
 Gets the value of the header with the specified key.
 
Tuple< string, string > GetCookie (int i)
 Gets the cookie at the specified index.
 
string GetCookie (string name)
 Gets the value of the cookie with the specified name.
 
void Clear ()
 Clears the request, resetting all properties to their default values.
 
HttpRequest SetBegin (string method, string url, string protocol=Constance.DefaultHttpProtocol)
 Sets the initial request line (method, URL, protocol).
 
HttpRequest SetHeader (string key, string value)
 Adds a header to the request.
 
HttpRequest SetCookie (string name, string value)
 Sets a cookie in the request.
 
HttpRequest AddCookie (string name, string value)
 Adds a cookie to the request.
 
HttpRequest SetBody (string body="")
 Sets the body of the request as a string.
 
HttpRequest SetBody (byte[] body)
 Sets the body of the request as a byte array.
 
bool IsPendingHeader ()
 Determines whether the request is pending headers.
 
bool IsPendingBody ()
 Determines whether the request is pending body data.
 
bool SetHeaderBuffer (byte[] buffer, int position, int length)
 Sets the header buffer from the provided byte array.
 
bool SetBodyBuffer (byte[] buffer, int position, int length)
 Sets the body buffer from the provided byte array.
 

Properties

string Method [get]
 Gets the HTTP method of the request (e.g., GET, POST).
 
string Url [get]
 Gets the URL of the request.
 
string Protocol [get]
 Gets the protocol version (e.g., HTTP/1.1).
 
IList< Tuple< string, string > > headers [get, set]
 
IList< Tuple< string, string > > Headers [get]
 Gets the list of headers in the request.
 
int HeaderCount [get]
 Gets header count in the request.
 
IList< Tuple< string, string > > cookies [get, set]
 
IList< Tuple< string, string > > Cookies [get]
 Gets the list of cookies in the request.
 
int CookieCount [get]
 Gets cookie count in the request.
 
int bodyIndex [get, set]
 
int BodyIndex [get]
 Gets the index in the buffer where the body starts.
 
int bodySize [get, set]
 
int BodySize [get]
 Gets the size of the body in bytes.
 
int bodyLength [get, set]
 
int BodyLength [get]
 Gets the total length of the body.
 
bool bodyLengthProvided [get, set]
 
bool BodyLengthProvided [get]
 Indicates whether the body length was provided in the request.
 
IMemoryBuffer cache [get, set]
 
IMemoryBuffer Cache [get]
 Gets the buffer that caches the request data.
 
int cacheSize [get, set]
 
int CacheSize [get]
 Gets the size of the cache.
 
bool IsEmpty [get]
 Indicates whether the request is empty.
 
bool IsErrorSet [get, protected set]
 Indicates whether an error is set on the request.
 
string BodyAsString [get]
 Gets the body of the request as a string.
 
byte[] BodyAsBytes [get]
 Gets the body of the request as a byte array.
 

Detailed Description

Represents an HTTP request with properties for the method, URL, protocol, headers, cookies, and body.

Member Function Documentation

◆ AddCookie()

HttpRequest XmobiTea.ProtonNetCommon.HttpRequest.AddCookie ( string name,
string value )

Adds a cookie to the request.

Parameters
nameThe name of the cookie.
valueThe value of the cookie.
Returns
The current HttpRequest instance.

◆ GetCookie() [1/2]

Tuple< string, string > XmobiTea.ProtonNetCommon.HttpRequest.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.HttpRequest.GetCookie ( string name)

Gets the value of the cookie with the specified name.

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

◆ GetHeader() [1/2]

HttpRequest(string method, string url, string protocol=Constance.DefaultHttpProtocol) Tuple< string, string > XmobiTea.ProtonNetCommon.HttpRequest.GetHeader ( int i)

Initializes a new instance of the HttpRequest class with the specified method, URL, and protocol.

Parameters
methodThe HTTP method (e.g., GET, POST).
urlThe URL of the request.
protocolThe protocol version (default is HTTP/1.1).

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.HttpRequest.GetHeader ( string key)

Gets the value of the header with the specified key.

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

◆ IsPendingBody()

bool XmobiTea.ProtonNetCommon.HttpRequest.IsPendingBody ( )

Determines whether the request is pending body data.

Returns
True if body data is pending; otherwise, false.

◆ IsPendingHeader()

bool XmobiTea.ProtonNetCommon.HttpRequest.IsPendingHeader ( )

Determines whether the request is pending headers.

Returns
True if headers are pending; otherwise, false.

◆ SetBegin()

HttpRequest XmobiTea.ProtonNetCommon.HttpRequest.SetBegin ( string method,
string url,
string protocol = Constance::DefaultHttpProtocol )

Sets the initial request line (method, URL, protocol).

Parameters
methodThe HTTP method.
urlThe URL of the request.
protocolThe protocol version (default is HTTP/1.1).
Returns
The current HttpRequest instance.

◆ SetBody() [1/2]

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

Sets the body of the request as a byte array.

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

◆ SetBody() [2/2]

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

Sets the body of the request as a string.

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

◆ SetBodyBuffer()

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

Sets the body buffer from the provided byte array.

Parameters
bufferThe byte array containing the body data.
positionThe position in the buffer where the data starts.
lengthThe length of the data in the buffer.
Returns
True if the body was successfully set; otherwise, false.

◆ SetCookie()

HttpRequest XmobiTea.ProtonNetCommon.HttpRequest.SetCookie ( string name,
string value )

Sets a cookie in the request.

Parameters
nameThe name of the cookie.
valueThe value of the cookie.
Returns
The current HttpRequest instance.

◆ SetHeader()

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

Adds a header to the request.

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

◆ SetHeaderBuffer()

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

Sets the header buffer from the provided byte array.

Parameters
bufferThe byte array containing the header data.
positionThe position in the buffer where the data starts.
lengthThe length of the data in the buffer.
Returns
True if the headers were successfully set; otherwise, false.

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