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 {
20public:
21						RandomTCPServerPort();
22						~RandomTCPServerPort();
23
24	status_t			InitCheck()							const;
25	int					FileDescriptor()					const;
26	uint16_t			Port()								const;
27
28private:
29	status_t			fInitStatus;
30	int					fSocketFd;
31	uint16_t			fServerPort;
32};
33
34
35class ChildProcess {
36public:
37						ChildProcess();
38						~ChildProcess();
39
40	status_t			Start(const std::vector<std::string>& args);
41private:
42	pid_t				fChildPid;
43};
44
45
46enum TestServerMode {
47	TEST_SERVER_MODE_HTTP,
48	TEST_SERVER_MODE_HTTPS,
49};
50
51
52class TestServer {
53public:
54						TestServer(TestServerMode mode);
55
56	status_t			Start();
57	BUrl				BaseUrl()							const;
58
59private:
60	TestServerMode		fMode;
61	ChildProcess		fChildProcess;
62	RandomTCPServerPort fPort;
63};
64
65
66class TestProxyServer {
67public:
68	status_t			Start();
69	uint16_t			Port()								const;
70
71private:
72	ChildProcess		fChildProcess;
73	RandomTCPServerPort	fPort;
74};
75
76
77#endif // TEST_SERVER_H
78