Fix try-block in Server.cs

This commit is contained in:
Glax 2024-08-26 13:21:34 +02:00
parent 1bd20791b8
commit dfa8e66f34

View File

@ -713,22 +713,17 @@ public class Server : GlobalBase
response.AddHeader("Access-Control-Max-Age", "1728000");
response.AppendHeader("Access-Control-Allow-Origin", "*");
try
{
if (content is not Stream)
{
response.ContentType = "application/json";
response.AddHeader("Cache-Control", "no-store");
try
{
response.OutputStream.Write(content is not null
? Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(content))
: Array.Empty<byte>());
response.OutputStream.Close();
}
catch (HttpListenerException e)
{
Log(e.ToString());
}
}
else if (content is FileStream stream)
{
string contentType = stream.Name.Split('.')[^1];
@ -749,9 +744,15 @@ public class Server : GlobalBase
response.ContentType = "text/plain";
break;
}
stream.CopyTo(response.OutputStream);
response.OutputStream.Close();
stream.Close();
}
}
catch (HttpListenerException e)
{
Log(e.ToString());
}
}
}