CppServer  1.0.4.0
C++ Server Library
Public Member Functions | Friends | List of all members
CppServer::HTTP::HTTPRequest Class Reference

HTTP request. More...

#include <http_request.h>

Public Member Functions

 HTTPRequest ()
 Initialize an empty HTTP request. More...
 
 HTTPRequest (std::string_view method, std::string_view url, std::string_view protocol="HTTP/1.1")
 Initialize a new HTTP request with a given method, URL and protocol. More...
 
 HTTPRequest (const HTTPRequest &)=default
 
 HTTPRequest (HTTPRequest &&)=default
 
 ~HTTPRequest ()=default
 
HTTPRequestoperator= (const HTTPRequest &)=default
 
HTTPRequestoperator= (HTTPRequest &&)=default
 
bool empty () const noexcept
 Is the HTTP request empty? More...
 
bool error () const noexcept
 Is the HTTP request error flag set? More...
 
std::string_view method () const noexcept
 Get the HTTP request method. More...
 
std::string_view url () const noexcept
 Get the HTTP request URL. More...
 
std::string_view protocol () const noexcept
 Get the HTTP request protocol version. More...
 
size_t headers () const noexcept
 Get the HTTP request headers count. More...
 
std::tuple< std::string_view, std::string_view > header (size_t i) const noexcept
 Get the HTTP request header by index. More...
 
size_t cookies () const noexcept
 Get the HTTP request cookies count. More...
 
std::tuple< std::string_view, std::string_view > cookie (size_t i) const noexcept
 Get the HTTP request cookie by index. More...
 
std::string_view body () const noexcept
 Get the HTTP request body. More...
 
size_t body_length () const noexcept
 Get the HTTP request body length. More...
 
const std::string & cache () const noexcept
 Get the HTTP request cache content. More...
 
std::string string () const
 Get string from the current HTTP request. More...
 
HTTPRequestClear ()
 Clear the HTTP request cache. More...
 
HTTPRequestSetBegin (std::string_view method, std::string_view url, std::string_view protocol="HTTP/1.1")
 Set the HTTP request begin with a given method, URL and protocol. More...
 
HTTPRequestSetHeader (std::string_view key, std::string_view value)
 Set the HTTP request header. More...
 
HTTPRequestSetCookie (std::string_view name, std::string_view value)
 Set the HTTP request cookie. More...
 
HTTPRequestAddCookie (std::string_view name, std::string_view value)
 Add the HTTP request cookie. More...
 
HTTPRequestSetBody (std::string_view body="")
 Set the HTTP request body. More...
 
HTTPRequestSetBodyLength (size_t length)
 Set the HTTP request body length. More...
 
HTTPRequestMakeHeadRequest (std::string_view url)
 Make HEAD request. More...
 
HTTPRequestMakeGetRequest (std::string_view url)
 Make GET request. More...
 
HTTPRequestMakePostRequest (std::string_view url, std::string_view content, std::string_view content_type="text/plain; charset=UTF-8")
 Make POST request. More...
 
HTTPRequestMakePutRequest (std::string_view url, std::string_view content, std::string_view content_type="text/plain; charset=UTF-8")
 Make PUT request. More...
 
HTTPRequestMakeDeleteRequest (std::string_view url)
 Make DELETE request. More...
 
HTTPRequestMakeOptionsRequest (std::string_view url)
 Make OPTIONS request. More...
 
HTTPRequestMakeTraceRequest (std::string_view url)
 Make TRACE request. More...
 
void swap (HTTPRequest &request) noexcept
 Swap two instances. More...
 

Friends

class HTTPSession
 
class HTTPSSession
 
std::ostream & operator<< (std::ostream &os, const HTTPRequest &request)
 Output instance into the given output stream. More...
 
void swap (HTTPRequest &request1, HTTPRequest &request2) noexcept
 

Detailed Description

HTTP request.

HTTP request is used to create or process parameters of HTTP protocol request (method, URL, headers, etc).

Not thread-safe.

Examples
http_server.cpp, https_server.cpp, ws_chat_client.cpp, ws_chat_server.cpp, wss_chat_client.cpp, and wss_chat_server.cpp.

Definition at line 30 of file http_request.h.

Constructor & Destructor Documentation

◆ HTTPRequest() [1/4]

CppServer::HTTP::HTTPRequest::HTTPRequest ( )
inline

Initialize an empty HTTP request.

Definition at line 37 of file http_request.h.

◆ HTTPRequest() [2/4]

CppServer::HTTP::HTTPRequest::HTTPRequest ( std::string_view  method,
std::string_view  url,
std::string_view  protocol = "HTTP/1.1" 
)
inline

Initialize a new HTTP request with a given method, URL and protocol.

Parameters
method- HTTP method
url- Requested URL
protocol- Protocol version (default is "HTTP/1.1")

Definition at line 44 of file http_request.h.

◆ HTTPRequest() [3/4]

CppServer::HTTP::HTTPRequest::HTTPRequest ( const HTTPRequest )
default

◆ HTTPRequest() [4/4]

CppServer::HTTP::HTTPRequest::HTTPRequest ( HTTPRequest &&  )
default

◆ ~HTTPRequest()

CppServer::HTTP::HTTPRequest::~HTTPRequest ( )
default

Member Function Documentation

◆ AddCookie()

HTTPRequest & CppServer::HTTP::HTTPRequest::AddCookie ( std::string_view  name,
std::string_view  value 
)

Add the HTTP request cookie.

Parameters
name- Cookie name
value- Cookie value

Definition at line 155 of file http_request.cpp.

◆ body()

std::string_view CppServer::HTTP::HTTPRequest::body ( ) const
inlinenoexcept

Get the HTTP request body.

Examples
http_server.cpp, and https_server.cpp.

Definition at line 72 of file http_request.h.

◆ body_length()

size_t CppServer::HTTP::HTTPRequest::body_length ( ) const
inlinenoexcept

Get the HTTP request body length.

Definition at line 74 of file http_request.h.

◆ cache()

const std::string& CppServer::HTTP::HTTPRequest::cache ( ) const
inlinenoexcept

Get the HTTP request cache content.

Examples
http_server.cpp, and https_server.cpp.

Definition at line 77 of file http_request.h.

◆ Clear()

HTTPRequest & CppServer::HTTP::HTTPRequest::Clear ( )

Clear the HTTP request cache.

Definition at line 41 of file http_request.cpp.

◆ cookie()

std::tuple< std::string_view, std::string_view > CppServer::HTTP::HTTPRequest::cookie ( size_t  i) const
noexcept

Get the HTTP request cookie by index.

Definition at line 30 of file http_request.cpp.

◆ cookies()

size_t CppServer::HTTP::HTTPRequest::cookies ( ) const
inlinenoexcept

Get the HTTP request cookies count.

Definition at line 68 of file http_request.h.

◆ empty()

bool CppServer::HTTP::HTTPRequest::empty ( ) const
inlinenoexcept

Is the HTTP request empty?

Definition at line 53 of file http_request.h.

◆ error()

bool CppServer::HTTP::HTTPRequest::error ( ) const
inlinenoexcept

Is the HTTP request error flag set?

Definition at line 55 of file http_request.h.

◆ header()

std::tuple< std::string_view, std::string_view > CppServer::HTTP::HTTPRequest::header ( size_t  i) const
noexcept

Get the HTTP request header by index.

Definition at line 19 of file http_request.cpp.

◆ headers()

size_t CppServer::HTTP::HTTPRequest::headers ( ) const
inlinenoexcept

Get the HTTP request headers count.

Definition at line 64 of file http_request.h.

◆ MakeDeleteRequest()

HTTPRequest & CppServer::HTTP::HTTPRequest::MakeDeleteRequest ( std::string_view  url)

Make DELETE request.

Parameters
url- URL to request
Returns
HTTP request

Definition at line 247 of file http_request.cpp.

◆ MakeGetRequest()

HTTPRequest & CppServer::HTTP::HTTPRequest::MakeGetRequest ( std::string_view  url)

Make GET request.

Parameters
url- URL to request
Returns
HTTP request

Definition at line 219 of file http_request.cpp.

◆ MakeHeadRequest()

HTTPRequest & CppServer::HTTP::HTTPRequest::MakeHeadRequest ( std::string_view  url)

Make HEAD request.

Parameters
url- URL to request
Returns
HTTP request

Definition at line 211 of file http_request.cpp.

◆ MakeOptionsRequest()

HTTPRequest & CppServer::HTTP::HTTPRequest::MakeOptionsRequest ( std::string_view  url)

Make OPTIONS request.

Parameters
url- URL to request
Returns
HTTP request

Definition at line 255 of file http_request.cpp.

◆ MakePostRequest()

HTTPRequest & CppServer::HTTP::HTTPRequest::MakePostRequest ( std::string_view  url,
std::string_view  content,
std::string_view  content_type = "text/plain; charset=UTF-8" 
)

