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

#include <Response.hpp>

Collaboration diagram for Response:

Public Member Functions

 Response ()
 
 Response (const Response &other)
 
Responseoperator= (const Response &other)
 
 ~Response ()
 
bool buildResponse (Request &req, const ServerConf &config)
 Analyzes the Request and Location settings to prepare the response. Sets the status code, phrase, and loads the DataStore with content.
 
void buildErrorPage (const std::string &code, const ServerConf &config)
 Fast-tracks the response to an error state. Loads the appropriate error page from config or default HTML.
 
bool sendSlice (int fd)
 Sends a slice of the response to the client socket. To be called during a POLLOUT event.
 
const std::string & getStatusCode () const
 
const std::string & getVersion () const
 
const std::string & getResponsePhrase () const
 
ResponseState getResponseState () const
 
BuildPhase getBuildPhase () const
 
CGIManagergetCgiInstance () const
 
int getCgiOutputFd () const
 Returns the CGI output pipe fd for epoll registration.
 
bool readCgiOutput ()
 Called by ServerManager when the CGI pipe is readable. Reads available data into _responseDataStore.
 
void cgiTimeout (const ServerConf &config)
 Called by ServerManager when the CGI process times out. Kills the process and builds a 504 error page.
 
void finalizeCgiResponse ()
 Finalizes the CGI response after all output has been read. Parses CGI output headers, builds the HTTP response, transitions to sendable state.
 
void setStatusCode (const std::string &code)
 
void setResponsePhrase (const std::string &phrase)
 
void addHeader (const std::string &key, const std::string &value)
 Adds a header to the response (e.g., "Content-Type", "text/html").
 
void addCookie (const Request &req)
 
const std::vector< std::string > & getSetCookies () const
 

Private Member Functions

std::string _generateHeaderString ()
 
std::string _lookupReasonPhrase (const std::string &code)
 
void _handleGet (const Request &req, const LocationConf &loc, const ServerConf &config)
 
bool _handlePost (Request &req, const LocationConf &loc, const ServerConf &config)
 
bool _continuePostWrite (Request &req)
 
void _handleDelete (const Request &req, const LocationConf &loc, const ServerConf &config)
 
bool _handleCGI (Request &req, const LocationConf &loc, const ServerConf &config)
 
void _finalizeSuccess (const std::string &contentType)
 
void _serveFile (const std::string &path, const ServerConf &config)
 
std::string _drainDataStore ()
 
void _splitCgiOutput (const std::string &raw, std::string &headers, std::string &body)
 
bool _parseCgiHeaders (const std::string &headerBlock, std::string &contentType)
 
bool _sendHeader (int fd)
 
bool _sendBodyStatic (int fd)
 
bool _sendBodyFile (int fd)
 
bool _sendBodyDataStore (int fd)
 
bool _sendBodyChunked (int fd)
 

Private Attributes

std::string _statusCode
 
std::string _version
 
std::string _response_phrase
 
size_t _writeBufferSize
 
DataStore _responseDataStore
 
size_t _totalBytesSent
 
std::map< std::string, std::string > _headers
 
std::vector< std::string > _setCookies
 
int _fileFd
 
size_t _fileSize
 
std::vector< char > _streamBuf
 
size_t _streamBufLen
 
size_t _streamBufSent
 
CGIManager_cgiInstance
 
size_t _currentChunkSize
 
BuildPhase _buildPhase
 
const ServerConf_cachedConfig
 
int _postOutFd
 
size_t _postWritePos
 
std::string _postFilename
 
ResponseState _responseState
 
std::string _headerBuffer
 

Detailed Description

Definition at line 43 of file Response.hpp.

Constructor & Destructor Documentation

◆ Response() [1/2]

Response::Response ( )

Definition at line 203 of file Response.cpp.

◆ Response() [2/2]

Response::Response ( const Response other)

Definition at line 227 of file Response.cpp.

◆ ~Response()

Response::~Response ( )

Definition at line 289 of file Response.cpp.

Member Function Documentation

◆ operator=()

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

Definition at line 252 of file Response.cpp.

◆ buildResponse()

bool Response::buildResponse ( Request req,
const ServerConf config 
)

Analyzes the Request and Location settings to prepare the response. Sets the status code, phrase, and loads the DataStore with content.

Returns
true if the response is finished, false if not.

Definition at line 298 of file Response.cpp.

◆ buildErrorPage()

void Response::buildErrorPage ( const std::string &  code,
const ServerConf config 
)

Fast-tracks the response to an error state. Loads the appropriate error page from config or default HTML.

Parameters
codeThe HTTP status code (e.g., "404", "500").

Definition at line 364 of file Response.cpp.

◆ sendSlice()

bool Response::sendSlice ( int  fd)

Sends a slice of the response to the client socket. To be called during a POLLOUT event.

Parameters
fdThe client socket file descriptor.
Returns
true if the entire response is finished, false if more data remains.

Definition at line 409 of file Response.cpp.

◆ getStatusCode()

const std::string & Response::getStatusCode ( ) const

Definition at line 863 of file Response.cpp.

◆ getVersion()

const std::string & Response::getVersion ( ) const

Definition at line 864 of file Response.cpp.

◆ getResponsePhrase()

const std::string & Response::getResponsePhrase ( ) const

Definition at line 865 of file Response.cpp.

◆ getResponseState()

ResponseState Response::getResponseState ( ) const

Definition at line 866 of file Response.cpp.

◆ getBuildPhase()

BuildPhase Response::getBuildPhase ( ) const

Definition at line 867 of file Response.cpp.

◆ getCgiInstance()

CGIManager * Response::getCgiInstance ( ) const

Definition at line 868 of file Response.cpp.

◆ getCgiOutputFd()

int Response::getCgiOutputFd ( ) const

Returns the CGI output pipe fd for epoll registration.

Returns
The fd, or -1 if no CGI is active.

Definition at line 870 of file Response.cpp.

◆ readCgiOutput()

bool Response::readCgiOutput ( )

Called by ServerManager when the CGI pipe is readable. Reads available data into _responseDataStore.

Returns
true if CGI output is fully consumed (EOF reached), false if more data expected.

Definition at line 877 of file Response.cpp.

◆ cgiTimeout()

void Response::cgiTimeout ( const ServerConf config)

Called by ServerManager when the CGI process times out. Kills the process and builds a 504 error page.

Definition at line 910 of file Response.cpp.

◆ finalizeCgiResponse()

void Response::finalizeCgiResponse ( )

Finalizes the CGI response after all output has been read. Parses CGI output headers, builds the HTTP response, transitions to sendable state.

Definition at line 930 of file Response.cpp.

◆ setStatusCode()

void Response::setStatusCode ( const std::string &  code)

Definition at line 1088 of file Response.cpp.

◆ setResponsePhrase()

void Response::setResponsePhrase ( const std::string &  phrase)

Definition at line 1094 of file Response.cpp.

◆ addHeader()

void Response::addHeader ( const std::string &  key,
const std::string &  value 
)

Adds a header to the response (e.g., "Content-Type", "text/html").

Definition at line 1099 of file Response.cpp.

◆ addCookie()

void Response::addCookie ( const Request req)

if you want accessible by the HTTP server, not by JavaScript. add this V cookie += "; HttpOnly";

Definition at line 1118 of file Response.cpp.

◆ getSetCookies()

const std::vector< std::string > & Response::getSetCookies ( ) const

Definition at line 1131 of file Response.cpp.

◆ _generateHeaderString()

std::string Response::_generateHeaderString ( )
private

Definition at line 1137 of file Response.cpp.

◆ _lookupReasonPhrase()

std::string Response::_lookupReasonPhrase ( const std::string &  code)
private

Definition at line 1152 of file Response.cpp.

◆ _handleGet()

void Response::_handleGet ( const Request req,
const LocationConf loc,
const ServerConf config 
)
private

Definition at line 540 of file Response.cpp.

◆ _handlePost()

bool Response::_handlePost ( Request req,
const LocationConf loc,
const ServerConf config 
)
private

Definition at line 608 of file Response.cpp.

◆ _continuePostWrite()

bool Response::_continuePostWrite ( Request req)
private

Definition at line 648 of file Response.cpp.

◆ _handleDelete()

