accept.hpp
Go to the documentation of this file.
/*
* RESTinio
*/
#pragma once
#include <restinio/helpers/http_field_parsers/media-type.hpp>
namespace restinio
{
namespace http_field_parsers
{
//
// accept_value_t
//
struct accept_value_t
{
struct item_t
{
using accept_ext_t = parameter_with_optional_value_t;
using accept_ext_container_t = parameter_with_optional_value_container_t;
media_type_value_t media_type;
restinio::optional_t< qvalue_t > weight;
accept_ext_container_t accept_params;
};
using item_container_t = std::vector< item_t >;
item_container_t items;
RESTINIO_NODISCARD
static auto
make_parser()
{
const auto media_type = media_type_value_t::make_weight_aware_parser();
return produce< accept_value_t >(
maybe_empty_comma_separated_list_p< item_container_t >(
produce< item_t >(
media_type >> &item_t::media_type,
maybe(
weight_p() >> &item_t::weight,
params_with_opt_value_p() >> &item_t::accept_params
)
)
) >> &accept_value_t::items
);
}
RESTINIO_NODISCARD
static expected_t< accept_value_t, restinio::easy_parser::parse_error_t >
try_parse( string_view_t what )
{
return restinio::easy_parser::try_parse( what, make_parser() );
}
};
} /* namespace http_field_parsers */
} /* namespace restinio */
nonstd::optional_lite::optional
class optional
Definition: optional.hpp:919
RESTINIO_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:33
media-type.hpp
Stuff related to Media-Type value in HTTP-fields.
restinio::easy_parser::maybe
RESTINIO_NODISCARD auto maybe(Clauses &&... clauses)
A factory function to create an optional clause.
Definition: easy_parser.hpp:3634
restinio::easy_parser::try_parse
RESTINIO_NODISCARD expected_t< typename Producer::result_type, parse_error_t > try_parse(string_view_t from, Producer producer)
Perform the parsing of the specified content by using specified value producer.
Definition: easy_parser.hpp:5042
restinio::http_field_parsers::parameter_with_optional_value_t
std::pair< std::string, restinio::optional_t< std::string > > parameter_with_optional_value_t
A type that describes a parameter with optional value.
Definition: basics.hpp:1696
restinio::http_field_parsers::params_with_opt_value_p
RESTINIO_NODISCARD 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:1863
restinio::http_field_parsers::parameter_with_optional_value_container_t
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:1707
restinio::http_field_parsers::weight_p
RESTINIO_NODISCARD auto weight_p() noexcept
A factory function to create a producer for weight parameter.
Definition: basics.hpp:1277
restinio
Definition: asio_include.hpp:21
restinio::string_view_t
nonstd::string_view string_view_t
Definition: string_view.hpp:19
restinio::expected_t
nonstd::expected< T, E > expected_t
Definition: expected.hpp:22
restinio::http_field_parsers::accept_value_t::item_t
Definition: accept.hpp:54
restinio::http_field_parsers::accept_value_t::item_t::media_type
media_type_value_t media_type
Definition: accept.hpp:59
restinio::http_field_parsers::accept_value_t::item_t::accept_params
accept_ext_container_t accept_params
Definition: accept.hpp:61
restinio::http_field_parsers::accept_value_t::item_t::accept_ext_container_t
parameter_with_optional_value_container_t accept_ext_container_t
Definition: accept.hpp:57
restinio::http_field_parsers::accept_value_t::item_t::accept_ext_t
parameter_with_optional_value_t accept_ext_t
Definition: accept.hpp:55
restinio::http_field_parsers::accept_value_t::item_t::weight
restinio::optional_t< qvalue_t > weight
Definition: accept.hpp:60
restinio::http_field_parsers::accept_value_t
Tools for working with the value of Accept HTTP-field.
Definition: accept.hpp:52
restinio::http_field_parsers::accept_value_t::make_parser
static RESTINIO_NODISCARD auto make_parser()
A factory function for a parser of Accept value.
Definition: accept.hpp:75
restinio::http_field_parsers::accept_value_t::items
item_container_t items
Definition: accept.hpp:66
restinio::http_field_parsers::accept_value_t::try_parse
static RESTINIO_NODISCARD expected_t< accept_value_t, restinio::easy_parser::parse_error_t > try_parse(string_view_t what)
An attempt to parse Accept HTTP-field.
Definition: accept.hpp:99
restinio::http_field_parsers::accept_value_t::item_container_t
std::vector< item_t > item_container_t
Definition: accept.hpp:64
restinio::http_field_parsers::media_type_value_t
Tools for working with media-type in HTTP-fields.
Definition: media-type.hpp:42
restinio::http_field_parsers::media_type_value_t::make_weight_aware_parser
static RESTINIO_NODISCARD auto make_weight_aware_parser()
Definition: media-type.hpp:93