transfer-encoding.hpp
Go to the documentation of this file.
/*
* RESTinio
*/
#pragma once
#include <restinio/helpers/http_field_parsers/basics.hpp>
#include <restinio/variant.hpp>
#include <tuple>
namespace restinio
{
namespace http_field_parsers
{
//
// transfer_encoding_value_t
//
struct transfer_encoding_value_t
{
enum class known_transfer_coding_t
{
chunked,
compress,
deflate,
gzip,
};
RESTINIO_NODISCARD
static constexpr known_transfer_coding_t chunked() noexcept
{ return known_transfer_coding_t::chunked; }
RESTINIO_NODISCARD
static constexpr known_transfer_coding_t compress() noexcept
{ return known_transfer_coding_t::compress; }
RESTINIO_NODISCARD
static constexpr known_transfer_coding_t deflate() noexcept
{ return known_transfer_coding_t::deflate; }
RESTINIO_NODISCARD
static constexpr known_transfer_coding_t gzip() noexcept
{ return known_transfer_coding_t::gzip; }
struct transfer_extension_t
{
std::string token;
parameter_with_mandatory_value_container_t transfer_parameters;
RESTINIO_NODISCARD
bool
operator==( const transfer_extension_t & o ) const noexcept
{
return std::tie(this->token, this->transfer_parameters) ==
std::tie(o.token, o.transfer_parameters);
}
};
using value_t = variant_t<
known_transfer_coding_t,
transfer_extension_t
>;
using value_container_t = std::vector< value_t >;
value_container_t values;
RESTINIO_NODISCARD
static auto
make_parser()
{
return produce< transfer_encoding_value_t >(
non_empty_comma_separated_list_p< value_container_t >(
produce< value_t >(
alternatives(
expected_caseless_token_p("chunked")
>> just_result( chunked() ),
expected_caseless_token_p("compress")
>> just_result( compress() ),
expected_caseless_token_p("deflate")
>> just_result( deflate() ),
expected_caseless_token_p("gzip")
>> just_result( gzip() ),
expected_caseless_token_p("x-gzip")
>> just_result( gzip() ),
produce< transfer_extension_t >(
token_p() >> to_lower() >> &transfer_extension_t::token,
params_with_value_p()
>> &transfer_extension_t::transfer_parameters
) >> as_result()
)
)
) >> &transfer_encoding_value_t::values
);
}
RESTINIO_NODISCARD
static expected_t<
transfer_encoding_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 */
basics.hpp
Utilities for parsing values of http-fields.
nonstd::variants::variant
Definition: variant.hpp:1301
restinio::easy_parser::parse_error_t
Information about parsing error.
Definition: easy_parser.hpp:93
RESTINIO_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:33
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::easy_parser::just_result
RESTINIO_NODISCARD 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...
Definition: easy_parser.hpp:4664
restinio::easy_parser::as_result
RESTINIO_NODISCARD auto as_result() noexcept
A factory function to create a as_result_consumer.
Definition: easy_parser.hpp:4470
restinio::easy_parser::to_lower
RESTINIO_NODISCARD auto to_lower() noexcept
A factory function to create a to_lower_transformer.
Definition: easy_parser.hpp:4610
restinio::easy_parser::alternatives
RESTINIO_NODISCARD auto alternatives(Clauses &&... clauses)
A factory function to create an alternatives clause.
Definition: easy_parser.hpp:3595
restinio::http_field_parsers::params_with_value_p
RESTINIO_NODISCARD impl::params_with_value_producer_t params_with_value_p()
A factory of producer of parameter_with_mandatory_value_container.
Definition: basics.hpp:1685
restinio::http_field_parsers::parameter_with_mandatory_value_container_t
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:1532
restinio::http_field_parsers::token_p
RESTINIO_NODISCARD auto token_p() noexcept
A factory function to create a token_producer.
Definition: basics.hpp:985
restinio::http_field_parsers::expected_caseless_token_p
RESTINIO_NODISCARD auto expected_caseless_token_p(string_view_t token)
A factory function to create a producer that expect a token with specific value.
Definition: basics.hpp:1112
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::transfer_encoding_value_t::transfer_extension_t
Description of transfer-extension.
Definition: transfer-encoding.hpp:77
restinio::http_field_parsers::transfer_encoding_value_t::transfer_extension_t::transfer_parameters
parameter_with_mandatory_value_container_t transfer_parameters
Definition: transfer-encoding.hpp:79
restinio::http_field_parsers::transfer_encoding_value_t::transfer_extension_t::token
std::string token
Definition: transfer-encoding.hpp:78
restinio::http_field_parsers::transfer_encoding_value_t::transfer_extension_t::operator==
RESTINIO_NODISCARD bool operator==(const transfer_extension_t &o) const noexcept
Definition: transfer-encoding.hpp:83
restinio::http_field_parsers::transfer_encoding_value_t
Tools for working with the value of Transfer-Encoding HTTP-field.
Definition: transfer-encoding.hpp:49
restinio::http_field_parsers::transfer_encoding_value_t::compress
static RESTINIO_NODISCARD constexpr known_transfer_coding_t compress() noexcept
Definition: transfer-encoding.hpp:64
restinio::http_field_parsers::transfer_encoding_value_t::value_container_t
std::vector< value_t > value_container_t
Definition: transfer-encoding.hpp:96
restinio::http_field_parsers::transfer_encoding_value_t::gzip
static RESTINIO_NODISCARD constexpr known_transfer_coding_t gzip() noexcept
Definition: transfer-encoding.hpp:72
restinio::http_field_parsers::transfer_encoding_value_t::chunked
static RESTINIO_NODISCARD constexpr known_transfer_coding_t chunked() noexcept
Definition: transfer-encoding.hpp:60
restinio::http_field_parsers::transfer_encoding_value_t::known_transfer_coding_t
known_transfer_coding_t
Enumeration for transfer-coding values from RFC7230.
Definition: transfer-encoding.hpp:52
restinio::http_field_parsers::transfer_encoding_value_t::known_transfer_coding_t::compress
@ compress
restinio::http_field_parsers::transfer_encoding_value_t::known_transfer_coding_t::gzip
@ gzip
restinio::http_field_parsers::transfer_encoding_value_t::known_transfer_coding_t::deflate
@ deflate
restinio::http_field_parsers::transfer_encoding_value_t::known_transfer_coding_t::chunked
@ chunked
restinio::http_field_parsers::transfer_encoding_value_t::values
value_container_t values
Definition: transfer-encoding.hpp:98
restinio::http_field_parsers::transfer_encoding_value_t::deflate
static RESTINIO_NODISCARD constexpr known_transfer_coding_t deflate() noexcept
Definition: transfer-encoding.hpp:68
restinio::http_field_parsers::transfer_encoding_value_t::make_parser
static RESTINIO_NODISCARD auto make_parser()
A factory function for a parser of Transfer-Encoding value.
Definition: transfer-encoding.hpp:107
restinio::http_field_parsers::transfer_encoding_value_t::try_parse
static RESTINIO_NODISCARD expected_t< transfer_encoding_value_t, restinio::easy_parser::parse_error_t > try_parse(string_view_t what)
An attempt to parse Transfer-Encoding HTTP-field.
Definition: transfer-encoding.hpp:143
variant.hpp