void Response::_handleDelete ( const Request req,
const LocationConf loc,
const ServerConf config 
)
private

Definition at line 773 of file Response.cpp.

◆ _handleCGI()

bool Response::_handleCGI ( Request req,
const LocationConf loc,
const ServerConf config 
)
private

Definition at line 713 of file Response.cpp.

◆ _finalizeSuccess()

void Response::_finalizeSuccess ( const std::string &  contentType)
private

Definition at line 820 of file Response.cpp.

◆ _serveFile()

void Response::_serveFile ( const std::string &  path,
const ServerConf config 
)
private

Definition at line 830 of file Response.cpp.

◆ _drainDataStore()

std::string Response::_drainDataStore ( )
private

Definition at line 994 of file Response.cpp.

◆ _splitCgiOutput()

void Response::_splitCgiOutput ( const std::string &  raw,
std::string &  headers,
std::string &  body 
)
private

Definition at line 1006 of file Response.cpp.

◆ _parseCgiHeaders()

bool Response::_parseCgiHeaders ( const std::string &  headerBlock,
std::string &  contentType 
)
private

Definition at line 1027 of file Response.cpp.

◆ _sendHeader()

bool Response::_sendHeader ( int  fd)
private

Definition at line 418 of file Response.cpp.

◆ _sendBodyStatic()

bool Response::_sendBodyStatic ( int  fd)
private

Definition at line 442 of file Response.cpp.

◆ _sendBodyFile()

bool Response::_sendBodyFile ( int  fd)
private

Definition at line 450 of file Response.cpp.

◆ _sendBodyDataStore()

bool Response::_sendBodyDataStore ( int  fd)
private

Definition at line 492 of file Response.cpp.

◆ _sendBodyChunked()

bool Response::_sendBodyChunked ( int  fd)
private

Member Data Documentation

◆ _statusCode

std::string Response::_statusCode
private

Definition at line 116 of file Response.hpp.

◆ _version

std::string Response::_version
private

Definition at line 117 of file Response.hpp.

◆ _response_phrase

std::string Response::_response_phrase
private

Definition at line 118 of file Response.hpp.

◆ _writeBufferSize

size_t Response::_writeBufferSize
private

Definition at line 120 of file Response.hpp.

◆ _responseDataStore

DataStore Response::_responseDataStore
private

Definition at line 121 of file Response.hpp.

◆ _totalBytesSent

size_t Response::_totalBytesSent
private

Definition at line 122 of file Response.hpp.

◆ _headers

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

Definition at line 123 of file Response.hpp.

◆ _setCookies

std::vector<std::string> Response::_setCookies
private

Definition at line 124 of file Response.hpp.

◆ _fileFd

int Response::_fileFd
private

Definition at line 125 of file Response.hpp.

◆ _fileSize

size_t Response::_fileSize
private

Definition at line 126 of file Response.hpp.

◆ _streamBuf

std::vector<char> Response::_streamBuf
private

Definition at line 127 of file Response.hpp.

◆ _streamBufLen

size_t Response::_streamBufLen
private

Definition at line 128 of file Response.hpp.

◆ _streamBufSent

size_t Response::_streamBufSent
private

Definition at line 129 of file Response.hpp.

◆ _cgiInstance

CGIManager* Response::_cgiInstance
private

Definition at line 130 of file Response.hpp.

◆ _currentChunkSize

size_t Response::_currentChunkSize
private

Definition at line 131 of file Response.hpp.

◆ _buildPhase

BuildPhase Response::_buildPhase
private

Definition at line 134 of file Response.hpp.

◆ _cachedConfig

const ServerConf* Response::_cachedConfig
private

Definition at line 135 of file Response.hpp.

◆ _postOutFd

int Response::_postOutFd
private

Definition at line 136 of file Response.hpp.

◆ _postWritePos

size_t Response::_postWritePos
private

Definition at line 137 of file Response.hpp.

◆ _postFilename

std::string Response::_postFilename
private

Definition at line 138 of file Response.hpp.

◆ _responseState

ResponseState Response::_responseState
private

Definition at line 140 of file Response.hpp.

◆ _headerBuffer

std::string Response::_headerBuffer
private

Definition at line 166 of file Response.hpp.


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