From 7f954bd567f3d43dc5aae2c857231f58c4f24b25 Mon Sep 17 00:00:00 2001 From: Alecio Furanze Date: Wed, 15 Nov 2023 11:52:15 +0200 Subject: [PATCH] add method to Response.cs send response --- src/HTTP/Response.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/HTTP/Response.cs b/src/HTTP/Response.cs index 1df0971b..28594931 100644 --- a/src/HTTP/Response.cs +++ b/src/HTTP/Response.cs @@ -9,6 +9,25 @@ public Response(HttpListenerResponse httpListenerResponse) RawResponse = httpListenerResponse; } + public void Send(int statusCode, byte[] buffer) + { + ThreadPool.QueueUserWorkItem(_ => + { + try + { + RawResponse.StatusCode = statusCode; + RawResponse.ContentEncoding = Encoding.UTF8; + RawResponse.ContentLength64 = buffer.Length; + RawResponse.OutputStream.Write(buffer, 0, buffer.Length); + RawResponse.Close(); + } + catch (Exception e) + { + // TODO: Handle it + Console.WriteLine(e); + } + }); + } } } \ No newline at end of file