RESTinio
Namespaces | Classes | Typedefs | Functions
restinio::http_field_parsers Namespace Reference

Namespaces

 accept_language_details
 
 authorization_details
 
 basic_auth
 
 bearer_auth
 
 content_disposition_details
 
 details
 
 host_details
 
 impl
 
 qvalue_details
 
 range_details
 
 try_extract_field_details
 

Classes

struct  accept_charset_value_t
 Tools for working with the value of Accept-Charset HTTP-field. More...
 
struct  accept_encoding_value_t
 Tools for working with the value of Accept-Encoding HTTP-field. More...
 
struct  accept_language_value_t
 Tools for working with the value of Accept-Language HTTP-field. More...
 
struct  accept_value_t
 Tools for working with the value of Accept HTTP-field. More...
 
struct  authorization_value_t
 Tools for working with the value of Authorization HTTP-field. More...
 
struct  cache_control_value_t
 Tools for working with the value of Cache-Control HTTP-field. More...
 
struct  connection_value_t
 Tools for working with the value of Connection HTTP-field. More...
 
struct  content_disposition_value_t
 Tools for working with the value of Content-Disposition HTTP-field. More...
 
struct  content_encoding_value_t
 Tools for working with the value of Content-Encoding HTTP-field. More...
 
struct  content_type_value_t
 Tools for working with the value of Content-Type HTTP-field. More...
 
struct  field_not_found_t
 A special type to be returned in the case if HTTP-field isn't found in a request. More...
 
struct  media_type_value_t
 Tools for working with media-type in HTTP-fields. More...
 
struct  not_found_t
 An empty type to be used as indicator of negative search result. More...
 
class  qvalue_t
 A class for holding the parsed value of qvalue from RFC7231. More...
 
struct  range_value_t
 Tools for working with the value of Range HTTP-field. More...
 
struct  raw_host_value_t
 Tools for working with the raw value of Host HTTP-field. More...
 
struct  transfer_encoding_value_t
 Tools for working with the value of Transfer-Encoding HTTP-field. More...
 
struct  user_agent_value_t
 Tools for working with the value of User-Agent HTTP-field. More...
 

Typedefs

using parameter_with_mandatory_value_t = std::pair< std::string, std::string >
 A type that describes a parameter with mandatory value. More...
 
using parameter_with_mandatory_value_container_t = std::vector< parameter_with_mandatory_value_t >
 A type of container for parameters with mandatory values. More...
 
using parameter_with_optional_value_t = std::pair< std::string, std::optional< std::string > >
 A type that describes a parameter with optional value. More...
 
using parameter_with_optional_value_container_t = std::vector< parameter_with_optional_value_t >
 A type of container for parameters with optional values. More...
 

Functions

std::ostream & operator<< (std::ostream &to, const authorization_value_t::param_value_t &v)
 
std::ostream & operator<< (std::ostream &to, const authorization_value_t::param_t &v)
 
std::ostream & operator<< (std::ostream &to, const authorization_value_t::auth_param_t &p)
 
std::ostream & operator<< (std::ostream &to, const authorization_value_t &v)
 
bool operator== (const qvalue_t &a, const qvalue_t &b) noexcept
 
bool operator!= (const qvalue_t &a, const qvalue_t &b) noexcept
 
bool operator< (const qvalue_t &a, const qvalue_t &b) noexcept
 
bool operator<= (const qvalue_t &a, const qvalue_t &b) noexcept
 
auto alpha_symbol_p ()
 A factory for producer of ALPHA symbols. More...
 
auto alphanum_symbol_p ()
 A factory for producer of symbol that an ALPHA or DIGIT. More...
 
auto vchar_symbol_p ()
 A factory for producer of VCHAR symbols. More...
 
auto ctext_symbol_p ()
 A factory for producer of ctext symbols. More...
 
auto comment_p ()
 A factory for producer of comment token. More...
 
auto ows_p () noexcept
 A factory function to create an ows_producer. More...
 
auto ows () noexcept
 A factory function to create an OWS clause. More...
 
auto token_symbol_p () noexcept
 A factory for producer of symbols than can be used in tokens. More...
 
auto token_p () noexcept
 A factory function to create a token_producer. More...
 
auto quoted_string_p () noexcept
 A factory function to create a quoted_string_producer. More...
 
auto quoted_pair_p () noexcept
 A factory function to create a quoted_pair_producer. More...
 
auto expected_token_p (string_view_t token)
 A factory function to create a producer that expect a token with specific value. More...
 
