HolyLib Wiki

HttpRequest

HttpRequest

This class represents the HttpRequest that is sent out after it was processed

Metatable function Description
__tostring Returns a formated string of the HttpRequest -> HttpRequest
__index Used to find the functions on the metatable and access saved variables
__newindex Used to allow one to save variables on the object

Methods

string HttpRequest:GetBody( )
The body of the HTTP Request.
CBaseClient HttpRequest:GetClient( )
Returns the client who sent the HTTP Request or NULL if it didn't find it.
number HttpRequest:GetContentLength( )
The length of the HTTP Request content.
string HttpRequest:GetHeader( string key )
returns the value of the given key from the header.
string HttpRequest:GetLocalAddr( )
number HttpRequest:GetLocalPort( )
string HttpRequest:GetMethod( )
The HTTP Method that was used like GET or PUT.
string HttpRequest:GetParam( string key )
returns the value of the given key from the parameters.
string HttpRequest:GetPath( )
Returns the raw request path, e.g. /users/42.
Unlike HttpRequest:GetPathParam, this returns the whole path as-is instead of extracting a named path parameter from it.
string HttpRequest:GetPathParam( string key )
returns the value of the given key from path parameters.
Player HttpRequest:GetPlayer( )
Returns the player who sent the HTTP Request or NULL if it didn't find it.
string HttpRequest:GetRemoteAddr( )
the IP Address of the Person who sent the HTTP Request
number HttpRequest:GetRemotePort( )
The Port the HTTP request was received from.
table HttpRequest:GetTable( )
Returns the lua table used by newindex and index
boolean HttpRequest:HasHeader( string key )
returns true if the client has the given key in the header.
boolean HttpRequest:HasParam( string key )
returns true if the client has the given key in the parameters.
boolean HttpRequest:IsValid( )
Returns whether this HttpRequest is valid.
HttpRequest:MarkHandled()
Marks the request as handled.
The worker thread that is waiting on this request will pick this up, send the response back to the client and delete the request.
Returning any value other than false from a request handler (see HttpServer:Get and the other method functions) will call this automatically, so you usually don't need to call this yourself.
If a request handler errors out, it will also be marked as handled automatically. Once a request was marked handled, the HttpRequest becomes invalid and must no longer be used!
HttpRequest:SetContent( string content, string contentType = text/plain )
Sets the content for the response.
HttpRequest:SetHeader( string key, string value )
Sets the given value for the given key in the header.
HttpRequest:SetRedirect( string url, number code = 302 )
Redirects one to the given URL and returns the given code.
HttpRequest:SetStatusCode( number status )
Sets the status code of the response, clamped between 100 and 600.