From 340c8ae9465fca22b4aee005b55dffdc16e9c3c2 Mon Sep 17 00:00:00 2001 From: Mike Nolan Date: Wed, 22 Jun 2022 15:03:20 -0500 Subject: [PATCH] Add Server header, connection close and urldecode on get params --- Tesses.WebServer.NetStandard/ServerContext.cs | 4 +++- Tesses.WebServer.NetStandard/SimpleHttpCode.cs | 3 ++- .../Tesses.WebServer.NetStandard.csproj | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Tesses.WebServer.NetStandard/ServerContext.cs b/Tesses.WebServer.NetStandard/ServerContext.cs index 421688b..c7e954e 100644 --- a/Tesses.WebServer.NetStandard/ServerContext.cs +++ b/Tesses.WebServer.NetStandard/ServerContext.cs @@ -23,6 +23,8 @@ namespace Tesses.WebServer RequestHeaders = headers; ResponseHeaders = new Dictionary>(); QueryParams = new Dictionary>(); + ResponseHeaders.Add("Server","Tesses.WebServer"); + ResponseHeaders.Add("Connection","close"); RawUrl=path; StatusCode = 200; @@ -64,7 +66,7 @@ namespace Tesses.WebServer string value = ""; if (itemSplit.Length == 2) { - value = itemSplit[1]; + value = WebUtility.UrlDecode( itemSplit[1]); } QueryParams.Add(key, value); } diff --git a/Tesses.WebServer.NetStandard/SimpleHttpCode.cs b/Tesses.WebServer.NetStandard/SimpleHttpCode.cs index feeebbf..b07f382 100644 --- a/Tesses.WebServer.NetStandard/SimpleHttpCode.cs +++ b/Tesses.WebServer.NetStandard/SimpleHttpCode.cs @@ -70,7 +70,7 @@ namespace Tesses.WebServer { //ctx.StatusCode = 200; int start = 0, end = (int)strm.Length - 1; - if (ctx.RequestHeaders.ContainsKey(BYTES_RANGE_HEADER)) + if (ctx.RequestHeaders.ContainsKey(BYTES_RANGE_HEADER) && strm.CanSeek) { if (ctx.RequestHeaders[BYTES_RANGE_HEADER].Count > 1) { @@ -100,6 +100,7 @@ namespace Tesses.WebServer { try { + if(strm.CanSeek) strm.Position = start; strm.CopyTo(ctx.NetworkStream, Math.Min(8 * 1024 * 1024, end - start + 1)); } diff --git a/Tesses.WebServer.NetStandard/Tesses.WebServer.NetStandard.csproj b/Tesses.WebServer.NetStandard/Tesses.WebServer.NetStandard.csproj index 7ce91b0..76d2c02 100644 --- a/Tesses.WebServer.NetStandard/Tesses.WebServer.NetStandard.csproj +++ b/Tesses.WebServer.NetStandard/Tesses.WebServer.NetStandard.csproj @@ -5,9 +5,9 @@ Tesses.WebServer Mike Nolan Tesses - 1.0.3.3 - 1.0.3.3 - 1.0.3.3 + 1.0.3.4 + 1.0.3.4 + 1.0.3.4 A TCP Listener HTTP(s) Server MIT HTTP, WebServer, Website