auto expected_caseless_token_p (string_view_t token)
 A factory function to create a producer that expect a token with specific value. More...
 
auto qvalue_p () noexcept
 A factory function to create a qvalue_producer. More...
 
auto weight_p () noexcept
 A factory function to create a producer for weight parameter. More...
 
template<typename Container , typename Element_Producer >
auto non_empty_comma_separated_list_p (Element_Producer element)
 A factory for a producer that handles non-empty list of comma-separated values. More...
 
template<typename Container , typename Element_Producer >
auto maybe_empty_comma_separated_list_p (Element_Producer element)
 A factory for a producer that handles possibly empty list of comma-separated values. More...
 
expected_t< string_view_t, not_found_tfind_first (const parameter_with_mandatory_value_container_t &where, string_view_t what)
 A helper function to find the first occurence of a parameter with the specified value. More...
 
impl::params_with_value_producer_t params_with_value_p ()
 A factory of producer of parameter_with_mandatory_value_container. More...
 
expected_t< std::optional< string_view_t >, not_found_tfind_first (const parameter_with_optional_value_container_t &where, string_view_t what)
 A helper function to find the first occurence of a parameter with the specified value. More...
 
impl::params_with_opt_value_producer_t params_with_opt_value_p ()
 A factory of producer of parameter_with_optional_value_container. More...
 
std::ostream & operator<< (std::ostream &to, const raw_host_value_t &rhv)
 
template<typename Parsed_Field_Type , typename Extra_Data >
auto try_parse_field (const generic_request_t< Extra_Data > &req, string_view_t field_name, string_view_t default_value=string_view_t{})
 A helper function for extraction and parsing a value of HTTP-field. More...
 
template<typename Parsed_Field_Type , typename Extra_Data >
auto try_parse_field (const generic_request_t< Extra_Data > &req, http_field_t field_id, string_view_t default_value=string_view_t{})
 A helper function for extraction and parsing a value of HTTP-field. More...
 

Typedef Documentation

◆ parameter_with_mandatory_value_container_t

A type of container for parameters with mandatory values.

Since
v.0.6.1

Definition at line 1534 of file basics.hpp.

◆ parameter_with_mandatory_value_t

using restinio::http_field_parsers::parameter_with_mandatory_value_t = typedef std::pair< std::string, std::string >

A type that describes a parameter with mandatory value.

Since
v.0.6.1

Definition at line 1523 of file basics.hpp.

◆ parameter_with_optional_value_container_t

A type of container for parameters with optional values.

Since
v.0.6.1

Definition at line 1709 of file basics.hpp.

◆ parameter_with_optional_value_t

using restinio::http_field_parsers::parameter_with_optional_value_t = typedef std::pair< std::string, std::optional<std::string> >

A type that describes a parameter with optional value.

Since
v.0.6.1

Definition at line 1698 of file basics.hpp.

Function Documentation

◆ alpha_symbol_p()

auto restinio::http_field_parsers::alpha_symbol_p ( )
inline

A factory for producer of ALPHA symbols.

Usage example:

produce<std::string>(
Since
v.0.6.2

Definition at line 790 of file basics.hpp.

◆ alphanum_symbol_p()

auto restinio::http_field_parsers::alphanum_symbol_p ( )
inline

A factory for producer of symbol that an ALPHA or DIGIT.

Usage example:

produce<std::string>(
Since
v.0.6.2

Definition at line 812 of file basics.hpp.

◆ comment_p()

auto restinio::http_field_parsers::comment_p ( )
inline

A factory for producer of comment token.

Usage example:

produce<std::string>(
)
);
Since
v.0.6.4

Definition at line 882 of file basics.hpp.

◆ ctext_symbol_p()

auto restinio::http_field_parsers::ctext_symbol_p ( )
inline

A factory for producer of ctext symbols.

Usage example:

produce<std::string>(
Since
v.0.6.4

Definition at line 856 of file basics.hpp.

◆ expected_caseless_token_p()

auto restinio::http_field_parsers::expected_caseless_token_p ( string_view_t  token)
inline

A factory function to create a producer that expect a token with specific value.

This processer uses case-insensitive comparison.

If the expected token is successfully parsed then boolean value is produced.

Usage example:

enum class compression { zlib, bz2, xz };
produce<compression>(
caseless_expected_token_p("Compression") >> skip(),
ows(),
symbol('='),
ows(),
caseless_expected_token_p("ZLib") >> just_result(compression::zlib),
caseless_expected_token_p("BZ2") >> just_result(compression::bz2),
caseless_expected_token_p("xz") >> just_result(compression::xz)
)
);
Since
v.0.6.9

Definition at line 1114 of file basics.hpp.

◆ expected_token_p()

auto restinio::http_field_parsers::expected_token_p ( string_view_t  token)
inline

A factory function to create a producer that expect a token with specific value.

If the expected token is successfully parsed then boolean value is produced.

Usage example:

enum class compression { zlib, bz2, xz };
produce<compression>(
expected_token_p("compression") >> skip(),
ows(),
symbol('='),
ows(),
expected_token_p("zlib") >> just_result(compression::zlib),
expected_token_p("bz2") >> just_result(compression::bz2),
expected_token_p("xz") >> just_result(compression::xz)
)
);
Since
v.0.6.9

