Add changeable server

This commit is contained in:
2025-10-14 23:12:43 -05:00
parent 1a419d9575
commit 931cf49320
13 changed files with 139 additions and 13 deletions

View File

@@ -32,6 +32,22 @@ class MyWebServer : public IHttpServer {
.SendStream(fs);
return true;
}
else if(ctx.path == "/mypath.html")
{
std::string txt = "<h1>Root: " + HttpUtils::HtmlEncode(ctx.GetServerRoot()) + "</h1>";
ctx.WithMimeType("text/html").SendText(txt);
return true;
}
else if(ctx.path == "/getabsolute.html")
{
std::string path;
if(ctx.queryParams.TryGetFirst("path",path))
{
std::string txt = "<h1>Path: " + HttpUtils::HtmlEncode(ctx.MakeAbsolute(path)) + "</h1>";
ctx.WithMimeType("text/html").SendText(txt);
return true;
}
}
else if(ctx.path == "/streaming.html")
{
StreamWriter writer(ctx.OpenResponseStream());
@@ -109,6 +125,12 @@ class MyOtherWebServer : public IHttpServer
ctx.SendText(data->text);
return true;
}
else if(ctx.path == "/mypath.html")
{
std::string txt = "<h1>Root: " + HttpUtils::HtmlEncode(ctx.GetServerRoot()) + "</h1>";
ctx.WithMimeType("text/html").SendText(txt);
return true;
}
return false;
}