Moved SendResponse() to HttpResponse

master
Harald Wolff 2020-12-18 09:17:20 +01:00
parent 6ac9df7c16
commit a76088b628
2 changed files with 40 additions and 9 deletions

View File

@ -170,18 +170,14 @@ namespace ln.http
catch (Exception e)
{
Logging.Log(e);
SendResponse(
connection.GetStream(),
httpRequest,
HttpResponse
.InternalServerError()
.Content(e)
);
HttpResponse
.InternalServerError()
.Content(e)
.SendResponse(connection.GetStream(), httpRequest);
}
HttpRequest.ClearCurrent();
connection.GetStream().Close();
connection.Close();
} finally
{
lock (currentConnections)
@ -191,6 +187,8 @@ namespace ln.http
public static void SendResponse(Stream stream, HttpRequest request, HttpResponse response)
{
response.SendResponse(stream, request);
/*
request.FinishRequest();
response.SetHeader("Content-Length", response.ContentStream.Length.ToString());
@ -217,6 +215,7 @@ namespace ln.http
response.ContentStream.Dispose();
stream.Flush();
*/
}
public static void StartSimpleServer(string[] arguments)

View File

@ -173,6 +173,38 @@ namespace ln.http
public virtual void SendResponse(Stream stream, HttpRequest httpRequest)
{
httpRequest.FinishRequest();
SetHeader("Content-Length", ContentStream.Length.ToString());
StreamWriter streamWriter = new StreamWriter(stream);
streamWriter.NewLine = "\r\n";
streamWriter.WriteLine("{0} {1} {2}", httpRequest.Protocol, (int)HttpStatusCode, HttpStatusCode.ToString());
foreach (String headerName in GetHeaderNames())
{
streamWriter.WriteLine("{0}: {1}", headerName, GetHeader(headerName));
}
foreach (HttpCookie httpCookie in Cookies)
{
streamWriter.WriteLine("Set-Cookie: {0}", httpCookie.ToString());
}
streamWriter.WriteLine();
streamWriter.Flush();
ContentStream.Position = 0;
ContentStream.CopyTo(stream);
ContentStream.Close();
ContentStream.Dispose();
stream.Flush();
}
}
}