RESTinio
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Functions
restinio::http_field_parsers Namespace Reference

Namespaces

namespace  accept_language_details
 
namespace  authorization_details
 
namespace  basic_auth
 
namespace  bearer_auth
 
namespace  content_disposition_details
 
namespace  details
 
namespace  host_details
 
namespace  impl
 
namespace  qvalue_details
 
namespace  range_details
 
namespace  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.
 
using parameter_with_mandatory_value_container_t
 A type of container for parameters with mandatory values.
 
using parameter_with_optional_value_t
 A type that describes a parameter with optional value.
 
using parameter_with_optional_value_container_t
 A type of container for parameters with optional values.
 

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.
 
auto alphanum_symbol_p ()
 A factory for producer of symbol that an ALPHA or DIGIT.
 
auto vchar_symbol_p ()
 A factory for producer of VCHAR symbols.
 
auto ctext_symbol_p ()
 A factory for producer of ctext symbols.
 
auto comment_p ()
 A factory for producer of comment token.
 
auto ows_p () noexcept
 A factory function to create an ows_producer.
 
auto ows () noexcept
 A factory function to create an OWS clause.
 
auto token_symbol_p () noexcept
 A factory for producer of symbols than can be used in tokens.
 
auto token_p () noexcept
 A factory function to create a token_producer.
 
auto quoted_string_p () noexcept
 A factory function to create a quoted_string_producer.
 
auto quoted_pair_p () noexcept
 A factory function to create a quoted_pair_producer.
 
auto expected_token_p (string_view_t token)
 A factory function to create a producer that expect a token with specific value.
 
auto expected_caseless_token_p (string_view_t token)
 A factory function to create a producer that expect a token with specific value.
 
auto qvalue_p () noexcept
 A factory function to create a qvalue_producer.
 
auto weight_p () noexcept
 A factory function to create a producer for weight parameter.
 
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.
 
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.
 
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.
 
impl::params_with_value_producer_t params_with_value_p ()
 A factory of producer of parameter_with_mandatory_value_container.
 
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.
 
impl::params_with_opt_value_producer_t params_with_opt_value_p ()
 A factory of producer of parameter_with_optional_value_container.
 
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.
 
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.
 

Typedef Documentation

◆ parameter_with_mandatory_value_container_t

Initial value:
std::vector< parameter_with_mandatory_value_t >

A type of container for parameters with mandatory values.

Since
v.0.6.1

Definition at line 1533 of file basics.hpp.

◆ parameter_with_mandatory_value_t

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

Initial value:
std::vector< parameter_with_optional_value_t >

A type of container for parameters with optional values.

Since
v.0.6.1

Definition at line 1708 of file basics.hpp.

◆ parameter_with_optional_value_t

Initial value:
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 1697 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:

auto to_container()
A factory function to create a to_container_consumer.
auto repeat(std::size_t min_occurences, std::size_t max_occurences, Clauses &&... clauses)
A factory function to create repetitor of subclauses.
auto alpha_symbol_p()
A factory for producer of ALPHA symbols.
Definition basics.hpp:790
run_on_this_thread_settings_t< Traits > on_this_thread()
A special marker for the case when http_server must be run on the context of the current thread.
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:

auto alphanum_symbol_p()
A factory for producer of symbol that an ALPHA or DIGIT.
Definition basics.hpp:812
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:

)
);
auto as_result() noexcept
A factory function to create a as_result_consumer.
auto alternatives(Clauses &&... clauses)
A factory function to create an alternatives clause.
auto token_p() noexcept
A factory function to create a token_producer.
Definition basics.hpp:987
auto comment_p()
A factory for producer of comment token.
Definition basics.hpp:882
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:

