mirror of
https://github.com/C9Glax/tranga.git
synced 2025-01-12 03:17:33 +01:00
API Fix closed response socket
This commit is contained in:
parent
abc66511d8
commit
6508055b43
@ -67,8 +67,6 @@ public class Server
|
|||||||
|
|
||||||
internal void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null)
|
internal void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null)
|
||||||
{
|
{
|
||||||
if (!response.OutputStream.CanWrite)
|
|
||||||
return;
|
|
||||||
//logger?.WriteLine(this.GetType().ToString(), $"Sending response: {statusCode}");
|
//logger?.WriteLine(this.GetType().ToString(), $"Sending response: {statusCode}");
|
||||||
response.StatusCode = (int)statusCode;
|
response.StatusCode = (int)statusCode;
|
||||||
response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
|
response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
|
||||||
@ -76,9 +74,16 @@ public class Server
|
|||||||
response.AddHeader("Access-Control-Max-Age", "1728000");
|
response.AddHeader("Access-Control-Max-Age", "1728000");
|
||||||
response.AppendHeader("Access-Control-Allow-Origin", "*");
|
response.AppendHeader("Access-Control-Allow-Origin", "*");
|
||||||
response.ContentType = "application/json";
|
response.ContentType = "application/json";
|
||||||
|
try
|
||||||
|
{
|
||||||
response.OutputStream.Write(content is not null
|
response.OutputStream.Write(content is not null
|
||||||
? Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(content))
|
? Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(content))
|
||||||
: Array.Empty<byte>());
|
: Array.Empty<byte>());
|
||||||
|
}
|
||||||
|
catch (HttpListenerException)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
response.OutputStream.Close();
|
response.OutputStream.Close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user