From db66e72bd311f4b0eb8f3f3233a82250b82f1a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20N=C3=A4geli?= Date: Sun, 13 Sep 2026 20:57:55 +0200 Subject: [PATCH] Fix API browser module emitting two content-type headers --- Modules/Pages/Extensions.cs | 5 ++--- Testing/Acceptance/Modules/ApiBrowsing/ApplicationTests.cs | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Modules/Pages/Extensions.cs b/Modules/Pages/Extensions.cs index 85f80ccb5..5e0f10f16 100644 --- a/Modules/Pages/Extensions.cs +++ b/Modules/Pages/Extensions.cs @@ -7,7 +7,7 @@ namespace GenHTTP.Modules.Pages; public static class Extensions { - private static readonly ByteString HtmlContentType = new("text/html; charset=\"utf-8\""); + private static readonly ContentType HtmlContentType = new("text/html; charset=\"utf-8\""); /// /// Creates a response that can be returned by a handler to serve @@ -17,8 +17,7 @@ public static class Extensions /// The HTML page to be served /// The HTML page response public static IResponseBuilder GetPage(this IRequest request, string content) => request.Respond() - .Content(new StringContent(content)) - .Header(KnownHeaders.ContentType, HtmlContentType); + .Content(new StringContent(content, HtmlContentType)); /// /// Escapes the given string so it can safely be used in HTML. diff --git a/Testing/Acceptance/Modules/ApiBrowsing/ApplicationTests.cs b/Testing/Acceptance/Modules/ApiBrowsing/ApplicationTests.cs index 1d55a10ce..a7c8a6b8c 100644 --- a/Testing/Acceptance/Modules/ApiBrowsing/ApplicationTests.cs +++ b/Testing/Acceptance/Modules/ApiBrowsing/ApplicationTests.cs @@ -62,6 +62,8 @@ public async Task TestScalar(ServerEngine engine) await response.AssertStatusAsync(HttpStatusCode.OK); + Assert.AreEqual("text/html", response.Content.Headers.ContentType?.MediaType); + AssertX.Contains("Scalar", await response.GetContentAsync()); }