userver
C++ Async Framework
Toggle main menu visibility
Documentation
API Groups
Namespaces
Reference
Class List
Class Index
File List
Macros
All
e
i
l
r
t
u
Functions
Macros
e
i
l
r
t
u
Examples
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
Concepts
Loading...
Searching...
No Matches
content_type.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/http/content_type.hpp
4
/// @brief @copybrief http::ContentType
5
6
#
include
<
iosfwd
>
7
#
include
<
stdexcept
>
8
#
include
<
string
>
9
#
include
<
string_view
>
10
11
#
include
<
userver
/
logging
/
fwd
.
hpp
>
12
#
include
<
userver
/
utils
/
str_icase
.
hpp
>
13
14
USERVER_NAMESPACE_BEGIN
15
16
/// HTTP helpers
17
namespace
http
{
18
19
/// @brief Content-Type parsing error
20
class
MalformedContentType
:
public
std::runtime_error {
21
using
std::runtime_error::runtime_error;
22
};
20
class
MalformedContentType
:
public
std::runtime_error {
…
};
23
24
/// @ingroup userver_universal userver_containers
25
///
26
/// @brief Content-Type representation
27
class
ContentType
{
28
public
:
29
/// Constructor from a single content-type/media-range header value
30
/// as per RFC7231.
31
/// @{
32
/* implicit */
ContentType
(std::string_view);
33
/* implicit */
ContentType(
const
std::string&);
34
/* implicit */
ContentType(
const
char
*);
35
/// @}
36
37
/// Media type (application/json).
38
std::string
MediaType
()
const
;
39
40
/// "type" token of media type (application).
41
const
std::string&
TypeToken
()
const
;
42
43
/// "subtype" token of media type (json).
44
const
std::string&
SubtypeToken
()
const
;
45
46
/// Whether the "charset" option was explicitly specified.
47
bool
HasExplicitCharset
()
const
;
48
49
/// Charset (utf-8).
50
const
std::string&
Charset
()
const
;
51
52
/// Value of "q" parameter in range 0--1000.
53
int
Quality
()
const
;
54
55
/// Whether this media range accepts specified content type.
56
/// Differs from equality comparison in wildcard support.
57
bool
DoesAccept
(
const
ContentType
&)
const
;
58
59
/// Value of "boundary" parameter.
60
const
std::string&
Boundary
()
const
;
61
62
/// Builds a string representation of content-type/media-range
63
std::string
ToString
()
const
;
64
65
private
:
66
friend
logging
::LogHelper& operator<<(
logging
::LogHelper&,
const
ContentType
&);
67
friend
std::ostream& operator<<(std::ostream&,
const
ContentType
&);
68
69
void
BuildStringRepresentation();
70
71
std::string type_;
72
std::string subtype_;
73
std::string charset_;
74
std::string boundary_;
75
int
quality_;
76
77
std::string string_representation_;
78
};
27
class
ContentType
{
…
};
79
80
bool
operator==(
const
ContentType
&,
const
ContentType
&);
81
bool
operator!=(
const
ContentType
&,
const
ContentType
&);
82
83
/// Weak ordering for Accept media-ranges checking.
84
/// Positions less specific types before more specific, so that the most
85
/// specific type can be matched first.
86
bool
operator
<(
const
ContentType
&,
const
ContentType
&);
87
88
class
ContentTypeHash
{
89
public
:
90
size_t operator()(
const
ContentType
&)
const
;
91
92
private
:
93
utils
::
StrIcaseHash
str_hasher_;
94
};
88
class
ContentTypeHash
{
…
};
95
96
namespace
content_type {
97
98
extern
const
ContentType
kApplicationOctetStream;
99
extern
const
ContentType
kApplicationJson;
100
extern
const
ContentType
kTextPlain;
101
102
}
// namespace content_type
103
}
// namespace http
17
namespace
http
{
…
}
104
105
USERVER_NAMESPACE_END
userver
http
content_type.hpp
Generated on Wed Apr 30 2025 15:48:43 for userver by
Doxygen
1.13.2