RESTinio
Loading...
Searching...
No Matches
user-agent.hpp
Go to the documentation of this file.
1/*
2 * RESTinio
3 */
4
12#pragma once
13
15
16#include <variant>
17
18namespace restinio
19{
20
21namespace http_field_parsers
22{
23
24//
25// user_agent_value_t
26//
42{
48 struct product_t
49 {
50 std::string product;
51 std::optional<std::string> product_version;
52 };
53
59 using tail_item_t = std::variant< product_t, std::string >;
60
62 std::vector< tail_item_t > tail;
63
69 [[nodiscard]]
70 static auto
72 {
75 maybe(
76 symbol('/'),
78 )
79 );
80
83 produce< std::vector< tail_item_t > >(
84 repeat( 0, N,
85 space(),
86 ows(),
90 )
91 )
93 );
94 }
95
101 [[nodiscard]]
107};
108
109} /* namespace http_field_parsers */
110
111} /* namespace restinio */
112
Utilities for parsing values of http-fields.
auto space() noexcept
A factory function to create a clause that expects a space, extracts it and then skips it.
auto to_container()
A factory function to create a to_container_consumer.
auto symbol(char expected) noexcept
A factory function to create a clause that expects the speficied symbol, extracts it and then skips i...
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.
auto maybe(Clauses &&... clauses)
A factory function to create an optional clause.
auto alternatives(Clauses &&... clauses)
A factory function to create an alternatives clause.
auto produce(Clauses &&... clauses)
A factory function to create a producer that creates an instance of the target type by using specifie...
constexpr std::size_t N
A special marker that means infinite repetitions.
auto repeat(std::size_t min_occurences, std::size_t max_occurences, Clauses &&... clauses)
A factory function to create repetitor of subclauses.
auto token_p() noexcept
A factory function to create a token_producer.
Definition basics.hpp:987
auto ows() noexcept
A factory function to create an OWS clause.
Definition basics.hpp:941
auto comment_p()
A factory for producer of comment token.
Definition basics.hpp:882
run_on_this_thread_settings_t< Traits > on_this_thread()
A special marker for the case when http_server must be run on the context of the current thread.
std::string_view string_view_t
nonstd::expected< T, E > expected_t
Definition expected.hpp:18
A type for holding an info about a product.
Tools for working with the value of User-Agent HTTP-field.
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.
std::variant< product_t, std::string > tail_item_t
A type for holding an info about a product or a comment.
static auto make_parser()
A factory function for a parser of User-Agent value.