diff --git a/SimpleHttpServer/HttpServer.cs b/SimpleHttpServer/HttpServer.cs index 0d5fc04..e235541 100644 --- a/SimpleHttpServer/HttpServer.cs +++ b/SimpleHttpServer/HttpServer.cs @@ -137,13 +137,13 @@ public sealed class HttpServer { private string NormalizeUrlPath(string url) => '/' + url.TrimStart('/'); private async Task ProcessRequestAsync(HttpListenerContext ctx) { + using RequestContext rc = new RequestContext(ctx); try { var decUri = WebUtility.UrlDecode(ctx.Request.RawUrl)!; // TODO add path escape countermeasures+unittests var splitted = NormalizeUrlPath(decUri).Split('?', 2, StringSplitOptions.None); var path = WebUtility.UrlDecode(splitted.First()); - using var rc = new RequestContext(ctx); if (simpleEndpointMethodInfos.TryGetValue((decUri, ctx.Request.HttpMethod.ToUpperInvariant()), out var endpointInvocationInfo)) { var mi = endpointInvocationInfo.methodInfo; var qparams = endpointInvocationInfo.queryParameters; @@ -198,6 +198,7 @@ public sealed class HttpServer { } } catch (Exception ex) { + await HandleDefaultErrorPageAsync(rc, 500); logger.Fatal($"Caught otherwise uncaught exception while ProcessingRequest:\n{ex}"); } }