userver: userver/utest/http_server_mock.hpp Source File
Loading...
Searching...
No Matches
http_server_mock.hpp
1#pragma once
2
3#include <cstdint>
4#include <map>
5
6#include <userver/utest/simple_server.hpp>
7
8#include <userver/clients/http/request.hpp>
9#include <userver/clients/http/response.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace utest {
14
15class HttpServerMock {
16public:
17 struct HttpRequest {
18 clients::http::HttpMethod method{clients::http::HttpMethod::kGet};
19 std::string path;
20
21 std::multimap<std::string, std::string> query;
22 clients::http::Headers headers;
23 std::string body;
24 };
25
26 struct HttpResponse {
27 int response_status{200};
28 clients::http::Headers headers;
29 std::string body;
30 };
31
32 using HttpHandler = std::function<HttpResponse(const HttpRequest&)>;
33
34 HttpServerMock(HttpHandler http_handler, SimpleServer::Protocol protocol = SimpleServer::kTcpIpV4);
35
36 std::string GetBaseUrl() const;
37
38 std::uint64_t GetConnectionsOpenedCount() const;
39
40private:
41 friend class HttpConnection;
42
43 HttpHandler http_handler_;
44 SimpleServer server_;
45};
46
47} // namespace utest
48
49USERVER_NAMESPACE_END