RESTinio
transfer-encoding.hpp
Go to the documentation of this file.
1 /*
2  * RESTinio
3  */
4 
5 /*!
6  * @file
7  * @brief Stuff related to value of Transfer-Encoding HTTP-field.
8  *
9  * @since v.0.6.9
10  */
11 
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 //
29 /*!
30  * @brief Tools for working with the value of Transfer-Encoding HTTP-field.
31  *
32  * This struct represents parsed value of HTTP-field Transfer-Encoding
33  * (see https://tools.ietf.org/html/rfc7230#section-3.3.1 and
34  * https://tools.ietf.org/html/rfc7230#section-4):
35 @verbatim
36 Transfer-Encoding = 1#transfer-coding
37 transfer-coding = "chunked"
38  / "compress"
39  / "deflate"
40  / ("gzip" | "x-gzip")
41  / transfer-extension
42 transfer-extension = token *( OWS ";" OWS transfer-parameter )
43 transfer-parameter = token BWS "=" BWS ( token / quoted-string )
44 @endverbatim
45  *
46  * @since v.0.6.9
47  */
49 {
50  //! Enumeration for transfer-coding values from RFC7230.
52  {
53  chunked,
54  compress,
55  deflate,
56  gzip,
57  };
58 
60  static constexpr known_transfer_coding_t chunked() noexcept
61  { return known_transfer_coding_t::chunked; }
62 
64  static constexpr known_transfer_coding_t compress() noexcept
66 
68  static constexpr known_transfer_coding_t deflate() noexcept
69  { return known_transfer_coding_t::deflate; }
70 
72  static constexpr known_transfer_coding_t gzip() noexcept
73  { return known_transfer_coding_t::gzip; }
74 
75  //! Description of transfer-extension.
77  {
80 
82  bool
83  operator==( const transfer_extension_t & o ) const noexcept
84  {
85  return std::tie(this->token, this->transfer_parameters) ==
87  }
88  };
89 
90  //! Type for one value from Transfer-Encoding HTTP-field.
91  using value_t = variant_t<
94  >;
95 
97 
99 
100  /*!
101  * @brief A factory function for a parser of Transfer-Encoding value.
102  *
103  * @since v.0.6.9
104  */
106  static auto
108  {
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() ),
127  ) >> as_result()
128  )
129  )
131  );
132  }
133 
134  /*!
135  * @brief An attempt to parse Transfer-Encoding HTTP-field.
136  *
137  * @since v.0.6.9
138  */
140  static expected_t<
144  {
146  }
147 };
148 
149 } /* namespace http_field_parsers */
150 
151 } /* namespace restinio */
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.
RESTINIO_NODISCARD 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.
known_transfer_coding_t
Enumeration for transfer-coding values from RFC7230.
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, optional_t< Value_Type > >::type opt_value(const Parameter_Container &params, string_view_t key)
Gets the value of a parameter specified by key wrapped in optional_t<Value_Type> if parameter exists ...
Definition: value_or.hpp:64