userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
request.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <chrono>
7
#include <initializer_list>
8
#include <memory>
9
#include <string>
10
#include <string_view>
11
#include <type_traits>
12
#include <unordered_map>
13
#include <utility>
14
#include <vector>
15
16
#include <
userver/clients/dns/resolver_fwd.hpp
>
17
#include <
userver/clients/http/cancellation_policy.hpp
>
18
#include <
userver/clients/http/error.hpp
>
19
#include <userver/clients/http/expected_status_codes.hpp>
20
#include <
userver/clients/http/response.hpp
>
21
#include <
userver/clients/http/response_future.hpp
>
22
#include <
userver/concurrent/queue_fwd.hpp
>
23
#include <
userver/crypto/certificate.hpp
>
24
#include <
userver/crypto/private_key.hpp
>
25
#include <
userver/http/http_version.hpp
>
26
#include <userver/utils/impl/internal_tag_fwd.hpp>
27
#include <userver/utils/impl/source_location.hpp>
28
#include <
userver/utils/not_null.hpp
>
29
#include <
userver/utils/str_icase.hpp
>
30
#include <
userver/utils/zstring_view.hpp
>
31
32
USERVER_NAMESPACE_BEGIN
33
34
namespace
tracing
{
35
class
TracingManagerBase
;
36
}
// namespace tracing
37
38
namespace
utils::impl {
39
class
WaitTokenStorageLock;
40
}
// namespace utils::impl
41
43
namespace
clients::http
{
44
45
class
RequestState;
46
class
StreamedResponse
;
47
class
WebSocketResponse
;
48
class
ConnectTo
;
49
class
Form
;
50
struct
DeadlinePropagationConfig
;
51
class
RequestStats;
52
class
DestinationStatistics;
53
struct
TestsuiteConfig;
54
class
MiddlewareBase
;
55
56
namespace
impl {
57
class
EasyWrapper;
58
class
RequestBackend;
59
}
// namespace impl
60
62
enum class
HttpMethod
{ kGet, kPost, kHead, kPut, kDelete, kPatch, kOptions };
63
65
std::string_view
ToStringView
(
HttpMethod
method);
66
68
HttpMethod
HttpMethodFromString
(std::string_view method_str);
69
70
using
USERVER_NAMESPACE::http::HttpVersion;
71
73
enum class
HttpAuthType
{
74
kBasic
,
75
kDigest
,
76
kDigestIE
,
77
kNegotiate
,
78
kNtlm
,
79
kNtlmWb
,
80
kAny
,
81
kAnySafe
,
82
};
83
85
enum class
ProxyAuthType
{
86
kBasic
,
87
kDigest
,
88
kDigestIE
,
89
kBearer
,
90
kNegotiate
,
91
kNtlm
,
92
kNtlmWb
,
93
kAny
,
94
kAnySafe
,
95
};
96
97
ProxyAuthType
ProxyAuthTypeFromString(std::string_view auth_name);
98
100
class
Request
final {
101
public
:
103
using
Cookies
= std::unordered_map<std::string, std::string, utils::StrCaseHash>;
104
108
explicit
Request
(std::shared_ptr<impl::RequestBackend> backend);
109
111
// For internal use only.
112
explicit
Request
(
113
impl::EasyWrapper&&,
114
RequestStats&& req_stats,
115
DestinationStatistics& dest_stats,
116
clients::dns::Resolver
* resolver,
117
const
tracing::TracingManagerBase
& tracing_manager
118
);
120
122
Request
&
method
(
HttpMethod
method
) &;
124
Request
method
(
HttpMethod
method
) &&;
125
127
Request
&
get
() &;
129
Request
get
() &&;
131
Request
&
get
(std::string
url
) &;
133
Request
get
(std::string
url
) &&;
134
136
Request
&
head
() &;
138
Request
head
() &&;
140
Request
&
head
(std::string
url
) &;
142
Request
head
(std::string
url
) &&;
143
145
Request
&
post
() &;
147
Request
post
() &&;
149
Request
&
post
(std::string
url
, std::string
data
= {}) &;
151
Request
post
(std::string
url
, std::string
data
= {}) &&;
153
Request
&
post
(std::string
url
,
Form
&&
form
) &;
155
Request
post
(std::string
url
,
Form
&&
form
) &&;
156
158
Request
&
put
() &;
160
Request
put
() &&;
162
Request
&
put
(std::string
url
, std::string
data
= {}) &;
164
Request
put
(std::string
url
, std::string
data
= {}) &&;
165
167
Request
&
patch
() &;
169
Request
patch
() &&;
171
Request
&
patch
(std::string
url
, std::string
data
= {}) &;
173
Request
patch
(std::string
url
, std::string
data
= {}) &&;
174
176
Request
&
delete_method
() &;
178
Request
delete_method
() &&;
180
Request
&
delete_method
(std::string
url
) &;
182
Request
delete_method
(std::string
url
) &&;
184
Request
&
delete_method
(std::string
url
, std::string
data
) &;
186
Request
delete_method
(std::string
url
, std::string
data
) &&;
187
189
Request
&
set_custom_http_request_method
(std::string
method
) &;
191
Request
set_custom_http_request_method
(std::string
method
) &&;
192
194
Request
&
url
(std::string
url
) &;
196
Request
url
(std::string
url
) &&;
197
199
Request
&
data
(std::string
data
) &;
201
Request
data
(std::string
data
) &&;
202
204
Request
&
form
(
Form
&&
form
) &;
206
Request
form
(
Form
&&
form
) &&;
207
209
Request
&
headers
(
const
Headers
&
headers
) &;
211
Request
headers
(
const
Headers
&
headers
) &&;
213
Request
&
headers
(
const
std::initializer_list<std::pair<utils::zstring_view, utils::zstring_view>>&
headers
) &;
215
Request
headers
(
const
std::initializer_list<std::pair<utils::zstring_view, utils::zstring_view>>&
headers
) &&;
216
218
Request
&
http_auth_type
(
219
HttpAuthType
value,
220
bool
auth_only,
221
utils::zstring_view
user,
222
utils::zstring_view
password
223
) &;
225
Request
http_auth_type
(
226
HttpAuthType
value,
227
bool
auth_only,
228
utils::zstring_view
user,
229
utils::zstring_view
password
230
) &&;
231
233
Request
&
proxy_headers
(
const
Headers
&
headers
) &;
235
Request
proxy_headers
(
const
Headers
&
headers
) &&;
237
Request
&
proxy_headers
(
const
std::initializer_list<std::pair<utils::zstring_view, utils::zstring_view>>&
headers
) &;
239
Request
proxy_headers
(
const
std::initializer_list<std::pair<utils::zstring_view, utils::zstring_view>>&
headers
) &&;
240
242
Request
&
user_agent
(
utils::zstring_view
value) &;
244
Request
user_agent
(
utils::zstring_view
value) &&;
245
250
Request
&
proxy
(
utils::zstring_view
value) &;
252
Request
proxy
(
utils::zstring_view
value) &&;
253
255
Request
&
proxy_auth_type
(
ProxyAuthType
value) &;
257
Request
proxy_auth_type
(
ProxyAuthType
value) &&;
258
260
Request
&
cookies
(
const
Cookies
&
cookies
) &;
262
Request
cookies
(
const
Cookies
&
cookies
) &&;
263
265
Request
&
cookies
(
const
std::unordered_map<std::string, std::string>&
cookies
) &;
267
Request
cookies
(
const
std::unordered_map<std::string, std::string>&
cookies
) &&;
268
270
Request
&
follow_redirects
(
bool
follow =
true
) &;
272
Request
follow_redirects
(
bool
follow =
true
) &&;
273
276
Request
&
timeout
(
long
timeout_ms) &;
278
Request
timeout
(
long
timeout_ms) &&;
280
Request
&
timeout
(std::chrono::milliseconds timeout_ms) & {
return
timeout
(timeout_ms.count()); }
282
Request
timeout
(std::chrono::milliseconds timeout_ms) && {
return
std::move(this->
timeout
(timeout_ms.count())); }
283
285
Request
&
verify
(
bool
verify
=
true
) &;
287
Request
verify
(
bool
verify
=
true
) &&;
288
290
Request
&
ca_info
(
utils::zstring_view
file_path) &;
292
Request
ca_info
(
utils::zstring_view
file_path) &&;
293
295
Request
&
ca
(
crypto::Certificate
cert) &;
297
Request
ca
(
crypto::Certificate
cert) &&;
298
300
Request
&
crl_file
(
utils::zstring_view
file_path) &;
302
Request
crl_file
(
utils::zstring_view
file_path) &&;
303
307
Request
&
client_key_cert
(
crypto::PrivateKey
pkey,
crypto::Certificate
cert) &;
309
Request
client_key_cert
(
crypto::PrivateKey
pkey,
crypto::Certificate
cert) &&;
310
312
Request
&
http_version
(
HttpVersion
version) &;
314
Request
http_version
(
HttpVersion
version) &&;
315
321
Request
&
retry
(
short
retries = 3,
bool
on_fails =
true
) &;
322
Request
retry
(
short
retries = 3,
bool
on_fails =
true
) &&;
323
327
Request
&
unix_socket_path
(
utils::zstring_view
path) &;
328
Request
unix_socket_path
(
utils::zstring_view
path) &&;
329
331
Request
&
use_ipv4
() &;
333
Request
use_ipv4
() &&;
334
336
Request
&
use_ipv6
() &;
338
Request
use_ipv6
() &&;
339
342
Request
&
connect_to
(
const
ConnectTo
&
connect_to
) &;
344
Request
connect_to
(
const
ConnectTo
&
connect_to
) &&;
345
347
template
<
typename
T>
348
requires
std::is_same_v<ConnectTo, T>
349
Request
&
connect_to
(T&&) {
350
static_assert
(!
sizeof
(T),
"ConnectTo argument must not be temporary, it must outlive Request"
);
351
return
*
this
;
352
}
353
355
Request
&
SetMiddlewaresList
(
const
std::vector<
utils::NotNull<MiddlewareBase*>
>&
middlewares
) &;
356
365
Request
&
SetIncompleteTlsConnectionCloseExpected
(
bool
expect) &;
367
Request
SetIncompleteTlsConnectionCloseExpected
(
bool
expect) &&;
368
371
Request
&
SetLoggedUrl
(std::string
url
) &;
373
Request
SetLoggedUrl
(std::string
url
) &&;
374
381
Request
&
SetExpectedStatusCodes
(
ExpectedStatusCodes
status_codes) &;
383
Request
SetExpectedStatusCodes
(
ExpectedStatusCodes
status_codes) &&;
384
387
Request
&
SetUrlTemplate
(std::string url_template) &;
389
Request
SetUrlTemplate
(std::string url_template) &&;
390
394
Request
&
SetDestinationMetricName
(
const
std::string& destination) &;
396
Request
SetDestinationMetricName
(
const
std::string& destination) &&;
397
399
// Set testsuite related settings. For internal use only.
400
void
SetTestsuiteConfig(
const
std::shared_ptr<const TestsuiteConfig>& config) &;
401
402
void
SetAllowedUrlsExtra(
const
std::vector<std::string>& urls) &;
403
404
// Set deadline propagation settings. For internal use only.
405
void
SetDeadlinePropagationConfig(
const
DeadlinePropagationConfig
& deadline_propagation_config) &;
406
407
void
SetWaitToken(utils::impl::InternalTag, utils::impl::WaitTokenStorageLock&&);
409
411
Request
&
DisableReplyDecoding
() &;
413
Request
DisableReplyDecoding
() &&;
414
415
void
SetCancellationPolicy(
CancellationPolicy
cp);
416
418
Request
&
SetTracingManager
(
const
tracing::TracingManagerBase
&) &;
420
Request
SetTracingManager
(
const
tracing::TracingManagerBase
&) &&;
421
433
[[nodiscard]]
ResponseFuture
async_perform
(
434
utils::impl::SourceLocation location = utils::impl::SourceLocation::Current()
435
);
436
440
[[nodiscard]]
StreamedResponse
async_perform_stream_body
(
441
const
std::shared_ptr<concurrent::StringStreamQueue>& queue,
442
utils::impl::SourceLocation location = utils::impl::SourceLocation::Current()
443
);
444
453
[[nodiscard]] std::shared_ptr<Response>
perform
(
454
utils::impl::SourceLocation location = utils::impl::SourceLocation::Current()
455
);
456
460
[[nodiscard]]
WebSocketResponse
PerformWebSocketHandshake
(
461
utils::impl::SourceLocation location = utils::impl::SourceLocation::Current()
462
);
463
465
const
std::string&
GetUrl
() const&;
467
const
std
::
string
&
GetUrl
() && = delete;
468
470
const
std
::
string
&
GetData
() const&;
472
const
std
::
string
&
GetData
() && = delete;
473
475
std
::
string
ExtractData
();
476
486
void
SetUrlUserinfoAllowed
(
bool
allowed);
487
488
private:
489
std
::shared_ptr<RequestState> pimpl_;
490
std
::shared_ptr<impl::RequestBackend> alternative_;
491
};
492
493
}
// namespace clients::http
494
495
USERVER_NAMESPACE_END
userver
clients
http
request.hpp
Generated on
for userver by
Doxygen
1.17.0