diff options
| author | Stefan Boberg <[email protected]> | 2021-09-13 12:24:59 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-13 12:24:59 +0200 |
| commit | 4e2649977d034b913413d2cb35d4a88afc30393f (patch) | |
| tree | 9258d4329a2217d581aaedfb251a655692987d4d /zenserver/testing/httptest.cpp | |
| parent | Added Ref<>::Get to work around issue casting a pointer to a derived type to ... (diff) | |
| download | zen-4e2649977d034b913413d2cb35d4a88afc30393f.tar.xz zen-4e2649977d034b913413d2cb35d4a88afc30393f.zip | |
Changed interface for httpServerRequest::SessionId()/RequestId() so they share storage and lazy eval logic
They now call into ParseSessionId()/ParseRequestId() when required
Eliminates redundant logic in derived implementations
Also moved package transport code into httpshared.(cpp|h) for easier sharing with client code
Added some I/O error reporting in http.sys related code
Changed IHttpPackageHandler interface to support partially updated handling flow
Diffstat (limited to 'zenserver/testing/httptest.cpp')
| -rw-r--r-- | zenserver/testing/httptest.cpp | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/zenserver/testing/httptest.cpp b/zenserver/testing/httptest.cpp index d1955ca27..2d469c936 100644 --- a/zenserver/testing/httptest.cpp +++ b/zenserver/testing/httptest.cpp @@ -36,17 +36,33 @@ HttpTestingService::HandleRequest(HttpServerRequest& Request) m_Router.HandleRequest(Request); } -////////////////////////////////////////////////////////////////////////// - Ref<IHttpPackageHandler> HttpTestingService::HandlePackageRequest(HttpServerRequest& HttpServiceRequest) { - return new PackageHandler(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(const HttpServerRequest& Request) +////////////////////////////////////////////////////////////////////////// + +HttpTestingService::PackageHandler::PackageHandler(HttpTestingService& Svc, uint32_t RequestId) : m_Svc(Svc), m_RequestId(RequestId) { - ZEN_UNUSED(Request); } HttpTestingService::PackageHandler::~PackageHandler() @@ -61,7 +77,12 @@ HttpTestingService::PackageHandler::FilterOffer(std::vector<IoHash>& OfferCids) return; } void -HttpTestingService::PackageHandler::OnBeginChunks() +HttpTestingService::PackageHandler::OnRequestBegin() +{ +} + +void +HttpTestingService::PackageHandler::OnRequestComplete() { } @@ -73,9 +94,4 @@ HttpTestingService::PackageHandler::CreateTarget(const IoHash& Cid, uint64_t Sto return {}; } -void -HttpTestingService::PackageHandler::OnEndChunks() -{ -} - } // namespace zen |