1/*
2 * Copyright 2020 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *   Kyle Ambroff-Kao, kyle@ambroffkao.com
7 */
8#ifndef TEST_SERVER_H
9#define TEST_SERVER_H
10
11#include <string>
12#include <vector>
13
14#include <os/support/SupportDefs.h>
15#include <os/support/Url.h>
16
17
18// Binds to a random unused TCP port.
19class RandomTCPServerPort
20{
21public:
22	RandomTCPServerPort();
23	~RandomTCPServerPort();
24
25	status_t InitCheck() const;
26	int FileDescriptor() const;
27	uint16_t Port() const;
28
29private:
30	status_t fInitStatus;
31	int fSocketFd;
32	uint16_t fServerPort;
33};
34
35
36class ChildProcess
37{
38public:
39	ChildProcess();
40	~ChildProcess();
41
42	status_t Start(const std::vector<std::string>& args);
43
44private:
45	pid_t fChildPid;
46};
47
48
49enum class TestServerMode {
50	Http,
51	Https,
52};
53
54
55class TestServer
56{
57public:
58	TestServer(TestServerMode mode);
59
60	status_t Start();
61	BUrl BaseUrl() const;
62
63private:
64	TestServerMode fMode;
65	ChildProcess fChildProcess;
66	RandomTCPServerPort fPort;
67};
68
69
70class TestProxyServer
71{
72public:
73	status_t Start();
74	uint16_t Port() const;
75
76private:
77	ChildProcess fChildProcess;
78	RandomTCPServerPort fPort;
79};
80
81
82#endif // TEST_SERVER_H
83