Fix try-block in Server.cs
This commit is contained in:
parent
d41de84262
commit
8f51d22303
@ -713,23 +713,18 @@ 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)
|
||||
else if (content is FileStream stream)
|
||||
{
|
||||
string contentType = stream.Name.Split('.')[^1];
|
||||
response.AddHeader("Cache-Control", "max-age=600");
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user