fastcgi++
A C++ FastCGI/Web API
Classes | Enumerations | Functions | Variables
Fastcgipp::Http Namespace Reference

Defines classes and functions relating to the HTTP protocol. More...

Classes

class  Address
 Efficiently stores IPv6 addresses. More...
 
struct  Environment
 Data structure of HTTP environment data. More...
 
struct  File
 Holds a file uploaded from the client. More...
 
class  SessionId
 Defines ID values for HTTP sessions. More...
 
class  Sessions
 Container for HTTP sessions. More...
 

Enumerations

enum  RequestMethod {
  RequestMethod::ERROR =0, RequestMethod::HEAD =1, RequestMethod::GET =2, RequestMethod::POST =3,
  RequestMethod::PUT =4, RequestMethod::DELETE =5, RequestMethod::TRACE =6, RequestMethod::OPTIONS =7,
  RequestMethod::CONNECT =8
}
 The HTTP request method as an enumeration. More...
 

Functions

template<class charT , class Traits >
std::basic_ostream< charT, Traits > & operator<< (std::basic_ostream< charT, Traits > &os, const RequestMethod requestMethod)
 
template<class charT , class Traits >
std::basic_ostream< charT, Traits > & operator<< (std::basic_ostream< charT, Traits > &os, const Address &address)
 Address stream insertion operation. More...
 
template<class charT , class Traits >
std::basic_istream< charT, Traits > & operator>> (std::basic_istream< charT, Traits > &is, Address &address)
 Address stream extractor operation. More...
 
void vecToString (const char *start, const char *end, std::wstring &string)
 Convert a char array to a std::wstring. More...
 
void vecToString (const char *start, const char *end, std::string &string)
 Convert a char string to a std::string. More...
 
template<class charT >
int atoi (const charT *start, const charT *end)
 Convert a char string to an integer. More...
 
template<class charT >
float atof (const charT *start, const charT *end)
 Convert a char string to a float. More...
 
template<class charT >
void decodeUrlEncoded (const char *data, const char *dataEnd, std::multimap< std::basic_string< charT >, std::basic_string< charT >> &output, const char *const fieldSeparator="&")
 Decodes a url-encoded string into a multimap container. More...
 
char * percentEscapedToRealBytes (const char *start, const char *end, char *destination)
 Convert a string with percent escaped byte values to their values. More...
 
template<class In , class Out >
Out base64Encode (In start, In end, Out destination)
 Convert a binary container of data to a Base64 encoded container. More...
 
template<class In , class Out >
Out base64Decode (In start, In end, Out destination)
 Convert a Base64 encoded container to a binary container. More...
 
template<class charT , class Traits >
std::basic_ostream< charT, Traits > & operator<< (std::basic_ostream< charT, Traits > &os, const SessionId &x)
 Output the ID data in base64 encoding. More...
 

Variables

const std::array< const char *const, 9 > requestMethodLabels
 Some textual labels for RequestMethod. More...
 
const std::array< const char, 64 > base64Characters
 List of characters in order for Base64 encoding. More...
 

Detailed Description

Defines classes and functions relating to the HTTP protocol.

Enumeration Type Documentation

◆ RequestMethod

The HTTP request method as an enumeration.

Enumerator
ERROR 
HEAD 
GET 
POST 
PUT 
DELETE 
TRACE 
OPTIONS 
CONNECT 

Definition at line 91 of file http.hpp.

Function Documentation

◆ atof()

template<class charT >
float Fastcgipp::Http::atof ( const charT *  start,
const charT *  end 
)

Convert a char string to a float.

This function is very similar to std::atof() except that it takes start/end values of a non null terminated char string instead of a null terminated string. The first character must be either a number or a minus sign (-). As soon as the end is reached or a non numerical character is reached, the result is tallied and returned.

Parameters
[in]startPointer to the first byte in the string
[in]endPointer to the last byte in the string + 1
Returns
Float value represented by the string
Template Parameters
charTCharacter type

Definition at line 81 of file http.cpp.

◆ atoi()

template<class charT >
int Fastcgipp::Http::atoi ( const charT *  start,
const charT *  end 
)

Convert a char string to an integer.

This function is very similar to std::atoi() except that it takes start/end values of a non null terminated char string instead of a null terminated string. The first character must be either a number or a minus sign (-). As soon as the end is reached or a non numerical character is reached, the result is tallied and returned.

Parameters
[in]startPointer to the first byte in the string
[in]endPointer to the last byte in the string + 1
Returns
Integer value represented by the string
Template Parameters
charTCharacter type

Definition at line 61 of file http.cpp.

Referenced by Fastcgipp::Http::Address::assign(), and Fastcgipp::Http::Environment< charT >::fill().

◆ base64Decode()

template<class In , class Out >
Out Fastcgipp::Http::base64Decode ( In  start,
In  end,
Out  destination 
)

Convert a Base64 encoded container to a binary container.

If destination is a fixed size container, it should have a size of at least (end-start)*3/4 not including null terminators if used.

Parameters
[in]startIterator to start of Base64 data.
[in]endIterator to end of Base64 data.
[out]destinationIterator to start of binary destination.
Template Parameters
InInput iterator type. Should be dereferenced to type char.
OutOutput iterator type. Should be dereferenced to type char.
Returns
Iterator to last position written+1 (The normal end() iterator). If the return value equals destination, an error occurred.

Definition at line 725 of file http.hpp.

Referenced by Fastcgipp::Http::SessionId::SessionId().

◆ base64Encode()

