aboutsummaryrefslogtreecommitdiff
path: root/zenserver/testing/httptest.cpp
blob: 2d469c936b3a9501dc8761051449363b9d1d7cdb (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright Epic Games, Inc. All Rights Reserved.

#include "httptest.h"

namespace zen {

HttpTestingService::HttpTestingService()
{
	m_Router.RegisterRoute(
		"hello",
		[this](HttpRouterRequest& Req) { Req.ServerRequest().WriteResponse(HttpResponseCode::OK); },
		HttpVerb::kGet);

	m_Router.RegisterRoute(
		"echo",
		[this](HttpRouterRequest& Req) {
			IoBuffer Body = Req.ServerRequest().ReadPayload();
			Req.ServerRequest().WriteResponse(HttpResponseCode::OK, HttpContentType::kBinary, Body);
		},
		HttpVerb::kPost);
}

HttpTestingService::~HttpTestingService()
{
}

const char*
HttpTestingService::BaseUri() const
{
	return "/testing/";
}

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

Ref<IHttpPackageHandler>
HttpTestingService::HandlePackageRequest(HttpServerRequest& HttpServiceRequest)
{
	RwLock::ExclusiveLockScope _(m_RwLock);

	const uint32_t RequestId = HttpServiceRequest.RequestId();

	if (auto It = m_HandlerMap.find(RequestId); It != m_HandlerMap.end())
	{
		Ref<HttpTestingService::PackageHandler> Handler = std::move(It->second);

		m_HandlerMap.erase(It);

		return Handler.Get();
	}

	auto InsertResult = m_HandlerMap.insert({RequestId, nullptr});

	_.ReleaseNow();

	return (InsertResult.first->second = new PackageHandler(*this, RequestId)).Get();
}

//////////////////////////////////////////////////////////////////////////

HttpTestingService::PackageHandler::PackageHandler(HttpTestingService& Svc, uint32_t RequestId) : m_Svc(Svc), m_RequestId(RequestId)
{
}

HttpTestingService::PackageHandler::~PackageHandler()
{
}

void
HttpTestingService::PackageHandler::FilterOffer(std::vector<IoHash>& OfferCids)
{
	ZEN_UNUSED(OfferCids);
	// No-op
	return;
}
void
HttpTestingService::PackageHandler::OnRequestBegin()
{
}

void
HttpTestingService::PackageHandler::OnRequestComplete()
{
}

zen::IoBuffer
HttpTestingService::PackageHandler::CreateTarget(const IoHash& Cid, uint64_t StorageSize)
{
	ZEN_UNUSED(Cid, StorageSize);

	return {};
}

}  // namespace zen