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
http_server_mock.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/utest/http_server_mock.hpp
4
/// @brief @copybrief utest::HttpServerMock
5
6
#
include
<
cstdint
>
7
#
include
<
map
>
8
9
#
include
<
userver
/
utest
/
simple_server
.
hpp
>
10
11
#
include
<
userver
/
clients
/
http
/
request
.
hpp
>
12
#
include
<
userver
/
clients
/
http
/
response
.
hpp
>
13
14
USERVER_NAMESPACE_BEGIN
15
16
namespace
utest {
17
18
/// @ingroup userver_utest
19
///
20
/// @brief Toy HTTP server for testing; for raw TCP or TLS testing use utest::SimpleServer.
21
///
22
/// In constructor opens specified ports in localhost address and listens on
23
/// them. On each HTTP request calls user callback.
24
///
25
/// ## Example usage:
26
/// @snippet core/utest/src/utest/http_server_mock_test.cpp Sample HttpServerMock usage
27
class
HttpServerMock
{
28
public
:
29
/// Structure with HTTP request that is passed to the HttpHandler callback
30
struct
HttpRequest
{
31
clients::http::
HttpMethod
method{clients::http::
HttpMethod
::kGet};
32
std::string path;
33
34
std::multimap<std::string, std::string> query;
35
clients::http::Headers headers;
36
std::string body;
37
};
30
struct
HttpRequest
{
…
};
38
39
/// Structure with HTTP response to return from the HttpHandler callback
40
struct
HttpResponse
{
41
int
response_status{200};
42
clients::http::Headers headers;
43
std::string body;
44
};
40
struct
HttpResponse
{
…
};
45
46
/// Callback that is invoked on each HTTP request
47
using
HttpHandler = std::function<
HttpResponse
(
const
HttpRequest
&)>;
48
49
HttpServerMock(HttpHandler http_handler, SimpleServer::Protocol protocol = SimpleServer::kTcpIpV4);
50
51
/// Returns URL to the server, for example 'http://127.0.0.1:8080'
52
std::string
GetBaseUrl
()
const
;
53
54
std::uint64_t GetConnectionsOpenedCount()
const
;
55
56
private
:
57
friend
class
HttpConnection;
58
59
HttpHandler http_handler_;
60
SimpleServer server_;
61
};
27
class
HttpServerMock
{
…
};
62
63
}
// namespace utest
64
65
USERVER_NAMESPACE_END
userver
utest
http_server_mock.hpp
Generated on Wed Apr 30 2025 15:55:44 for userver by
Doxygen
1.13.2