Commit 77d094c9 authored by NTAuthority's avatar NTAuthority

allow not closing the response stream

parent 76992d7d
......@@ -55,22 +55,28 @@ namespace uhttpsharp
private readonly Stream _headerStream = new MemoryStream();
private readonly bool _closeConnection;
private readonly bool _closeBaseStream;
public HttpResponse(HttpResponseCode code, string content, bool closeConnection)
: this(code, "text/html; charset=utf-8", StringToStream(content), closeConnection)
: this(code, "text/html; charset=utf-8", StringToStream(content), closeConnection, true)
{
}
public HttpResponse(HttpResponseCode code, string contentType, string content, bool closeConnection)
: this(code, contentType, StringToStream(content), closeConnection)
: this(code, contentType, StringToStream(content), closeConnection, true)
{
}
public HttpResponse(string contentType, Stream contentStream, bool closeConnection)
: this(HttpResponseCode.Ok, contentType, contentStream, closeConnection)
: this(HttpResponseCode.Ok, contentType, contentStream, closeConnection, true)
{
}
public HttpResponse(HttpResponseCode code, string contentType, Stream contentStream, bool keepAliveConnection)
: this(code, contentType, contentStream, keepAliveConnection, true)
{
}
public HttpResponse(HttpResponseCode code, string contentType, Stream contentStream, bool keepAliveConnection, bool closeBaseStream)
{
Protocol = "HTTP/1.1";
ContentType = contentType;
......@@ -78,6 +84,7 @@ namespace uhttpsharp
Code = code;
ContentStream = contentStream;
_closeConnection = !keepAliveConnection;
_closeBaseStream = closeBaseStream;
CacheHeaders(new StreamWriter(_headerStream));
}
......@@ -108,7 +115,10 @@ namespace uhttpsharp
await ContentStream.CopyToAsync(writer.BaseStream).ConfigureAwait(false);
// CitizenMP addition
ContentStream.Close();
if (_closeBaseStream)
{
ContentStream.Close();
}
await writer.BaseStream.FlushAsync().ConfigureAwait(false);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment