mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
The dashboard's web server answers one request at a time, so converting a big .nif (glom files up to tens of MB) held up every other request, flairs included. - dWeb: Web::Defer hands a request to another thread; the reply is sent from the web thread on its next poll (DeferredQueue). A client that leaves first cancels it and the late reply is dropped. The synchronous route API is unchanged. - Web::Shutdown closes connections while the state their close events touch is still alive; the destructor no longer runs handlers during static destruction (stopping the dashboard aborted in ~WSClient). - WorkerPool: priority lanes, with one thread only for urgent work (flairs, small models, textures), and limited background work. - Scenery: mesh and texture routes (and the showcase's) convert on the pool; thread-safe memory and disk caches, one conversion per model at a time with waiters sharing it; zones are converted ahead onto the disk cache while viewed. - Setting scenery_workers (0: half the cores, 2 to 4). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
75 lines
2.1 KiB
C++
75 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <algorithm>
|
|
#include "eHTTPStatusCode.h"
|
|
#include "json.hpp"
|
|
|
|
/**
|
|
* HTTP Request Context
|
|
*
|
|
* Carries all request metadata through the middleware chain.
|
|
* Populated by the Web framework before middleware/handlers are called.
|
|
*/
|
|
struct HTTPContext {
|
|
// Request metadata
|
|
std::string method{};
|
|
std::string path{}; // lowercased: routes match without regard to case
|
|
std::string originalPath{}; // as sent, for parameters whose case matters (file names)
|
|
std::string queryString{};
|
|
std::string body{};
|
|
|
|
// Request headers (header name -> value)
|
|
// Header names are lowercase for case-insensitive lookup
|
|
std::map<std::string, std::string> headers{};
|
|
|
|
// Client information
|
|
std::string clientIP{};
|
|
unsigned long connectionId = 0; // the web server's id of the connection (for Web::Defer)
|
|
|
|
// Authentication information (populated by auth middleware)
|
|
bool isAuthenticated = false;
|
|
std::string authenticatedUser{};
|
|
uint32_t accountId = 0;
|
|
uint8_t gmLevel = 0;
|
|
|
|
// Custom data for middleware to communicate
|
|
std::map<std::string, std::string> userData{};
|
|
|
|
/**
|
|
* Get header value (case-insensitive)
|
|
*/
|
|
const std::string& GetHeader(const std::string& headerName) const {
|
|
static const std::string empty{};
|
|
|
|
// Convert to lowercase for comparison
|
|
std::string lowerName = headerName;
|
|
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower);
|
|
|
|
const auto it = headers.find(lowerName);
|
|
return it != headers.end() ? it->second : empty;
|
|
}
|
|
|
|
/**
|
|
* Set header value (automatically lowercased)
|
|
*/
|
|
void SetHeader(const std::string& headerName, const std::string& value) {
|
|
std::string lowerName = headerName;
|
|
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower);
|
|
headers[lowerName] = value;
|
|
}
|
|
|
|
/**
|
|
* Get user data as JSON for template rendering
|
|
*/
|
|
nlohmann::json GetUserDataJson() const {
|
|
nlohmann::json userData;
|
|
userData["username"] = authenticatedUser;
|
|
userData["gmLevel"] = gmLevel;
|
|
userData["accountId"] = accountId;
|
|
return userData;
|
|
}
|
|
};
|