Webserv
Loading...
Searching...
No Matches
http::Request Class Reference

#include <Request.hpp>

Public Member Functions

 Request ()
bool wantsJson () const
 Checks the 'Accept' header to see if the client prefers JSON.
void clear ()
 Resets the request to a default state, ready for reuse. Cleans up any existing body and resets all fields.
size_t getMaxAllowedContentSize () const
config::LocationBlock const * location () const
 Gets a const pointer to the matched LocationBlock.
config::ServerBlock const * server () const
 Gets a const pointer to the matched ServerBlock.
Headersheaders ()
 Gets a mutable reference to the request headers.
Headers const & headers () const
 Gets a constant reference to the request headers.
RequestStartLine::Method method () const
 Gets the HTTP method enum.
std::string const & uri () const
 Gets the full, original request URI (e.g., "/path?query=1").
Requesturi (std::string const &)
std::string const & path () const
 Gets the path portion of the URI (e.g., "/path").
std::string const & queryString () const
 Gets the query string portion of the URI (e.g., "query=1").
std::string const & version () const
 Gets the HTTP protocol version (e.g., "HTTP/1.1").
utils::TempFile const * body () const
utils::TempFilebody ()
const std::string & bodyPath () const
utils::TempFile::MoveStatus moveBody (const std::string &destPath) const
 Relocates the request body to a permanent location.
Requeststatus (HttpStatus statusCode)
 Sets the response status and automatically syncs the reason phrase.
HttpStatus status () const
 Gets the current status code.
std::string resolvePath () const
 Resolves the full filesystem path for a request.
std::string const & remoteAddr () const
 Gets the remote (client) IP address for this request.
 ~Request ()

Protected Member Functions

Requestlocation (config::LocationBlock const *location)
Requestserver (config::ServerBlock const *server)
Requestmethod (RequestStartLine::Method method)
Requestpath (std::string const &)
Requestversion (std::string const &)
RequestremoteAddr (std::string const &addr)
Requestbody (utils::TempFile *body)

Private Member Functions

 Request (const Request &)
Requestoperator= (const Request &)

Private Attributes

RequestStartLine requestLine_
Headers headers_
utils::TempFilebody_
config::LocationBlock const * location_
config::ServerBlock const * server_
HttpStatus status_
std::string remoteAddr_

Friends

class RequestParser
class Router
class network::ClientHandler

Constructor & Destructor Documentation

◆ Request() [1/2]

http::Request::Request ( )

◆ ~Request()

http::Request::~Request ( )

◆ Request() [2/2]

http::Request::Request ( const Request & )
private

Member Function Documentation

◆ body() [1/3]

utils::TempFile * http::Request::body ( )

◆ body() [2/3]

utils::TempFile const * http::Request::body ( ) const

◆ body() [3/3]

Request & http::Request::body ( utils::TempFile * body)
protected

◆ bodyPath()

const std::string & http::Request::bodyPath ( ) const

◆ clear()

void http::Request::clear ( )

Resets the request to a default state, ready for reuse. Cleans up any existing body and resets all fields.

◆ getMaxAllowedContentSize()

size_t http::Request::getMaxAllowedContentSize ( ) const

◆ headers() [1/2]

Headers & http::Request::headers ( )

Gets a mutable reference to the request headers.

Note
This is public to allow handlers to inspect headers.

◆ headers() [2/2]

Headers const & http::Request::headers ( ) const

Gets a constant reference to the request headers.

◆ location() [1/2]

config::LocationBlock const * http::Request::location ( ) const

Gets a const pointer to the matched LocationBlock.

Returns
Const pointer to the block, or NULL if not matched.

◆ location() [2/2]

Request & http::Request::location ( config::LocationBlock const * location)
protected

◆ method() [1/2]

RequestStartLine::Method http::Request::method ( ) const

Gets the HTTP method enum.

◆ method() [2/2]

Request & http::Request::method ( RequestStartLine::Method method)
protected

◆ moveBody()

utils::TempFile::MoveStatus http::Request::moveBody ( const std::string & destPath) const

Relocates the request body to a permanent location.

This transfers ownership of the file; it will NO LONGER be managed or deleted by the Request object upon destruction.

Parameters
destPathAbsolute path to the destination file.
Returns
MoveStatus indicating success or the specific type of failure.

◆ operator=()

Request & http::Request::operator= ( const Request & )
private

◆ path() [1/2]

std::string const & http::Request::path ( ) const

Gets the path portion of the URI (e.g., "/path").

◆ path() [2/2]

Request & http::Request::path ( std::string const & path)
protected

◆ queryString()

std::string const & http::Request::queryString ( ) const

Gets the query string portion of the URI (e.g., "query=1").

◆ remoteAddr() [1/2]

std::string const & http::Request::remoteAddr ( ) const

Gets the remote (client) IP address for this request.

Returns
The client IP address as a string (e.g., "192.168.1.100").

◆ remoteAddr() [2/2]

Request & http::Request::remoteAddr ( std::string const & addr)
protected

◆ resolvePath()

std::string http::Request::resolvePath ( ) const

Resolves the full filesystem path for a request.

This function correctly implements the logic for both the Nginx 'root' and 'alias' directives. 'alias' takes precedence if it exists.

Returns
The fully resolved filesystem path.

◆ server() [1/2]

config::ServerBlock const * http::Request::server ( ) const

Gets a const pointer to the matched ServerBlock.

Returns
Const pointer to the block, or NULL if not matched.

◆ server() [2/2]

Request & http::Request::server ( config::ServerBlock const * server)
protected

◆ status() [1/2]

HttpStatus http::Request::status ( ) const

Gets the current status code.

◆ status() [2/2]

Request & http::Request::status ( HttpStatus statusCode)

Sets the response status and automatically syncs the reason phrase.

Parameters
statusCodeThe HttpStatus enum value (e.g., NOT_FOUND).
Returns
A reference to this object for chaining.

◆ uri() [1/2]

std::string const & http::Request::uri ( ) const

Gets the full, original request URI (e.g., "/path?query=1").

◆ uri() [2/2]

Request & http::Request::uri ( std::string const & uri)

◆ version() [1/2]

std::string const & http::Request::version ( ) const

Gets the HTTP protocol version (e.g., "HTTP/1.1").

◆ version() [2/2]

Request & http::Request::version ( std::string const & version)
protected

◆ wantsJson()

bool http::Request::wantsJson ( ) const

Checks the 'Accept' header to see if the client prefers JSON.

Returns
True if 'application/json' is found in the Accept header.

◆ network::ClientHandler

friend class network::ClientHandler
friend

◆ RequestParser

friend class RequestParser
friend

◆ Router

friend class Router
friend

Member Data Documentation

◆ body_

utils::TempFile* http::Request::body_
private

◆ headers_

Headers http::Request::headers_
private

◆ location_

config::LocationBlock const* http::Request::location_
private

◆ remoteAddr_

std::string http::Request::remoteAddr_
private

◆ requestLine_

RequestStartLine http::Request::requestLine_
private

◆ server_

config::ServerBlock const* http::Request::server_
private

◆ status_

HttpStatus http::Request::status_
private

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