LeftHookRoll
An HTTP/1.0 compliant web server, as specified by RFC1945
Loading...
Searching...
No Matches
Request Class Reference

#include <Request.hpp>

Collaboration diagram for Request:

Public Member Functions

 Request ()
 
 Request (long long _maxBodySize)
 
 Request (const Request &other)
 
Requestoperator= (const Request &other)
 
 ~Request ()
 
size_t parseHeaders (const std::string &rawBuffer)
 Parses the raw buffer containing the HTTP Request-Line and Headers. Transitions state to REQ_BODY, REQ_CHUNKED, or REQ_DONE upon finding "\r\n\r\n".
 
bool isChunkedDone (const std::string &newData) const
 Checks if the incoming chunked data contains the terminal "\r\n\r\n". Used to transition from REQ_CHUNKED to REQ_DONE.
 
bool processBodySlice ()
 Unified method to prepare the body for the Response/CGI phase. For Content-Length bodies, this does nothing and returns true immediately. For Chunked bodies, it decodes PARSE_BYTE_SLICE bytes per call to prevent blocking.
 
long long getContentLength () const
 
HTTPMethod getMethod () const
 
const std::string & getURL () const
 
const std::string & getProtocol () const
 
const std::string & getQuery () const
 
const std::map< std::string, std::string > & getHeaders () const
 
const std::map< std::string, std::string > & getCookies () const
 
std::string getHeader (const std::string &key) const
 Gets a specific header value.
 
std::string getCookie (const std::string &key) const
 Gets a specific cookie value.
 
DataStoregetBodyStore ()
 Returns a reference to the DataStore to allow direct writing from recv().
 
ReqState getReqState () const
 
std::string getStatusCode () const
 
size_t getMaxBytesToRead () const
 
size_t getTotalBytesRead () const
 
bool isComplete () const
 

Private Member Functions

void _parseRequestLine (const std::string &line)
 
void _parseHeaderLine (const std::string &line)
 
void _parseCookies (const std::string &cookieHeader)
 
void _typeOfReq ()
 
void _extractQueryFromURL ()
 

Private Attributes

HTTPMethod _methodName
 
std::string _URL
 
std::string _protocol
 
std::string _query
 
long long _contentLength
 
DataStore _body
 
DataStore _decodedBody
 
std::map< std::string, std::string > _headers
 
std::map< std::string, std::string > _cookies
 
ReqState _reqState
 
std::string _statusCode
 
size_t _maxBodySize
 
size_t _totalBytesRead
 
size_t _chunkSize
 
size_t _chunkDecodeOffset
 
bool _isBodyProcessed
 
std::string _chunkBuffer
 
size_t _ramParsePos
 

Detailed Description

Definition at line 35 of file Request.hpp.

Constructor & Destructor Documentation

◆ Request() [1/3]

Request::Request ( )

Definition at line 42 of file Request.cpp.

◆ Request() [2/3]

Request::Request ( long long  _maxBodySize)

Definition at line 45 of file Request.cpp.

◆ Request() [3/3]

Request::Request ( const Request other)

Definition at line 48 of file Request.cpp.

◆ ~Request()

Request::~Request ( )

Definition at line 78 of file Request.cpp.

Member Function Documentation

◆ operator=()

Request & Request::operator= ( const Request other)

Definition at line 52 of file Request.cpp.

◆ parseHeaders()

size_t Request::parseHeaders ( const std::string &  rawBuffer)

Parses the raw buffer containing the HTTP Request-Line and Headers. Transitions state to REQ_BODY, REQ_CHUNKED, or REQ_DONE upon finding "\r\n\r\n".

Parameters
rawBufferThe string buffer accumulated by the Connection.
Returns
size_t The index at which the headers end (after "\r\n\r\n"). Useful for slicing leftover body data that recv() accidentally grabbed.

Definition at line 168 of file Request.cpp.

◆ isChunkedDone()

bool Request::isChunkedDone ( const std::string &  newData) const

Checks if the incoming chunked data contains the terminal "\r\n\r\n". Used to transition from REQ_CHUNKED to REQ_DONE.

Parameters
newDataThe latest chunk of data received from the socket.
Returns
true if the terminal chunk is found, false otherwise.

Definition at line 359 of file Request.cpp.

◆ processBodySlice()

bool Request::processBodySlice ( )

Unified method to prepare the body for the Response/CGI phase. For Content-Length bodies, this does nothing and returns true immediately. For Chunked bodies, it decodes PARSE_BYTE_SLICE bytes per call to prevent blocking.

Returns
true if the body is fully clean and ready, false if it needs more processing loops.

Definition at line 302 of file Request.cpp.

◆ getContentLength()