Definition at line 1075 of file basics.hpp.

◆ find_first() [1/2]

expected_t< string_view_t, not_found_t > restinio::http_field_parsers::find_first ( const parameter_with_mandatory_value_container_t where,
string_view_t  what 
)
inline

A helper function to find the first occurence of a parameter with the specified value.

Note
The caseless (case-insentive) search is used. It means that search with value "charset" will returns items "CharSet", "charset", "CHARSET" and so on.

Usage example:

const auto charset = find_first(content_type_params, "charset");
if(charset) {
... // Handle the value of charset parameter.
}
Since
v.0.6.1

Definition at line 1570 of file basics.hpp.

◆ find_first() [2/2]

expected_t< std::optional<string_view_t>, not_found_t > restinio::http_field_parsers::find_first ( const parameter_with_optional_value_container_t where,
string_view_t  what 
)
inline

A helper function to find the first occurence of a parameter with the specified value.

Note
The caseless (case-insentive) search is used. It means that search with value "charset" will returns items "CharSet", "charset", "CHARSET" and so on.

Usage example:

const auto max_age = find_first(cache_control_params, "max-age");
if(max_age) {
if(*max_age) {
... // Handle the value of max-age parameter.
}
else {
... // Handle the case where max-age specified but without a value.
}
}
Since
v.0.6.1

Definition at line 1740 of file basics.hpp.

◆ maybe_empty_comma_separated_list_p()

template<typename Container , typename Element_Producer >
auto restinio::http_field_parsers::maybe_empty_comma_separated_list_p ( Element_Producer  element)

A factory for a producer that handles possibly empty list of comma-separated values.

That producer handles the following rule:

#element => [ ( "," / element ) *( OWS "," [ OWS element ] ) ]

See: https://tools.ietf.org/html/rfc7230 (section "7. ABNF List Extension: #rule")

Usage example:

auto parse = produce< byte_ranges_data >(
maybe_empty_comma_separated_list_p< std::vector< byte_range > >(
make_byte_range_parser()
) >> &byte_ranges_data::ranges
);
Template Parameters
Containerthe type of container to be produced.
Element_Producerthe type of the producer of a single item.
Since
v.0.6.1

Definition at line 1505 of file basics.hpp.

◆ non_empty_comma_separated_list_p()

template<typename Container , typename Element_Producer >
auto restinio::http_field_parsers::non_empty_comma_separated_list_p ( Element_Producer  element)

A factory for a producer that handles non-empty list of comma-separated values.

That producer handles the following rule:

1#element => *( "," OWS ) element *( OWS "," [ OWS element ] )

See: https://tools.ietf.org/html/rfc7230 (section "7. ABNF List Extension: #rule")

Usage example:

auto parse = produce< byte_ranges_data >(
non_empty_comma_separated_list_p< std::vector< byte_range > >(
make_byte_range_parser()
) >> &byte_ranges_data::ranges
);
Template Parameters
Containerthe type of container to be produced.
Element_Producerthe type of the producer of a single item.
Since
v.0.6.1

Definition at line 1459 of file basics.hpp.

◆ operator!=()

bool restinio::http_field_parsers::operator!= ( const qvalue_t a,
const qvalue_t b 
)
inlinenoexcept

Definition at line 229 of file basics.hpp.

◆ operator<()

bool restinio::http_field_parsers::operator< ( const qvalue_t a,
const qvalue_t b 
)
inlinenoexcept

Definition at line 236 of file basics.hpp.

◆ operator<<() [1/5]

std::ostream& restinio::http_field_parsers::operator<< ( std::ostream &  to,
const authorization_value_t::param_value_t v 
)
inline

Definition at line 248 of file authorization.hpp.

◆ operator<<() [2/5]

