userver: userver/utest/http_server_mock.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
http_server_mock.hpp
1#pragma once
2
3#include <atomic>
4#include <cstdint>
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 {
16 public:
17 struct HttpRequest {
18 clients::http::HttpMethod method{clients::http::HttpMethod::kGet};
19 std::string path;
20
21 std::unordered_map<std::string, std::string> query;
22 clients::http::Headers headers;
23 std::string body;
24 };
25
26 struct HttpResponse {
27 int response_status;
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,
35 SimpleServer::Protocol protocol = SimpleServer::kTcpIpV4);
36
37 std::string GetBaseUrl() const;
38
39 std::uint64_t GetConnectionsOpenedCount() const;
40
41 private:
42 friend class HttpConnection;
43
44 HttpHandler http_handler_;
45 SimpleServer server_;
46};
47
48} // namespace utest
49
50USERVER_NAMESPACE_END