userver: userver/utest/simple_server.hpp Source File
Loading...
Searching...
No Matches
simple_server.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <cstdint>
7#include <functional>
8#include <initializer_list>
9#include <memory>
10#include <string>
11#include <vector>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace utest {
16
26class SimpleServer final {
27public:
29 struct Response {
30 enum Commands {
31 kWriteAndClose,
32 kTryReadMore,
33 kWriteAndContinue,
34 };
35
36 std::string data_to_send{};
37
39 Commands command{kWriteAndClose};
40 };
41
43 using Request = std::string;
44
46 using OnRequest = std::function<Response(const Request&)>;
47
48 using Port = unsigned short;
49 enum Protocol {
50 kTcpIpV4,
51 kTcpIpV6
52 };
53
54 SimpleServer(OnRequest callback, Protocol protocol = kTcpIpV4);
56
58 Port GetPort() const;
59
60 enum class Schema {
61 kHttp,
62 kHttps,
63 };
64
66 std::string GetBaseUrl(Schema type = Schema::kHttp) const;
67
68 std::uint64_t GetConnectionsOpenedCount() const;
69
70private:
71 class Impl;
72 const std::unique_ptr<Impl> pimpl_;
73};
74
75} // namespace utest
76
77USERVER_NAMESPACE_END