join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::HttpResponse Class Reference

HTTP response. More...

#include <httpmessage.hpp>

Inheritance diagram for join::HttpResponse:
Collaboration diagram for join::HttpResponse:

Public Member Functions

 HttpResponse ()=default
 create the HttpResponse instance.
 
 HttpResponse (const HttpResponse &other)
 create the HttpResponse instance by copy.
 
HttpResponseoperator= (const HttpResponse &other)
 assign the HttpResponse instance by copy.
 
 HttpResponse (HttpResponse &&other)
 create the HttpResponse instance by move.
 
HttpResponseoperator= (HttpResponse &&other)
 assign the HttpResponse instance by move.
 
virtual ~HttpResponse ()=default
 destroy the HttpResponse instance.
 
const std::string & status () const
 get HTTP response status.
 
const std::string & reason () const
 get HTTP response reason.
 
void response (const std::string &status, const std::string &reason={})
 set HTTP response status.
 
virtual void clear () override
 clear HTTP message.
 
virtual int writeHeaders (std::ostream &out) const override
 write HTTP headers to the given output stream.
 
- Public Member Functions inherited from join::HttpMessage
 HttpMessage ()
 create the HttpMessage instance.
 
 HttpMessage (const HttpMessage &other)
 create the HttpMessage instance by copy.
 
HttpMessageoperator= (const HttpMessage &other)
 assign the HttpMessage instance by copy.
 
 HttpMessage (HttpMessage &&other)
 create the HttpMessage instance by move.
 
HttpMessageoperator= (HttpMessage &&other)
 assign the HttpMessage instance by move.
 
virtual ~HttpMessage ()=default
 destroy the HttpMessage instance.
 
const std::string & version () const
 get HTTP version.
 
void version (const std::string &v)
 set HTTP version (default "HTTP/1.1").
 
bool hasHeader (const std::string &name) const
 checks if there is a header with the specified name.
 
std::string header (const std::string &name) const
 get header by name.
 
void header (const std::string &name, const std::string &val)
 add header to the HTTP request.
 
void header (const HeaderMap::value_type &h)
 add header to the HTTP request.
 
const HeaderMapheaders () const
 get headers map.
 
void headers (const HeaderMap &heads)
 add headers to the HTTP request.
 
std::string dumpHeaders () const
 dump headers.
 
size_t contentLength () const
 get content length.
 
virtual int readHeaders (std::istream &in)
 read HTTP header from the given input stream.
 

Protected Member Functions

virtual int parseFirstLine (const std::string &line) override
 parse first line.
 
- Protected Member Functions inherited from join::HttpMessage
virtual int parseHeader (const std::string &head)
 parse HTTP header.
 

Protected Attributes

std::string _status
 HTTP status.
 
std::string _reason
 HTTP reason.
 
- Protected Attributes inherited from join::HttpMessage
std::string _version
 HTTP version.
 
HeaderMap _headers
 HTTP headers.
 

Additional Inherited Members

- Public Types inherited from join::HttpMessage
using HeaderMap = std::map <std::string, std::string, details::lessNoCase>
 
- Static Protected Attributes inherited from join::HttpMessage
static const std::streamsize _maxHeaderLen = 2048
 HTTP max header size.
 

Detailed Description

HTTP response.

Constructor & Destructor Documentation

◆ HttpResponse() [1/3]

join::HttpResponse::HttpResponse ( )
default

create the HttpResponse instance.

◆ HttpResponse() [2/3]

HttpResponse::HttpResponse ( const HttpResponse & other)

create the HttpResponse instance by copy.

Parameters
otherrequest to copy.

◆ HttpResponse() [3/3]

HttpResponse::HttpResponse ( HttpResponse && other)

create the HttpResponse instance by move.

Parameters
otherrequest to move.

◆ ~HttpResponse()

virtual join::HttpResponse::~HttpResponse ( )
virtualdefault

destroy the HttpResponse instance.

Member Function Documentation

◆ clear()

void HttpResponse::clear ( )
overridevirtual

clear HTTP message.

Reimplemented from join::HttpMessage.

◆ operator=() [1/2]

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

assign the HttpResponse instance by copy.

Parameters
otherrequest to copy.
Returns
a reference of the current object.

◆ operator=() [2/2]

HttpResponse & HttpResponse::operator= ( HttpResponse && other)

assign the HttpResponse instance by move.

Parameters
otherrequest to move.
Returns
a reference of the current object.

◆ parseFirstLine()

int HttpResponse::parseFirstLine ( const std::string & line)
overrideprotectedvirtual

parse first line.

Parameters
linefirst line to parse.
Returns
0 on success, -1 on failure.

Implements join::HttpMessage.

◆ reason()

const std::string & HttpResponse::reason ( ) const

get HTTP response reason.

Returns
HTTP response reason.

◆ response()

void HttpResponse::response ( const std::string & status,
const std::string & reason = {} )

set HTTP response status.

Parameters
statusHTTP status.
reasonHTTP reason.

◆ status()

const std::string & HttpResponse::status ( ) const

get HTTP response status.

Returns
HTTP response status.

◆ writeHeaders()

int HttpResponse::writeHeaders ( std::ostream & out) const
overridevirtual

write HTTP headers to the given output stream.

Parameters
outoutput stream.
Returns
0 on success, -1 on failure.

Implements join::HttpMessage.

Member Data Documentation

◆ _reason

std::string join::HttpResponse::_reason
protected

HTTP reason.

◆ _status

std::string join::HttpResponse::_status
protected

HTTP status.


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