join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::HttpMessage Class Referenceabstract

HTTP message. More...

#include <httpmessage.hpp>

Inheritance diagram for join::HttpMessage:

Public Types

using HeaderMap = std::map <std::string, std::string, details::lessNoCase>
 

Public Member Functions

 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 void clear ()
 clear HTTP message.
 
virtual int readHeaders (std::istream &in)
 read HTTP header from the given input stream.
 
virtual int writeHeaders (std::ostream &out) const =0
 write HTTP headers to the given output stream.
 

Protected Member Functions

virtual int parseFirstLine (const std::string &line)=0
 parse first line.
 
virtual int parseHeader (const std::string &head)
 parse HTTP header.
 

Protected Attributes

std::string _version
 HTTP version.
 
HeaderMap _headers
 HTTP headers.
 

Static Protected Attributes

static const std::streamsize _maxHeaderLen = 2048
 HTTP max header size.
 

Detailed Description

HTTP message.

Member Typedef Documentation

◆ HeaderMap

using join::HttpMessage::HeaderMap = std::map <std::string, std::string, details::lessNoCase>

Constructor & Destructor Documentation

◆ HttpMessage() [1/3]

HttpMessage::HttpMessage ( )

create the HttpMessage instance.

◆ HttpMessage() [2/3]

HttpMessage::HttpMessage ( const HttpMessage & other)

create the HttpMessage instance by copy.

Parameters
otherrequest to copy.

◆ HttpMessage() [3/3]

HttpMessage::HttpMessage ( HttpMessage && other)

create the HttpMessage instance by move.

Parameters
otherrequest to move.

◆ ~HttpMessage()

virtual join::HttpMessage::~HttpMessage ( )
virtualdefault

destroy the HttpMessage instance.

Member Function Documentation

◆ clear()

void HttpMessage::clear ( )
virtual

clear HTTP message.

Reimplemented in join::HttpRequest, and join::HttpResponse.

◆ contentLength()

size_t HttpMessage::contentLength ( ) const

get content length.

Returns
content length.

◆ dumpHeaders()

std::string HttpMessage::dumpHeaders ( ) const

dump headers.

Returns
headers.

◆ hasHeader()

bool HttpMessage::hasHeader ( const std::string & name) const

checks if there is a header with the specified name.

Parameters
namename of the header to search for.
Returns
true of there is such a header, false otherwise.

◆ header() [1/3]

void HttpMessage::header ( const HeaderMap::value_type & h)

add header to the HTTP request.

Parameters
hheader.

◆ header() [2/3]

std::string HttpMessage::header ( const std::string & name) const

get header by name.

Parameters
nameheader name.
Returns
header value.

◆ header() [3/3]

void HttpMessage::header ( const std::string & name,
const std::string & val )

add header to the HTTP request.

Parameters
nameheader name.
valheader value.

◆ headers() [1/2]

const HttpMessage::HeaderMap & HttpMessage::headers ( ) const

get headers map.

Returns
headers map.

◆ headers() [2/2]

void HttpMessage::headers ( const HeaderMap & heads)

add headers to the HTTP request.

Parameters
headsheaders.

◆ operator=() [1/2]

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

assign the HttpMessage instance by copy.

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

◆ operator=() [2/2]

HttpMessage & HttpMessage::operator= ( HttpMessage && other)

assign the HttpMessage instance by move.

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

◆ parseFirstLine()

virtual int join::HttpMessage::parseFirstLine ( const std::string & line)
protectedpure virtual

parse first line.

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

Implemented in join::HttpRequest, and join::HttpResponse.

◆ parseHeader()

int HttpMessage::parseHeader ( const std::string & head)
protectedvirtual

parse HTTP header.

Parameters
headHTTP header to parse.
Returns
0 on success, -1 on failure.

◆ readHeaders()

int HttpMessage::readHeaders ( std::istream & in)
virtual

read HTTP header from the given input stream.

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

◆ version() [1/2]

const std::string & HttpMessage::version ( ) const

get HTTP version.

Returns
HTTP version.

◆ version() [2/2]

void HttpMessage::version ( const std::string & v)

set HTTP version (default "HTTP/1.1").

Parameters
vHTTP version.

◆ writeHeaders()

virtual int join::HttpMessage::writeHeaders ( std::ostream & out) const
pure virtual

write HTTP headers to the given output stream.

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

Implemented in join::HttpRequest, and join::HttpResponse.

Member Data Documentation

◆ _headers

HeaderMap join::HttpMessage::_headers
protected

HTTP headers.

◆ _maxHeaderLen

const std::streamsize join::HttpMessage::_maxHeaderLen = 2048
staticprotected

HTTP max header size.

◆ _version

std::string join::HttpMessage::_version
protected

HTTP version.


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