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

A data container for an HTTP response. More...

#include <HttpResponse.hpp>

Public Member Functions

 HttpResponse ()
 HttpResponse (Status code, std::string const &httpVersion)
 HttpResponse (HttpResponse const &)
HttpResponse const & operator= (HttpResponse const &)
 ~HttpResponse ()
void setStatus (Status s)
void setNoBody ()
void setBodyInMemory (std::vector< char > const &, std::string const &mimeType)
void setBodyFromFile (int fd, size_t size)
void setBodyFromFile (int fd, size_t size, std::string const &mimeType)
void setBodyFromCgi (int pipe_fd)
Status getStatus () const
char const * getResponsePhrase () const
HeaderMapgetHeaders ()
HeaderMap const & getHeaders () const
std::string const & getVersion () const
BodySourceType getBodyType () const
std::string buildHeaders () const

Public Attributes

union { 
   struct { 
      std::vector< char > *   data 
      size_t   sent 
   }   inMemoryBody
 Details for in-memory bodies. More...
   struct { 
      int   fd 
      size_t   totalSize 
      size_t   sent 
   }   fileBody
 Details for file-based bodies. More...
   struct { 
      int   pipe_fd 
   }   cgiBody
 Details for CGI-based bodies. More...
}; 

Private Member Functions

void cleanupBody ()

Private Attributes

std::string httpVersion_
Status statusCode_
HeaderMap headers_
BodySourceType bodyType_

Detailed Description

A data container for an HTTP response.

This object is populated by a handler and then serialized into a raw HTTP response string by the ResponseBuilder.

Constructor & Destructor Documentation

◆ HttpResponse() [1/3]

http::HttpResponse::HttpResponse ( )

◆ HttpResponse() [2/3]

http::HttpResponse::HttpResponse ( Status code,
std::string const & httpVersion )

◆ HttpResponse() [3/3]

http::HttpResponse::HttpResponse ( HttpResponse const & rhs)

◆ ~HttpResponse()

http::HttpResponse::~HttpResponse ( )

Member Function Documentation

◆ buildHeaders()

std::string http::HttpResponse::buildHeaders ( ) const

◆ cleanupBody()

void http::HttpResponse::cleanupBody ( )
private

◆ getBodyType()

BodySourceType http::HttpResponse::getBodyType ( ) const

◆ getHeaders() [1/2]

HeaderMap & http::HttpResponse::getHeaders ( )

◆ getHeaders() [2/2]

HeaderMap const & http::HttpResponse::getHeaders ( ) const

◆ getResponsePhrase()

char const * http::HttpResponse::getResponsePhrase ( ) const

◆ getStatus()

Status http::HttpResponse::getStatus ( ) const

◆ getVersion()

std::string const & http::HttpResponse::getVersion ( ) const

◆ operator=()

HttpResponse const & http::HttpResponse::operator= ( HttpResponse const & rhs)

◆ setBodyFromCgi()

void http::HttpResponse::setBodyFromCgi ( int pipe_fd)

◆ setBodyFromFile() [1/2]

void http::HttpResponse::setBodyFromFile ( int fd,
size_t size )

◆ setBodyFromFile() [2/2]

void http::HttpResponse::setBodyFromFile ( int fd,
size_t size,
std::string const & mimeType )

◆ setBodyInMemory()

void http::HttpResponse::setBodyInMemory ( std::vector< char > const & body,
std::string const & mimeType )

◆ setNoBody()

void http::HttpResponse::setNoBody ( )

◆ setStatus()

void http::HttpResponse::setStatus ( Status s)

Member Data Documentation

◆ [union]

union { ... } http::HttpResponse

◆ bodyType_

BodySourceType http::HttpResponse::bodyType_
private

◆ [struct]

struct { ... } http::HttpResponse::cgiBody

Details for CGI-based bodies.

◆ data

std::vector<char>* http::HttpResponse::data

Pointer to the internal buffer holding the body.

◆ fd

int http::HttpResponse::fd

File descriptor to read from.

◆ [struct]

struct { ... } http::HttpResponse::fileBody

Details for file-based bodies.

◆ headers_

HeaderMap http::HttpResponse::headers_
private

◆ httpVersion_

std::string http::HttpResponse::httpVersion_
private

◆ [struct]

struct { ... } http::HttpResponse::inMemoryBody

Details for in-memory bodies.

◆ pipe_fd

int http::HttpResponse::pipe_fd

Pipe descriptor to read from.

◆ sent

size_t http::HttpResponse::sent

Tracks bytes sent by the Reactor.

◆ statusCode_

Status http::HttpResponse::statusCode_
private

◆ totalSize

size_t http::HttpResponse::totalSize

Total size of the file.


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