HTTPnet is a high performance .NET library for HTTP and WebSocket based communication. It provides a HTTP/WebSocket server and a powerful processing pipeline for HTTP request and their responses.
In your example files are sent to client this way:
context.HttpContext.Response.Body = File.OpenRead(filename);
But Stream returned by function OpenRead is never disposed explicitly. It is not possible to write to the file until Stream is disposed later by garbage collector.
I think that it is possible to dispose it after call to ResponseWriter.WriteAsync in file HttpSessionHandler.cs. Something like this:
try
{
var httpContext = new HttpContext(httpRequest, httpResponse, _clientSession, this);
await _clientSession.HandleHttpRequestAsync(httpContext);
if (httpContext.Response != null)
{
await ResponseWriter.WriteAsync(httpContext.Response, _clientSession.CancellationToken);
HttpNetTrace.Verbose(nameof(HttpSessionHandler), "Response '{0}' sent to '{1}'.", httpContext.Response.StatusCode, _clientSession.Client.Identifier);
}
if (httpContext.CloseConnection)
{
_clientSession.Close();
}
}
finally
{
httpResponse.Body?.Dispose();
}
In your example files are sent to client this way:
context.HttpContext.Response.Body = File.OpenRead(filename);
But Stream returned by function OpenRead is never disposed explicitly. It is not possible to write to the file until Stream is disposed later by garbage collector.
I think that it is possible to dispose it after call to ResponseWriter.WriteAsync in file HttpSessionHandler.cs. Something like this: