From 4571b979fd9556fae1d938bef0b2c2841f22e783 Mon Sep 17 00:00:00 2001 From: GHXX Date: Wed, 27 May 2026 23:28:13 +0200 Subject: [PATCH] fix SetStatusCodeAndDisposeAsync(HttpStatusCode.NotModified) breaking --- SimpleHttpServer/Types/RequestContext.cs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/SimpleHttpServer/Types/RequestContext.cs b/SimpleHttpServer/Types/RequestContext.cs index ffe8f0a..0b12685 100644 --- a/SimpleHttpServer/Types/RequestContext.cs +++ b/SimpleHttpServer/Types/RequestContext.cs @@ -44,19 +44,14 @@ public class RequestContext : IDisposable { public async Task SetStatusCodeAndDisposeAsync(int status) { using (this) { SetStatusCode(status); - await WriteToRespAsync("\n\n"); - await RespWriter.FlushAsync(); - } - } - - public async Task SetStatusCodeAndDisposeAsync(HttpStatusCode status) { - using (this) { - SetStatusCode((int) status); - await WriteToRespAsync("\n\n"); - await RespWriter.FlushAsync(); + if (status != (int)HttpStatusCode.NotModified) { // NotModified must not write any data to response + await WriteToRespAsync("\n\n"); + await RespWriter.FlushAsync(); + } } } + public async Task SetStatusCodeAndDisposeAsync(HttpStatusCode status) => await SetStatusCodeAndDisposeAsync((int) status); public async Task SetStatusCodeAndDisposeAsync(int status, string description) { using (this) {