long long Request::getContentLength ( ) const

Definition at line 379 of file Request.cpp.

◆ getMethod()

HTTPMethod Request::getMethod ( ) const

Definition at line 82 of file Request.cpp.

◆ getURL()

const std::string & Request::getURL ( ) const

Definition at line 86 of file Request.cpp.

◆ getProtocol()

const std::string & Request::getProtocol ( ) const

Definition at line 90 of file Request.cpp.

◆ getQuery()

const std::string & Request::getQuery ( ) const

Definition at line 94 of file Request.cpp.

◆ getHeaders()

const std::map< std::string, std::string > & Request::getHeaders ( ) const

Definition at line 98 of file Request.cpp.

◆ getCookies()

const std::map< std::string, std::string > & Request::getCookies ( ) const

Definition at line 102 of file Request.cpp.

◆ getHeader()

std::string Request::getHeader ( const std::string &  key) const

Gets a specific header value.

Returns
The value, or empty string if not found.

Definition at line 267 of file Request.cpp.

◆ getCookie()

std::string Request::getCookie ( const std::string &  key) const

Gets a specific cookie value.

Returns
The value, or empty string if not found.

Definition at line 279 of file Request.cpp.

◆ getBodyStore()

DataStore & Request::getBodyStore ( )

Returns a reference to the DataStore to allow direct writing from recv().

Definition at line 390 of file Request.cpp.

◆ getReqState()

ReqState Request::getReqState ( ) const

Definition at line 367 of file Request.cpp.

◆ getStatusCode()

std::string Request::getStatusCode ( ) const

Definition at line 370 of file Request.cpp.

◆ getMaxBytesToRead()

size_t Request::getMaxBytesToRead ( ) const

Definition at line 375 of file Request.cpp.

◆ getTotalBytesRead()

size_t Request::getTotalBytesRead ( ) const

Definition at line 383 of file Request.cpp.

◆ isComplete()

bool Request::isComplete ( ) const

Definition at line 386 of file Request.cpp.

◆ _parseRequestLine()

void Request::_parseRequestLine ( const std::string &  line)
private

Definition at line 107 of file Request.cpp.

◆ _parseHeaderLine()

void Request::_parseHeaderLine ( const std::string &  line)
private

Definition at line 287 of file Request.cpp.

◆ _parseCookies()

void Request::_parseCookies ( const std::string &  cookieHeader)
private

Definition at line 205 of file Request.cpp.

◆ _typeOfReq()

void Request::_typeOfReq ( )
private

Definition at line 227 of file Request.cpp.

◆ _extractQueryFromURL()

void Request::_extractQueryFromURL ( )
private

Definition at line 157 of file Request.cpp.

Member Data Documentation

◆ _methodName

HTTPMethod Request::_methodName
private

Definition at line 105 of file Request.hpp.

◆ _URL

std::string Request::_URL
private

Definition at line 106 of file Request.hpp.

◆ _protocol

std::string Request::_protocol
private

Definition at line 107 of file Request.hpp.

◆ _query

std::string Request::_query
private

Definition at line 108 of file Request.hpp.

◆ _contentLength

long long Request::_contentLength
private

Definition at line 109 of file Request.hpp.

◆ _body

DataStore Request::_body
private

Definition at line 111 of file Request.hpp.

◆ _decodedBody

DataStore Request::_decodedBody
private

Definition at line 112 of file Request.hpp.

◆ _headers

std::map<std::string, std::string> Request::_headers
private

Definition at line 113 of file Request.hpp.

◆ _cookies

std::map<std::string, std::string> Request::_cookies
private

Definition at line 114 of file Request.hpp.

◆ _reqState

ReqState Request::_reqState
private

Definition at line 117 of file Request.hpp.

◆ _statusCode

std::string Request::_statusCode
private

Definition at line 118 of file Request.hpp.

◆ _maxBodySize

size_t Request::_maxBodySize
private

Definition at line 119 of file Request.hpp.

◆ _totalBytesRead

size_t Request::_totalBytesRead
private

Definition at line 120 of file Request.hpp.

◆ _chunkSize

size_t Request::_chunkSize
private

Definition at line 123 of file Request.hpp.

◆ _chunkDecodeOffset

size_t Request::_chunkDecodeOffset
private

Definition at line 124 of file Request.hpp.

◆ _isBodyProcessed

bool Request::_isBodyProcessed
private

Definition at line 125 of file Request.hpp.

◆ _chunkBuffer

std::string Request::_chunkBuffer
private

Definition at line 126 of file Request.hpp.

◆ _ramParsePos

size_t Request::_ramParsePos
private

Definition at line 127 of file Request.hpp.


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