userver: userver/utest/http_server_mock.hpp Source File
Loading...
Searching...
No Matches
http_server_mock.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <cstdint>
7#include <map>
8
10
13
14USERVER_NAMESPACE_BEGIN
15
16namespace utest {
17
27class HttpServerMock {
28public:
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;
36 std::string body;
37 };
38
40 struct HttpResponse {
41 int response_status{200};
43 std::string body;
44 };
45
47 using HttpHandler = std::function<HttpResponse(const HttpRequest&)>;
48
49 HttpServerMock(HttpHandler http_handler, SimpleServer::Protocol protocol = SimpleServer::kTcpIpV4);
50
52 std::string GetBaseUrl() const;
53
55 SimpleServer::Port GetPort() const;
56
57 std::uint64_t GetConnectionsOpenedCount() const;
58
59private:
60 friend class HttpConnection;
61
62 HttpHandler http_handler_;
63 SimpleServer server_;
64};
65
66} // namespace utest
67
68USERVER_NAMESPACE_END