fix some serving issues
This commit is contained in:
parent
94b23cadc5
commit
8cdff9268a
|
|
@ -252,7 +252,7 @@ public sealed class HttpServer {
|
||||||
if (reqPath.StartsWith(k)) { // do a static serve
|
if (reqPath.StartsWith(k)) { // do a static serve
|
||||||
wasStaticlyServed = true;
|
wasStaticlyServed = true;
|
||||||
var relativeStaticReqPath = reqPath[k.Length..];
|
var relativeStaticReqPath = reqPath[k.Length..];
|
||||||
var staticResponsePath = Path.Combine(v, relativeStaticReqPath);
|
var staticResponsePath = Path.Combine(v, relativeStaticReqPath.TrimStart('/'));
|
||||||
|
|
||||||
if (Path.GetRelativePath(v, staticResponsePath).Contains("..")) {
|
if (Path.GetRelativePath(v, staticResponsePath).Contains("..")) {
|
||||||
requestLogger.Warning($"Blocked GET request to {reqPath} as somehow the target file does not lie inside the static serve folder? Are you using symlinks?");
|
requestLogger.Warning($"Blocked GET request to {reqPath} as somehow the target file does not lie inside the static serve folder? Are you using symlinks?");
|
||||||
|
|
@ -262,7 +262,7 @@ public sealed class HttpServer {
|
||||||
|
|
||||||
if (File.Exists(staticResponsePath)) {
|
if (File.Exists(staticResponsePath)) {
|
||||||
rc.SetStatusCode(HttpStatusCode.OK);
|
rc.SetStatusCode(HttpStatusCode.OK);
|
||||||
using var f = File.OpenRead(v);
|
using var f = File.OpenRead(staticResponsePath);
|
||||||
await f.CopyToAsync(rc.ListenerContext.Response.OutputStream);
|
await f.CopyToAsync(rc.ListenerContext.Response.OutputStream);
|
||||||
} else {
|
} else {
|
||||||
await rc.SetStatusCodeAndDisposeAsync(HttpStatusCode.NotFound);
|
await rc.SetStatusCodeAndDisposeAsync(HttpStatusCode.NotFound);
|
||||||
|
|
@ -278,8 +278,8 @@ public sealed class HttpServer {
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
await HandleDefaultErrorPageAsync(rc, 500);
|
await HandleDefaultErrorPageAsync(rc, 500);
|
||||||
mainLogger.Fatal($"Caught otherwise uncaught exception while ProcessingRequest:\n{ex}");
|
mainLogger.Fatal($"Caught otherwise uncaught exception while ProcessingRequest:\n{ex}");
|
||||||
}
|
} finally {
|
||||||
finally {
|
try { await rc.RespWriter.FlushAsync(); } catch (ObjectDisposedException) { }
|
||||||
rc.ListenerContext.Response.Close();
|
rc.ListenerContext.Response.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -288,6 +288,7 @@ public sealed class HttpServer {
|
||||||
|
|
||||||
|
|
||||||
private static async Task HandleDefaultErrorPageAsync(RequestContext ctx, int errorCode) {
|
private static async Task HandleDefaultErrorPageAsync(RequestContext ctx, int errorCode) {
|
||||||
|
ctx.SetStatusCode(errorCode);
|
||||||
await ctx.WriteLineToRespAsync($"""
|
await ctx.WriteLineToRespAsync($"""
|
||||||
<body>
|
<body>
|
||||||
<h1>Oh no, an error occurred!</h1>
|
<h1>Oh no, an error occurred!</h1>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user