aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/storage/upstream/upstreamservice.cpp
blob: e7f7d2d5ca03d311bd32dcbed1c44d6612d9cd81 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright Epic Games, Inc. All Rights Reserved.
#include "upstreamservice.h"

#include "upstreamcache.h"

#include <zencore/compactbinarybuilder.h>
#include <zencore/string.h>

namespace zen {

using namespace std::literals;

HttpUpstreamService::HttpUpstreamService(UpstreamCache& Upstream, AuthMgr& Mgr) : m_Upstream(Upstream), m_AuthMgr(Mgr)
{
	m_Router.RegisterRoute(
		"endpoints",
		[this](HttpRouterRequest& Req) {
			CbObjectWriter Writer;
			Writer.BeginArray("Endpoints"sv);
			m_Upstream.IterateEndpoints([&Writer](UpstreamEndpoint& Ep) {
				UpstreamEndpointInfo   Info	  = Ep.GetEndpointInfo();
				UpstreamEndpointStatus Status = Ep.GetStatus();

				Writer.BeginObject();
				Writer << "Name"sv << Info.Name;
				Writer << "Url"sv << Info.Url;
				Writer << "State"sv << ToString(Status.State);
				Writer << "Reason"sv << Status.Reason;
				Writer.EndObject();

				return true;
			});
			Writer.EndArray();
			Req.ServerRequest().WriteResponse(HttpResponseCode::OK, Writer.Save());
		},
		HttpVerb::kGet);
}

HttpUpstreamService::~HttpUpstreamService()
{
}

const char*
HttpUpstreamService::BaseUri() const
{
	return "/upstream/";
}

void
HttpUpstreamService::HandleRequest(zen::HttpServerRequest& Request)
{
	m_Router.HandleRequest(Request);
}

}  // namespace zen