auto ctext_symbol_p()
A factory for producer of ctext symbols.
Definition basics.hpp:856
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 };
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)
)
);
auto symbol(char expected) noexcept
A factory function to create a clause that expects the speficied symbol, extracts it and then skips i...
auto just_result(T value) noexcept(noexcept(impl::just_result_consumer_t< T >{value}))
A special consumer that replaces the produced value by a value specified by a user and sets that user...
auto skip() noexcept
A factory function to create a skip_consumer.
auto ows() noexcept
A factory function to create an OWS clause.
Definition basics.hpp:941
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 };
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)
)
);
auto expected_token_p(string_view_t token)
A factory function to create a producer that expect a token with specific value.
Definition basics.hpp:1075
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.
}
expected_t< string_view_t, not_found_t > find_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.
Definition basics.hpp:1570
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()

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:

make_bytes_prefix_parser(),
maybe_empty_comma_separated_list_p< std::vector< byte_range > >(
) >> &byte_ranges_data::ranges
);
auto maybe_empty_comma_separated_list_p(Element_Producer element)
A factory for a producer that handles possibly empty list of comma-separated values.
Definition basics.hpp:1505
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()

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:

make_bytes_prefix_parser(),
non_empty_comma_separated_list_p< std::vector< byte_range > >(
) >> &byte_ranges_data::ranges
);
auto non_empty_comma_separated_list_p(Element_Producer element)
A factory for a producer that handles non-empty list of comma-separated values.
Definition basics.hpp:1459
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 235 of file basics.hpp.

◆ operator<<() [1/5]

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

Definition at line 305 of file authorization.hpp.

◆ operator<<() [2/5]

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

Definition at line 267 of file authorization.hpp.

◆ operator<<() [3/5]

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

Definition at line 259 of file authorization.hpp.

◆ operator<<() [4/5]

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

Definition at line 247 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 556 of file host.hpp.

◆ operator<=()

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

Definition at line 242 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:

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:

ows_p() >> skip(),
symbol('v'),
symbol('='),
ows_p() >> skip(),
);
auto ows_p() noexcept
A factory function to create an ows_producer.
Definition basics.hpp:911
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;
};
token_p() >> to_lower() >> &my_field::value,
params_with_opt_value_p() >> &my_field::params
);
auto to_lower() noexcept
A factory function to create a to_lower_transformer.
std::vector< parameter_with_optional_value_t > parameter_with_optional_value_container_t
A type of container for parameters with optional values.
Definition basics.hpp:1708
impl::params_with_opt_value_producer_t params_with_opt_value_p()
A factory of producer of parameter_with_optional_value_container.
Definition basics.hpp:1865
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;
};
token_p() >> to_lower() >> &my_field::value,
params_with_value_p() >> &my_field::params
);
impl::params_with_value_producer_t params_with_value_p()
A factory of producer of parameter_with_mandatory_value_container.
Definition basics.hpp:1687
std::vector< parameter_with_mandatory_value_t > parameter_with_mandatory_value_container_t
A type of container for parameters with mandatory values.
Definition basics.hpp:1533
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:

repeat(1, N,
)
);
constexpr std::size_t N
A special marker that means infinite repetitions.
auto quoted_pair_p() noexcept
A factory function to create a quoted_pair_producer.
Definition basics.hpp:1040
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>;
ows(),
token_p() >> &parameter::first,
symbol('='),
ows(),
token_p() >> &parameter::second,
quoted_string_p() >> &parameter::second
)
);
auto quoted_string_p() noexcept
A factory function to create a quoted_string_producer.
Definition basics.hpp:1014
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:

alternatives(symbol('r'), symbol('R')),
symbol('='),
);
auto qvalue_p() noexcept
A factory function to create a qvalue_producer.
Definition basics.hpp:1252
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>;
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:

auto token_symbol_p() noexcept
A factory for producer of symbols than can be used in tokens.
Definition basics.hpp:959
Since
v.0.6.9

Definition at line 959 of file basics.hpp.

◆ try_parse_field() [1/2]

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:

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 {
...
}
}
}
std::shared_ptr< request_t > request_handle_t
An alias for handle for incoming request without additional extra-data.
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.

◆ try_parse_field() [2/2]

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:

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.

◆ vchar_symbol_p()

auto restinio::http_field_parsers::vchar_symbol_p ( )
inline

A factory for producer of VCHAR symbols.

Usage example:

auto vchar_symbol_p()
A factory for producer of VCHAR symbols.
Definition basics.hpp:834
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.