std::ostream& restinio::http_field_parsers::operator<< ( std::ostream &  to,
const authorization_value_t::param_t v 
)
inline

Definition at line 260 of file authorization.hpp.

◆ operator<<() [3/5]

std::ostream& restinio::http_field_parsers::operator<< ( std::ostream &  to,
const authorization_value_t::auth_param_t p 
)
inline

Definition at line 268 of file authorization.hpp.

◆ operator<<() [4/5]

std::ostream& restinio::http_field_parsers::operator<< ( std::ostream &  to,
const authorization_value_t v 
)
inline

Definition at line 306 of file authorization.hpp.

◆ operator<<() [5/5]

std::ostream& restinio::http_field_parsers::operator<< ( std::ostream &  to,
const raw_host_value_t rhv 
)
inline

Definition at line 557 of file host.hpp.

◆ operator<=()

bool restinio::http_field_parsers::operator<= ( const qvalue_t a,
const qvalue_t b 
)
inlinenoexcept

Definition at line 243 of file basics.hpp.

◆ operator==()

bool restinio::http_field_parsers::operator== ( const qvalue_t a,
const qvalue_t b 
)
inlinenoexcept

Definition at line 222 of file basics.hpp.

◆ ows()

auto restinio::http_field_parsers::ows ( )
inlinenoexcept

A factory function to create an OWS clause.

This clause handles an optional sequence of spaces in the input stream and skips the value of that sequence.

Usage example:

produce<std::string>(
ows(),
symbol('v'),
symbol('='),
ows(),
);

This expression corresponds the following rule:

T := OWS 'v' '=' OWS token
Since
v.0.6.1

Definition at line 941 of file basics.hpp.

◆ ows_p()

auto restinio::http_field_parsers::ows_p ( )
inlinenoexcept

A factory function to create an ows_producer.

Usage example:

produce<std::string>(
ows_p() >> skip(),
symbol('v'),
symbol('='),
ows_p() >> skip(),
);
Note
Factory function ows() can be used instead of expression ows_p() >> skip().
Since
v.0.6.1

Definition at line 911 of file basics.hpp.

◆ params_with_opt_value_p()

impl::params_with_opt_value_producer_t restinio::http_field_parsers::params_with_opt_value_p ( )
inline

A factory of producer of parameter_with_optional_value_container.

Creates a produces that handles the following rule:

T := *( OWS ';' OWS token ['=' OWS (token / quoted_string)] )

Usage example:

struct my_field {
std::string value;
};
produce<my_field>(
token_p() >> to_lower() >> &my_field::value,
params_with_opt_value_p() >> &my_field::params
);
Note
Parameters names are converted to lower case. Parameters' values are not changed and stored as they are.
Since
v.0.6.1

Definition at line 1865 of file basics.hpp.

◆ params_with_value_p()

impl::params_with_value_producer_t restinio::http_field_parsers::params_with_value_p ( )
inline

A factory of producer of parameter_with_mandatory_value_container.

Creates a produces that handles the following rule:

T := *( OWS ';' OWS token '=' OWS (token / quoted_string))

Usage example:

struct my_field {
std::string value;
};
produce<my_field>(
token_p() >> to_lower() >> &my_field::value,
params_with_value_p() >> &my_field::params
);
Note
Parameters names are converted to lower case. Parameters' values are not changed and stored as they are.
Since
v.0.6.1

Definition at line 1687 of file basics.hpp.

◆ quoted_pair_p()

auto restinio::http_field_parsers::quoted_pair_p ( )
inlinenoexcept

A factory function to create a quoted_pair_producer.

Usage example:

produce<std::string>(
repeat(1, N,
)
);
Since
v.0.6.4

Definition at line 1040 of file basics.hpp.

◆ quoted_string_p()

auto restinio::http_field_parsers::quoted_string_p ( )
inlinenoexcept

A factory function to create a quoted_string_producer.

Usage example:

using parameter = std::pair<std::string, std::string>;
produce<parameter>(
ows(),
token_p() >> &parameter::first,
symbol('='),
ows(),
token_p() >> &parameter::second,
quoted_string_p() >> &parameter::second
)
);
Since
v.0.6.1

Definition at line 1014 of file basics.hpp.

◆ qvalue_p()

auto restinio::http_field_parsers::qvalue_p ( )
inlinenoexcept

A factory function to create a qvalue_producer.

Usage example:

produce<qvalue_t>(
alternatives(symbol('r'), symbol('R')),
symbol('='),
);
Since
v.0.6.1

