RESTinio
transfer-encoding.hpp
Go to the documentation of this file.
1 /*
2  * RESTinio
3  */
4 
12 #pragma once
13 
15 
16 #include <restinio/variant.hpp>
17 
18 #include <tuple>
19 
20 namespace restinio
21 {
22 
23 namespace http_field_parsers
24 {
25 
26 //
27 // transfer_encoding_value_t
28 //
49 {
52  {
53  chunked,
54  compress,
55  deflate,
56  gzip,
57  };
58 
60  static constexpr known_transfer_coding_t chunked() noexcept
62 
64  static constexpr known_transfer_coding_t compress() noexcept
66 
68  static constexpr known_transfer_coding_t deflate() noexcept
70 
72  static constexpr known_transfer_coding_t gzip() noexcept
74 
77  {
78  std::string token;
80 
82  bool
83  operator==( const transfer_extension_t & o ) const noexcept
84  {
85  return std::tie(this->token, this->transfer_parameters) ==
86  std::tie(o.token, o.transfer_parameters);
87  }
88  };
89 
91  using value_t = variant_t<
94  >;
95 
96  using value_container_t = std::vector< value_t >;
97 
99 
106  static auto
108  {
109  return produce< transfer_encoding_value_t >(
110  non_empty_comma_separated_list_p< value_container_t >(
111  produce< value_t >(
112  alternatives(
113  expected_caseless_token_p("chunked")
114  >> just_result( chunked() ),
115  expected_caseless_token_p("compress")
116  >> just_result( compress() ),
117  expected_caseless_token_p("deflate")
118  >> just_result( deflate() ),
120  >> just_result( gzip() ),
121  expected_caseless_token_p("x-gzip")
122  >> just_result( gzip() ),
123  produce< transfer_extension_t >(
127  ) >> as_result()
128  )
129  )
131  );
132  }
133 
140  static expected_t<
144  {
146  }
147 };
148 
149 } /* namespace http_field_parsers */
150 
151 } /* namespace restinio */
152 
RESTINIO_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:33
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::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::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::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::transfer_encoding_value_t::deflate
static constexpr RESTINIO_NODISCARD known_transfer_coding_t deflate() noexcept
Definition: transfer-encoding.hpp:68
restinio::easy_parser::parse_error_t
Information about parsing error.
Definition: easy_parser.hpp:93
restinio::string_view_t
nonstd::string_view string_view_t
Definition: string_view.hpp:19
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::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
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::deflate
@ deflate
restinio::http_field_parsers::transfer_encoding_value_t::compress
static constexpr RESTINIO_NODISCARD known_transfer_coding_t compress() noexcept
Definition: transfer-encoding.hpp:64
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::http_field_parsers::transfer_encoding_value_t::values
value_container_t values
Definition: transfer-encoding.hpp:98
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::transfer_encoding_value_t::known_transfer_coding_t::chunked
@ chunked
restinio::http_field_parsers::transfer_encoding_value_t::known_transfer_coding_t::gzip
@ gzip
restinio::http_field_parsers::transfer_encoding_value_t::transfer_extension_t::token
std::string token
Definition: transfer-encoding.hpp:78
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::transfer_encoding_value_t::gzip
static constexpr RESTINIO_NODISCARD known_transfer_coding_t gzip() noexcept
Definition: transfer-encoding.hpp:72
restinio::expected_t
nonstd::expected< T, E > expected_t
Definition: expected.hpp:22
basics.hpp
Utilities for parsing values of http-fields.
restinio
Definition: asio_include.hpp:21
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
variant.hpp
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::chunked
static constexpr RESTINIO_NODISCARD known_transfer_coding_t chunked() noexcept
Definition: transfer-encoding.hpp:60
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::http_field_parsers::transfer_encoding_value_t
Tools for working with the value of Transfer-Encoding HTTP-field.
Definition: transfer-encoding.hpp:49
nonstd::variants::variant
Definition: variant.hpp:1209
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::make_parser
static RESTINIO_NODISCARD auto make_parser()
A factory function for a parser of Transfer-Encoding value.
Definition: transfer-encoding.hpp:107