RESTinio
user-agent.hpp
Go to the documentation of this file.
1 /*
2  * RESTinio
3  */
4 
5 /*!
6  * @file
7  * @brief Stuff related to value of User-Agent HTTP-field.
8  *
9  * @since v.0.6.4
10  */
11 
12 #pragma once
13 
14 #include <restinio/helpers/http_field_parsers/basics.hpp>
15 
16 #include <restinio/variant.hpp>
17 
18 namespace restinio
19 {
20 
21 namespace http_field_parsers
22 {
23 
24 //
25 // user_agent_value_t
26 //
27 /*!
28  * @brief Tools for working with the value of User-Agent HTTP-field.
29  *
30  * This struct represents parsed value of HTTP-field User-Agent
31  * (see https://tools.ietf.org/html/rfc7231#section-5.5.3):
32 @verbatim
33  User-Agent = product *( RWS ( product / comment ) )
34 
35  product = token ["/" product-version]
36  product-version = token
37 @endverbatim
38  *
39  * @since v.0.6.4
40  */
42 {
43  /*!
44  * @brief A type for holding an info about a product.
45  *
46  * @since v.0.6.4
47  */
48  struct product_t
49  {
52  };
53 
54  /*!
55  * @brief A type for holding an info about a product or a comment.
56  *
57  * @since v.0.6.4
58  */
60 
63 
64  /*!
65  * @brief A factory function for a parser of User-Agent value.
66  *
67  * @since v.0.6.4
68  */
70  static auto
72  {
74  token_p() >> &product_t::product,
75  maybe(
76  symbol('/'),
78  )
79  );
80 
81  return produce< user_agent_value_t >(
84  repeat( 0, N,
85  space(),
86  ows(),
89  comment_p() >> to_container()
90  )
91  )
93  );
94  }
95 
96  /*!
97  * @brief An attempt to parse User-Agent HTTP-field.
98  *
99  * @since v.0.6.4
100  */
104  {
106  }
107 };
108 
109 } /* namespace http_field_parsers */
110 
111 } /* namespace restinio */
A type for holding an info about a product.
Definition: user-agent.hpp:48
static RESTINIO_NODISCARD expected_t< user_agent_value_t, restinio::easy_parser::parse_error_t > try_parse(string_view_t what)
An attempt to parse User-Agent HTTP-field.
Definition: user-agent.hpp:103
restinio::optional_t< std::string > product_version
Definition: user-agent.hpp:51
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.
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