Definition at line 1252 of file basics.hpp.

◆ token_p()

auto restinio::http_field_parsers::token_p ( )
inlinenoexcept

A factory function to create a token_producer.

Usage example:

using parameter = std::pair<std::string, std::string>;
produce<parameter>(
ows(),
token_p() >> &parameter::first,
symbol('='),
ows(),
token_p() >> &parameter::second
);
Since
v.0.6.1

Definition at line 987 of file basics.hpp.

◆ token_symbol_p()

auto restinio::http_field_parsers::token_symbol_p ( )
inlinenoexcept

A factory for producer of symbols than can be used in tokens.

Usage example:

produce<std::string>(
Since
v.0.6.9

Definition at line 959 of file basics.hpp.

◆ try_parse_field() [1/2]

template<typename Parsed_Field_Type , typename Extra_Data >
auto restinio::http_field_parsers::try_parse_field ( const generic_request_t< Extra_Data > &  req,
string_view_t  field_name,
string_view_t  default_value = string_view_t{} 
)

A helper function for extraction and parsing a value of HTTP-field.

This helper is intended to be used when HTTP-field is identified by its name.

Usage example:

auto on_post(const restinio::request_handle_t & req) {
const auto auth_field = try_parse_field< authorization_value_t >(
req, "X-My-Authorization");
if(auto * auth = std::get_if<authorization_value_t>(&auth_field)) {
// X-My-Authorization is successfully parsed.
if("basic" == auth->auth_scheme) {
... // Dealing with basic authentification.
}
else if("bearer" == auth->auth_scheme) {
... // Dealing with bearer authentification.
}
else {
...
}
}
}
Template Parameters
Parsed_Field_TypeThe type of field value to be received as the result of successful parse if the field is present.
Extra_DataThe type of extra-data incorporated into an instance of restinio::generic_request_t. There is no need to specify that type, it has to be detected automatically by the compiler.
Since
v.0.6.8
Parameters
reqA request that should hold a HTTP-field.
field_nameThe name of HTTP-field to be extracted and parsed.
default_valueThe default value to be used if HTTP-field is not found. If this value is not empty, then the variant with field_not_found_t won't be returned.

Definition at line 151 of file try_parse_field.hpp.

◆ try_parse_field() [2/2]

template<typename Parsed_Field_Type , typename Extra_Data >
auto restinio::http_field_parsers::try_parse_field ( const generic_request_t< Extra_Data > &  req,
http_field_t  field_id,
string_view_t  default_value = string_view_t{} 
)

A helper function for extraction and parsing a value of HTTP-field.

This helper is intended to be used when HTTP-field is identified by its ID.

Usage example:

auto on_post(const restinio::request_handle_t & req) {
const auto auth_field = try_parse_field< authorization_value_t >(
req, restinio::http_field::authorization);
if(auto * auth = std::get_if<authorization_value_t>(&auth_field)) {
// Authorization is successfully parsed.
if("basic" == auth->auth_scheme) {
... // Dealing with basic authentification.
}
else if("bearer" == auth->auth_scheme) {
... // Dealing with bearer authentification.
}
else {
...
}
}
}
Template Parameters
Parsed_Field_TypeThe type of field value to be received as the result of successful parse if the field is present.
Extra_DataThe type of extra-data incorporated into an instance of restinio::generic_request_t. There is no need to specify that type, it has to be detected automatically by the compiler.
Since
v.0.6.8
Parameters
reqA request that should hold a HTTP-field.
field_idThe ID of a HTTP-field to be extracted and parsed.
default_valueThe default value to be used if HTTP-field is not found. If this value is not empty, then the variant with field_not_found_t won't be returned.

Definition at line 209 of file try_parse_field.hpp.

◆ vchar_symbol_p()

auto restinio::http_field_parsers::vchar_symbol_p ( )
inline

A factory for producer of VCHAR symbols.

Usage example:

produce<std::string>(
Since
v.0.6.2

Definition at line 834 of file basics.hpp.

◆ weight_p()

auto restinio::http_field_parsers::weight_p ( )
inlinenoexcept

A factory function to create a producer for weight parameter.

Returns a producer that handles the following rules:

weight = OWS ';' OWS ('q' / 'Q') '=' qvalue

qvalue = ( "0" [ "." 0*3DIGIT ] )
       / ( "1" [ "." 0*3("0") ] )

See: https://tools.ietf.org/html/rfc7231

That producer produces a value of type qvalue_t.

Since
v.0.6.1

Definition at line 1279 of file basics.hpp.