Skip to content

Commit

Permalink
add method to Response.cs send response
Browse files Browse the repository at this point in the history
  • Loading branch information
alec1o committed Nov 15, 2023
1 parent 879d280 commit 7f954bd
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/HTTP/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}

}
}

0 comments on commit 7f954bd

Please sign in to comment.