template<class In , class Out >
Out Fastcgipp::Http::base64Encode ( In  start,
In  end,
Out  destination 
)

Convert a binary container of data to a Base64 encoded container.

If destination is a fixed size container, it should have a size of at least ((end-start-1)/3 + 1)*4 not including null terminators if used and assuming integer arithmetic.

Parameters
[in]startIterator to start of binary data.
[in]endIterator to end of binary data.
[out]destinationIterator to start of Base64 destination.
Template Parameters
InInput iterator type. Should be dereferenced to type char.
OutOutput iterator type. Should be dereferenced to type char.
Returns
Iterator to last position written+1 (The normal end() iterator).

Definition at line 769 of file http.hpp.

References base64Characters.

Referenced by operator<<().

◆ decodeUrlEncoded()

template<class charT >
void Fastcgipp::Http::decodeUrlEncoded ( const char *  data,
const char *  dataEnd,
std::multimap< std::basic_string< charT >, std::basic_string< charT >> &  output,
const char *const  fieldSeparator = "&" 
)

Decodes a url-encoded string into a multimap container.

Parameters
[in]dataData to decode
[in]dataEnd+1 last byte to decode
[out]outputContainer to output data into
[in]fieldSeparatorString that signifies field separation

Definition at line 670 of file http.cpp.

References Fastcgipp::NONE, percentEscapedToRealBytes(), and vecToString().

Referenced by Fastcgipp::Http::Environment< charT >::fill(), and Fastcgipp::Http::Environment< charT >::parsePostsUrlEncoded().

◆ operator<<() [1/3]

template<class charT , class Traits >
std::basic_ostream< charT, Traits > & Fastcgipp::Http::operator<< ( std::basic_ostream< charT, Traits > &  os,
const Address address 
)

Address stream insertion operation.

This stream inserter obeys all stream manipulators regarding alignment, field width and numerical base.

Definition at line 924 of file http.cpp.

References Fastcgipp::Http::Address::m_data, and Fastcgipp::Http::Address::size.

◆ operator<<() [2/3]

template<class charT , class Traits >
std::basic_ostream<charT, Traits>& Fastcgipp::Http::operator<< ( std::basic_ostream< charT, Traits > &  os,
const RequestMethod  requestMethod 
)
inline

Definition at line 108 of file http.hpp.

◆ operator<<() [3/3]

template<class charT , class Traits >
std::basic_ostream<charT, Traits>& Fastcgipp::Http::operator<< ( std::basic_ostream< charT, Traits > &  os,
const SessionId x 
)

Output the ID data in base64 encoding.

Definition at line 613 of file http.hpp.

References base64Encode(), and Fastcgipp::Http::SessionId::m_data.

◆ operator>>()

template<class charT , class Traits >
std::basic_istream< charT, Traits > & Fastcgipp::Http::operator>> ( std::basic_istream< charT, Traits > &  is,
Address address 
)

Address stream extractor operation.

In order for this to work the string must represent either an IPv4 address in standard textual decimal form (127.0.0.1) or an IPv6 in standard form.

Definition at line 1106 of file http.cpp.

References Fastcgipp::Http::Address::size.

◆ percentEscapedToRealBytes()

char * Fastcgipp::Http::percentEscapedToRealBytes ( const char *  start,
const char *  end,
char *  destination 
)

Convert a string with percent escaped byte values to their values.

Since converting a percent escaped string to actual values can only make it shorter, it is safe to assume that the return value will always be smaller than size. It is thereby a safe move to make the destination block of memory the same size as the source.

Parameters
[in]startIterator to the first character in the percent escaped string
[in]endIterator to +1 the last character in the percent escaped string
[out]destinationPointer to the section of memory to write the converted string to
Returns
Iterator to +1 the last character written

Definition at line 116 of file http.cpp.

Referenced by decodeUrlEncoded(), and Fastcgipp::Http::Environment< charT >::fill().

◆ vecToString() [1/2]

void Fastcgipp::Http::vecToString ( const char *  start,
const char *  end,
std::wstring &  string 
)

Convert a char array to a std::wstring.

Parameters
[in]startFirst byte in char array
[in]end1+ last byte of the array (no null terminator)
[out]stringReference to the wstring that should be modified

Definition at line 40 of file http.cpp.

References WARNING_LOG.

Referenced by decodeUrlEncoded(), Fastcgipp::Http::Environment< charT >::fill(), and Fastcgipp::Http::Environment< charT >::parsePostsMultipart().

◆ vecToString() [2/2]

void Fastcgipp::Http::vecToString ( const char *  start,
const char *  end,
std::string &  string 
)
inline

Convert a char string to a std::string.

Parameters
[in]startFirst byte in char string
[in]end1+ last byte of the string (no null terminator)
[out]stringReference to the string that should be modified

Definition at line 425 of file http.hpp.

Variable Documentation

◆ base64Characters

const std::array< const char, 64 > Fastcgipp::Http::base64Characters
Initial value:
=
{{
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S',
'T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l',
'm','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4',
'5','6','7','8','9','+','/'
}}

List of characters in order for Base64 encoding.

Definition at line 751 of file http.cpp.

Referenced by base64Encode().

◆ requestMethodLabels

const std::array< const char *const, 9 > Fastcgipp::Http::requestMethodLabels
Initial value:
=
{{
"ERROR",
"HEAD",
"GET",
"POST",
"PUT",
"DELETE",
"TRACE",
"OPTIONS",
"CONNECT"
}}

Some textual labels for RequestMethod.

Definition at line 759 of file http.cpp.

Referenced by Fastcgipp::Http::Environment< charT >::fill().