HTTP module

Response

HTTP response message with status, reason phrase, headers, and body metadata.

Response

#include <icy/http/response.h>

Inherits: Message

HTTP response message with status, reason phrase, headers, and body metadata.

Public Methods

ReturnNameDescription
ResponseCreates the Response with OK status.
ResponseCreates the Response with the given status and reason phrase.
ResponseCreates the Response with the given version, status and reason phrase.
ResponseCreates the Response with the given status and an appropriate reason phrase.
ResponseCreates the Response with the given version, status and an appropriate reason phrase.
~Response virtualDestroys the Response.
voidsetStatusSets the HTTP status code.
StatusCodegetStatus constReturns the HTTP status code.
voidsetReasonSets the HTTP reason phrase.
const std::string &getReason constReturns the HTTP reason phrase.
voidsetStatusAndReasonSets the HTTP status code and reason phrase.
voidsetDateSets the Date header to the given date/time value.
TimestampgetDate constReturns the value of the Date header.
voidaddCookieAdds the cookie to the response by adding a Set-Cookie header.
voidgetCookies constReturns a vector with all the cookies set in the response header.
voidwrite virtual constWrites the HTTP response headers to the given output stream.
voidwrite virtual constWrites the HTTP response headers to the given output string.
voidwrite virtual constWrites the HTTP response headers directly into a byte buffer.
boolsuccess virtual constReturns true if the HTTP response code was successful (< 400).

Response

Response()

Creates the Response with OK status.


Response

Response(StatusCode status, const std::string & reason)

Creates the Response with the given status and reason phrase.


Response

Response(const std::string & version, StatusCode status, const std::string & reason)

Creates the Response with the given version, status and reason phrase.


Response

Response(StatusCode status)

Creates the Response with the given status and an appropriate reason phrase.


Response

Response(const std::string & version, StatusCode status)

Creates the Response with the given version, status and an appropriate reason phrase.


~Response

virtual

virtual ~Response()

Destroys the Response.


setStatus

void setStatus(StatusCode status)

Sets the HTTP status code.

The reason phrase is set according to the status code.


getStatus

const

StatusCode getStatus() const

Returns the HTTP status code.


setReason

void setReason(const std::string & reason)

Sets the HTTP reason phrase.


getReason

const

const std::string & getReason() const

Returns the HTTP reason phrase.


setStatusAndReason

void setStatusAndReason(StatusCode status, const std::string & reason)

Sets the HTTP status code and reason phrase.


setDate

void setDate(const Timestamp & dateTime)

Sets the Date header to the given date/time value.


getDate

const

Timestamp getDate() const

Returns the value of the Date header.


addCookie

void addCookie(const Cookie & cookie)

Adds the cookie to the response by adding a Set-Cookie header.


getCookies

const

void getCookies(std::vector< Cookie > & cookies) const

Returns a vector with all the cookies set in the response header.

May throw an exception in case of a malformed Set-Cookie header.


write

virtual const

virtual void write(std::ostream & ostr) const

Writes the HTTP response headers to the given output stream.


write

virtual const

virtual void write(std::string & str) const

Writes the HTTP response headers to the given output string.


write

virtual const

virtual void write(Buffer & buf) const

Writes the HTTP response headers directly into a byte buffer.


success

virtual const

virtual bool success() const

Returns true if the HTTP response code was successful (< 400).

Private Attributes

ReturnNameDescription
StatusCode_status
std::string_reason

_status

StatusCode _status

_reason

std::string _reason