2
0

Compare commits

..

No commits in common. "682fd0bc2a9d41a2b623540794430e57b22d52d3" and "03aeab44cd081bfd798a9a6449113becbd5b7ebc" have entirely different histories.

View File

@ -706,6 +706,10 @@ public class Server : GlobalBase
private void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null)
{
if (response.OutputStream.CanWrite == false)
{
Log($"No response sent to request: Stream closed before response could be sent.");
}
//Log($"Response: {statusCode} {content}");
response.StatusCode = (int)statusCode;
response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
@ -718,16 +722,13 @@ public class Server : GlobalBase
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();
}
else if (content is FileStream stream)
{
string contentType = stream.Name.Split('.')[^1];
response.AddHeader("Cache-Control", "max-age=600");
switch (contentType.ToLower())
{
case "gif":
@ -746,9 +747,9 @@ public class Server : GlobalBase
}
stream.CopyTo(response.OutputStream);
response.OutputStream.Close();
stream.Close();
}
response.OutputStream.Close();
}
catch (HttpListenerException e)
{