Fix license compliance and fix things up, add reverse proxy, fix some security flaws with HttpUtils

This commit is contained in:
2026-08-31 20:57:18 -05:00
parent 313e75b14c
commit 3bce736834
41 changed files with 2227 additions and 384 deletions
+22 -3
View File
@@ -58,22 +58,36 @@ RouteServer::RouteServer(std::shared_ptr<IHttpServer> root) : root(root) {}
void RouteServer::Add(std::string method, std::string pattern,
ServerRequestHandler handler) {
mtx.Lock();
this->routes.emplace_back(pattern, method, handler);
mtx.Unlock();
}
bool RouteServer::Handle(ServerContext &ctx) {
auto pathArgs = ctx.pathArguments;
auto path = Tesses::Framework::Filesystem::VFSPath::ParseUriPath(ctx.path);
bool mustUnlock = true;
mtx.Lock();
for (auto &svr : this->routes) {
if (svr.method != ctx.method &&
!((svr.method == "GET" && ctx.method == "HEAD") ||
(svr.method == "HEAD" && ctx.method == "GET")))
continue;
ctx.pathArguments = pathArgs;
if (svr.Equals(path, ctx.pathArguments) && svr.handler &&
svr.handler(ctx))
return true;
if (svr.Equals(path, ctx.pathArguments) && svr.handler) {
auto hndl = svr.handler;
mtx.Unlock();
if (hndl(ctx)) {
return true;
}
mustUnlock = false;
break;
}
}
if (mustUnlock)
mtx.Unlock();
ctx.pathArguments = pathArgs;
if (this->root)
@@ -104,4 +118,9 @@ void RouteServer::Query(std::string pattern, ServerRequestHandler handler) {
void RouteServer::Options(std::string pattern, ServerRequestHandler handler) {
Add("OPTIONS", pattern, handler);
}
void RouteServer::Clear() {
mtx.Lock();
this->routes.clear();
mtx.Unlock();
}
} // namespace Tesses::Framework::Http