userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
content_type.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <iosfwd>
7
#include <stdexcept>
8
#include <string>
9
#include <string_view>
10
11
#include <fmt/core.h>
12
13
#include <
userver/logging/fwd.hpp
>
14
#include <
userver/utils/str_icase.hpp
>
15
16
USERVER_NAMESPACE_BEGIN
17
19
namespace
http
{
20
22
class
MalformedContentType :
public
std::runtime_error {
23
public
:
24
using
std::runtime_error::runtime_error;
25
26
MalformedContentType(
const
MalformedContentType&) =
default
;
27
MalformedContentType(MalformedContentType&&) =
default
;
28
MalformedContentType& operator=(
const
MalformedContentType&) =
default
;
29
MalformedContentType& operator=(MalformedContentType&&) =
default
;
30
31
~MalformedContentType()
override
;
32
};
33
37
class
ContentType
{
38
public
:
42
/* implicit */
ContentType
(std::string_view);
43
/* implicit */
ContentType
(
const
std::string&);
44
/* implicit */
ContentType
(
const
char
*);
46
48
std::string
MediaType
()
const
;
49
51
const
std::string&
TypeToken
()
const
;
52
54
const
std::string&
SubtypeToken
()
const
;
55
57
bool
HasExplicitCharset
()
const
;
58
60
const
std::string&
Charset
()
const
;
61
63
int
Quality
()
const
;
64
67
bool
DoesAccept
(
const
ContentType
&)
const
;
68
70
const
std::string&
Boundary
()
const
;
71
73
std::string
ToString
()
const
;
74
75
private
:
76
friend
logging::LogHelper
& operator<<(
logging::LogHelper
&,
const
ContentType
&);
77
friend
std::ostream& operator<<(std::ostream&,
const
ContentType
&);
78
79
void
BuildStringRepresentation();
80
81
std::string type_;
82
std::string subtype_;
83
std::string charset_;
84
std::string boundary_;
85
int
quality_;
86
87
std::string string_representation_;
88
};
89
90
bool
operator==(
const
ContentType
&,
const
ContentType
&);
91
95
bool
operator<
(
const
ContentType
&,
const
ContentType
&);
96
97
class
ContentTypeHash
{
98
public
:
99
size_t
operator()(
const
ContentType
&)
const
;
100
101
private
:
102
utils::StrIcaseHash
str_hasher_;
103
};
104
106
namespace
content_type
{
107
108
extern
const
ContentType
kApplicationOctetStream;
109
extern
const
ContentType
kApplicationJson;
110
extern
const
ContentType
kTextPlain;
111
112
}
// namespace content_type
113
}
// namespace http
114
115
USERVER_NAMESPACE_END
116
117
template
<>
118
struct
fmt::formatter<USERVER_NAMESPACE::
http::ContentType
> {
119
constexpr
static
auto
parse(format_parse_context& ctx) {
return
ctx.begin(); }
120
121
template
<
typename
FormatContext>
122
auto
format(
const
USERVER_NAMESPACE::http::ContentType& value, FormatContext& ctx)
const
->
decltype
(ctx.out()) {
123
return
fmt::format_to(ctx.out(),
"{}"
, value.ToString());
124
}
125
};
userver
http
content_type.hpp
Generated on
for userver by
Doxygen
1.17.0