WebFramework v3.0.12
Web framework for C++.
Loading...
Searching...
No Matches
framework::HTTPResponse Class Reference

HTTPBuilder wrapper. More...

#include <HTTPResponse.h>

Public Member Functions

HTTPResponseoperator= (const web::HTTPBuilder &builder)
 Assign operator for HTTPBuilder.
 
void setHTTPVersion (const std::string &version)
 
void setResponseCode (web::responseCodes code)
 Set HTTP response code.
 
void addHeader (const std::string &name, const std::string &value)
 Set additional HTTP header.
 
void addBody (const std::string &body)
 
void addBody (const json::JSONBuilder &json)
 
void addBody (std::string &&body) noexcept
 
HTTPResponseappendBody (const std::string &body)
 
void addCookie (const std::string &name, const std::string &value)
 Add cookie to HTTP response.
 
void setDefault ()
 Clears HTTPResponse.
 
void setIsValid (bool isValid)
 
 operator bool () const
 

Static Public Member Functions

static std::string getFullDate ()
 Adds full date GMT to response.
 

Friends

streams::IOSocketStream & operator<< (streams::IOSocketStream &stream, HTTPResponse &response)
 Sending HTTPResponse through network.
 

Detailed Description

HTTPBuilder wrapper.

Overriding output stream operator for simplify HTTP response sending

Definition at line 14 of file HTTPResponse.h.

Constructor & Destructor Documentation

◆ HTTPResponse()

framework::HTTPResponse::HTTPResponse ( )

Definition at line 12 of file HTTPResponse.cpp.

Member Function Documentation

◆ addBody() [1/3]

void framework::HTTPResponse::addBody ( const json::JSONBuilder & json)

Some JSON data with HTTP response

Content-Length and Content-Type headers setting automatically

Parameters
jsonJSON data

Definition at line 47 of file HTTPResponse.cpp.

◆ addBody() [2/3]

void framework::HTTPResponse::addBody ( const std::string & body)

Some data with HTTP response

Content-Length header setting automatically

Parameters
bodydata

◆ addBody() [3/3]

void framework::HTTPResponse::addBody ( std::string && body)
noexcept

Some data with HTTP response

Content-Length header setting automatically

Parameters
bodydata

◆ addCookie()

void framework::HTTPResponse::addCookie ( const std::string & name,
const std::string & value )

Add cookie to HTTP response.

Parameters
nameof cookie
valueof cookie

Definition at line 69 of file HTTPResponse.cpp.

◆ addHeader()

void framework::HTTPResponse::addHeader ( const std::string & name,
const std::string & value )

Set additional HTTP header.

Parameters
nameof HTTP header
valueof HTTP header

Definition at line 34 of file HTTPResponse.cpp.

◆ appendBody()

HTTPResponse & framework::HTTPResponse::appendBody ( const std::string & body)

Some data with HTTP response

Content-Length header setting automatically

Parameters
bodydata
Returns
reference to self

Definition at line 62 of file HTTPResponse.cpp.

◆ getFullDate()

string framework::HTTPResponse::getFullDate ( )
static

Adds full date GMT to response.

Returns
date in following format 'day,' 'day of the month' 'name of the month' 'full year' 'hours:minutes:seconds' GMT

Definition at line 7 of file HTTPResponse.cpp.

◆ operator bool()

framework::HTTPResponse::operator bool ( ) const
explicit

isValid getter

Definition at line 93 of file HTTPResponse.cpp.

◆ operator=()

HTTPResponse & framework::HTTPResponse::operator= ( const web::HTTPBuilder & builder)

Assign operator for HTTPBuilder.

Parameters
builderyour HTTPBuilder
Returns
self for builder pattern

Definition at line 17 of file HTTPResponse.cpp.

◆ setDefault()

void framework::HTTPResponse::setDefault ( )

Clears HTTPResponse.

Definition at line 77 of file HTTPResponse.cpp.

◆ setHTTPVersion()

void framework::HTTPResponse::setHTTPVersion ( const std::string & version)

Set HTTP version

Default is HTTP/1.1

Parameters
versionfull HTTP version like HTTP/1.1

Definition at line 24 of file HTTPResponse.cpp.

◆ setIsValid()

void framework::HTTPResponse::setIsValid ( bool isValid)

Definition at line 88 of file HTTPResponse.cpp.

◆ setResponseCode()

void framework::HTTPResponse::setResponseCode ( web::responseCodes code)

Set HTTP response code.

Parameters
codevalue from web::responseCodes

Definition at line 29 of file HTTPResponse.cpp.

Friends And Related Symbol Documentation

◆ operator<<

streams::IOSocketStream & operator<< ( streams::IOSocketStream & stream,
HTTPResponse & response )
friend

Sending HTTPResponse through network.

Parameters
streamspecial class for sending data through network
responseclass instance
Returns
reference to self
Exceptions
web::WebException

Definition at line 98 of file HTTPResponse.cpp.


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