Make POST request.

Parameters
url- URL to request
content- Content
content_type- Content type (default is "text/plain; charset=UTF-8")
Returns
HTTP request

Definition at line 227 of file http_request.cpp.

◆ MakePutRequest()

HTTPRequest & CppServer::HTTP::HTTPRequest::MakePutRequest ( std::string_view  url,
std::string_view  content,
std::string_view  content_type = "text/plain; charset=UTF-8" 
)

Make PUT request.

Parameters
url- URL to request
content- Content
content_type- Content type (default is "text/plain; charset=UTF-8")
Returns
HTTP request

Definition at line 237 of file http_request.cpp.

◆ MakeTraceRequest()

HTTPRequest & CppServer::HTTP::HTTPRequest::MakeTraceRequest ( std::string_view  url)

Make TRACE request.

Parameters
url- URL to request
Returns
HTTP request

Definition at line 263 of file http_request.cpp.

◆ method()

std::string_view CppServer::HTTP::HTTPRequest::method ( ) const
inlinenoexcept

Get the HTTP request method.

Examples
http_server.cpp, and https_server.cpp.

Definition at line 58 of file http_request.h.

◆ operator=() [1/2]

HTTPRequest& CppServer::HTTP::HTTPRequest::operator= ( const HTTPRequest )
default

◆ operator=() [2/2]

HTTPRequest& CppServer::HTTP::HTTPRequest::operator= ( HTTPRequest &&  )
default

◆ protocol()

std::string_view CppServer::HTTP::HTTPRequest::protocol ( ) const
inlinenoexcept

Get the HTTP request protocol version.

Definition at line 62 of file http_request.h.

◆ SetBegin()

HTTPRequest & CppServer::HTTP::HTTPRequest::SetBegin ( std::string_view  method,
std::string_view  url,
std::string_view  protocol = "HTTP/1.1" 
)

Set the HTTP request begin with a given method, URL and protocol.

Parameters
method- HTTP method
url- Requested URL
protocol- Protocol version (default is "HTTP/1.1")
Examples
ws_chat_client.cpp, and wss_chat_client.cpp.

Definition at line 62 of file http_request.cpp.

◆ SetBody()

HTTPRequest & CppServer::HTTP::HTTPRequest::SetBody ( std::string_view  body = "")

Set the HTTP request body.

Parameters
body- Body content (default is "")

Definition at line 174 of file http_request.cpp.

◆ SetBodyLength()

HTTPRequest & CppServer::HTTP::HTTPRequest::SetBodyLength ( size_t  length)

Set the HTTP request body length.

Parameters
length- Body length

Definition at line 193 of file http_request.cpp.

◆ SetCookie()

HTTPRequest & CppServer::HTTP::HTTPRequest::SetCookie ( std::string_view  name,
std::string_view  value 
)

Set the HTTP request cookie.

Parameters
name- Cookie name
value- Cookie value

Definition at line 118 of file http_request.cpp.

◆ SetHeader()

HTTPRequest & CppServer::HTTP::HTTPRequest::SetHeader ( std::string_view  key,
std::string_view  value 
)

Set the HTTP request header.

Parameters
key- Header key
value- Header value
Examples
ws_chat_client.cpp, and wss_chat_client.cpp.

Definition at line 94 of file http_request.cpp.

◆ string()

std::string CppServer::HTTP::HTTPRequest::string ( ) const
inline

Get string from the current HTTP request.

Definition at line 80 of file http_request.h.

◆ swap()

void CppServer::HTTP::HTTPRequest::swap ( HTTPRequest request)
noexcept

Swap two instances.

Definition at line 626 of file http_request.cpp.

◆ url()

std::string_view CppServer::HTTP::HTTPRequest::url ( ) const
inlinenoexcept

Get the HTTP request URL.

Examples
http_server.cpp, and https_server.cpp.

Definition at line 60 of file http_request.h.

Friends And Related Function Documentation

◆ HTTPSession

friend class HTTPSession
friend

Definition at line 32 of file http_request.h.

◆ HTTPSSession

friend class HTTPSSession
friend

Definition at line 33 of file http_request.h.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const HTTPRequest request 
)
friend

Output instance into the given output stream.

Definition at line 610 of file http_request.cpp.

◆ swap

void swap ( HTTPRequest request1,
HTTPRequest request2 
)
friend

Definition at line 173 of file http_request.h.


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