blob: 57d2d63f312ec9f29c267f9f515b0d4ded11ed38 (
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.
#pragma once
#include <zencore/logging.h>
#include <zencore/stats.h>
#include <zenhttp/httpserver.h>
#include <zenhttp/websocket.h>
#include <atomic>
namespace zen {
/**
* Test service to facilitate testing the HTTP framework and client interactions
*/
class HttpTestingService : public HttpService, public WebSocketService
{
public:
HttpTestingService();
~HttpTestingService();
virtual const char* BaseUri() const override;
virtual void HandleRequest(HttpServerRequest& Request) override;
virtual Ref<IHttpPackageHandler> HandlePackageRequest(HttpServerRequest& HttpServiceRequest) override;
class PackageHandler : public IHttpPackageHandler
{
public:
PackageHandler(HttpTestingService& Svc, uint32_t RequestId);
~PackageHandler();
virtual void FilterOffer(std::vector<IoHash>& OfferCids) override;
virtual void OnRequestBegin() override;
virtual IoBuffer CreateTarget(const IoHash& Cid, uint64_t StorageSize) override;
virtual void OnRequestComplete() override;
private:
HttpTestingService& m_Svc;
uint32_t m_RequestId;
};
private:
virtual void RegisterHandlers(WebSocketServer& Server) override;
virtual bool HandleRequest(const WebSocketMessage& Request) override;
HttpRequestRouter m_Router;
std::atomic<uint32_t> m_Counter{0};
metrics::OperationTiming m_TimingStats;
RwLock m_RwLock;
std::unordered_map<uint32_t, Ref<PackageHandler>> m_HandlerMap;
};
} // namespace zen
|