RESTinio

transfer-encoding.hpp
Go to the documentation of this file.
1/*
2 * RESTinio
3 */
4
12#pragma once
13
14#include <restinio/helpers/http_field_parsers/basics.hpp>
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//
48 struct transfer_encoding_value_t
49{
51 enum class known_transfer_coding_t
52 {
53 chunked,
54 compress,
55 deflate,
56 gzip,
57 };
58
59 RESTINIO_NODISCARD
60 static constexpr known_transfer_coding_t chunked() noexcept
61 { return known_transfer_coding_t::chunked; }
62
63 RESTINIO_NODISCARD
64 static constexpr known_transfer_coding_t compress() noexcept
65 { return known_transfer_coding_t::compress; }
66
67 RESTINIO_NODISCARD
68 static constexpr known_transfer_coding_t deflate() noexcept
69 { return known_transfer_coding_t::deflate; }
70
71 RESTINIO_NODISCARD
72 static constexpr known_transfer_coding_t gzip() noexcept
73 { return known_transfer_coding_t::gzip; }
74
76 struct transfer_extension_t
77 {
78 std::string token;
79 parameter_with_mandatory_value_container_t transfer_parameters;
80
81 RESTINIO_NODISCARD
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<
92 known_transfer_coding_t,
93 transfer_extension_t
94 >;
95
96 using value_container_t = std::vector< value_t >;
97
98 value_container_t values;
99
105 RESTINIO_NODISCARD
106 static auto
107 make_parser()
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() ),
119 expected_caseless_token_p("gzip")
120 >> just_result( gzip() ),
121 expected_caseless_token_p("x-gzip")
122 >> just_result( gzip() ),
123 produce< transfer_extension_t >(
124 token_p() >> to_lower() >> &transfer_extension_t::token,
125 params_with_value_p()
126 >> &transfer_extension_t::transfer_parameters
127 ) >> as_result()
128 )
129 )
130 ) >> &transfer_encoding_value_t::values
131 );
132 }
133
139 RESTINIO_NODISCARD
140 static expected_t<
141 transfer_encoding_value_t,
142 restinio::easy_parser::parse_error_t >
143 try_parse( string_view_t what )
144 {
145 return restinio::easy_parser::try_parse( what, make_parser() );
146 }
147};
148
149} /* namespace http_field_parsers */
150
151} /* namespace restinio */
152
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