RESTinio
Toggle main menu visibility
Loading...
Searching...
No Matches
restinio
helpers
http_field_parsers
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
<
variant
>
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
*/
41
struct
user_agent_value_t
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
{
50
std::string
product
;
51
std::optional<std::string>
product_version
;
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
*/
59
using
tail_item_t
= std::variant<
product_t
, std::string >;
60
61
product_t
product
;
62
std
::
vector
<
tail_item_t
>
tail
;
63
64
/*!
65
* @brief A factory function for a parser of User-Agent value.
66
*
67
* @since v.0.6.4
68
*/
69
[[nodiscard]]
70
static
auto
71
make_parser
()
72
{
73
auto
product_producer = produce<
product_t
>(
74
token_p() >> &product_t::product,
75
maybe(
76
symbol(
'/'
),
77
token_p() >> &product_t::product_version
78
)
79
);
80
81
return
produce<
user_agent_value_t
>(
82
product_producer >> &user_agent_value_t::product,
83
produce< std::vector< tail_item_t > >(
84
repeat( 0, N,
85
space(),
86
ows(),
87
alternatives(
88
product_producer >> to_container(),
89
comment_p() >> to_container()
90
)
91
)
92
) >> &user_agent_value_t::tail
93
);
94
}
95
96
/*!
97
* @brief An attempt to parse User-Agent HTTP-field.
98
*
99
* @since v.0.6.4
100
*/
101
[[nodiscard]]
102
static
expected_t
<
user_agent_value_t
,
restinio
::
easy_parser
::
parse_error_t
>
103
try_parse
( string_view_t what )
104
{
105
return
restinio
::
easy_parser
::try_parse( what, make_parser() );
106
}
107
};
108
109
}
/* namespace http_field_parsers */
110
111
}
/* namespace restinio */
restinio::easy_parser
Definition
easy_parser.hpp:42
restinio::http_field_parsers
Definition
accept-charset.hpp:20
restinio
Definition
sendfile_operation_default.ipp:12
restinio::http_field_parsers::user_agent_value_t::product_t
A type for holding an info about a product.
Definition
user-agent.hpp:49
restinio::http_field_parsers::user_agent_value_t::product_t::product_version
std::optional< std::string > product_version
Definition
user-agent.hpp:51
restinio::http_field_parsers::user_agent_value_t::product_t::product
std::string product
Definition
user-agent.hpp:50
restinio::http_field_parsers::user_agent_value_t
Tools for working with the value of User-Agent HTTP-field.
Definition
user-agent.hpp:42
restinio::http_field_parsers::user_agent_value_t::try_parse
static 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::http_field_parsers::user_agent_value_t::tail
std::vector< tail_item_t > tail
Definition
user-agent.hpp:62
restinio::http_field_parsers::user_agent_value_t::tail_item_t
std::variant< product_t, std::string > tail_item_t
A type for holding an info about a product or a comment.
Definition
user-agent.hpp:59
restinio::http_field_parsers::user_agent_value_t::make_parser
static auto make_parser()
A factory function for a parser of User-Agent value.
Definition
user-agent.hpp:71
restinio::http_field_parsers::user_agent_value_t::product
product_t product
Definition
user-agent.hpp:61
Generated by
1.17.0