Fix try-block in Server.cs
This commit is contained in:
parent
1bd20791b8
commit
dfa8e66f34
@ -713,45 +713,46 @@ public class Server : GlobalBase
|
||||
response.AddHeader("Access-Control-Max-Age", "1728000");
|
||||
response.AppendHeader("Access-Control-Allow-Origin", "*");
|
||||
|
||||
if (content is not Stream)
|
||||
try
|
||||
{
|
||||
response.ContentType = "application/json";
|
||||
response.AddHeader("Cache-Control", "no-store");
|
||||
try
|
||||
if (content is not Stream)
|
||||
{
|
||||
response.ContentType = "application/json";
|
||||
response.AddHeader("Cache-Control", "no-store");
|
||||
response.OutputStream.Write(content is not null
|
||||
? Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(content))
|
||||
: Array.Empty<byte>());
|
||||
response.OutputStream.Close();
|
||||
}
|
||||
catch (HttpListenerException e)
|
||||
else if (content is FileStream stream)
|
||||
{
|
||||
Log(e.ToString());
|
||||
string contentType = stream.Name.Split('.')[^1];
|
||||
response.AddHeader("Cache-Control", "max-age=600");
|
||||
switch (contentType.ToLower())
|
||||
{
|
||||
case "gif":
|
||||
response.ContentType = "image/gif";
|
||||
break;
|
||||
case "png":
|
||||
response.ContentType = "image/png";
|
||||
break;
|
||||
case "jpg":
|
||||
case "jpeg":
|
||||
response.ContentType = "image/jpeg";
|
||||
break;
|
||||
case "log":
|
||||
response.ContentType = "text/plain";
|
||||
break;
|
||||
}
|
||||
|
||||
stream.CopyTo(response.OutputStream);
|
||||
response.OutputStream.Close();
|
||||
stream.Close();
|
||||
}
|
||||
}
|
||||
else if(content is FileStream stream)
|
||||
catch (HttpListenerException e)
|
||||
{
|
||||
string contentType = stream.Name.Split('.')[^1];
|
||||
response.AddHeader("Cache-Control", "max-age=600");
|
||||
switch (contentType.ToLower())
|
||||
{
|
||||
case "gif":
|
||||
response.ContentType = "image/gif";
|
||||
break;
|
||||
case "png":
|
||||
response.ContentType = "image/png";
|
||||
break;
|
||||
case "jpg":
|
||||
case "jpeg":
|
||||
response.ContentType = "image/jpeg";
|
||||
break;
|
||||
case "log":
|
||||
response.ContentType = "text/plain";
|
||||
break;
|
||||
}
|
||||
stream.CopyTo(response.OutputStream);
|
||||
response.OutputStream.Close();
|
||||
stream.Close();
|
||||
Log(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user