diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-05-05 13:55:38 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-05-05 13:55:38 -0400 |
| commit | 3a8b567f14ec3353cf55e296e6f06e13632b2e10 (patch) | |
| tree | 5112d8469106caa247420a1db3b4443da348d2a7 /SocketHttpListener.Portable | |
| parent | 364c8206bf500ac466d5360ddfe01b67fa8b59a9 (diff) | |
update file responses
Diffstat (limited to 'SocketHttpListener.Portable')
| -rw-r--r-- | SocketHttpListener.Portable/Net/HttpListenerResponse.cs | 2 | ||||
| -rw-r--r-- | SocketHttpListener.Portable/Net/ResponseStream.cs | 28 |
2 files changed, 17 insertions, 13 deletions
diff --git a/SocketHttpListener.Portable/Net/HttpListenerResponse.cs b/SocketHttpListener.Portable/Net/HttpListenerResponse.cs index d9f91c0cc..3cb6a0d75 100644 --- a/SocketHttpListener.Portable/Net/HttpListenerResponse.cs +++ b/SocketHttpListener.Portable/Net/HttpListenerResponse.cs @@ -480,6 +480,8 @@ namespace SocketHttpListener.Net headers.SetInternal("Set-Cookie", cookie.ToString()); } + headers.SetInternal("Status", status_code.ToString(CultureInfo.InvariantCulture)); + using (StreamWriter writer = new StreamWriter(ms, encoding, 256, true)) { writer.Write("HTTP/{0} {1} {2}\r\n", version, status_code, status_description); diff --git a/SocketHttpListener.Portable/Net/ResponseStream.cs b/SocketHttpListener.Portable/Net/ResponseStream.cs index 71d081046..dea4049d5 100644 --- a/SocketHttpListener.Portable/Net/ResponseStream.cs +++ b/SocketHttpListener.Portable/Net/ResponseStream.cs @@ -344,13 +344,6 @@ namespace SocketHttpListener.Net private async Task TransmitFileManaged(string path, long offset, long count, FileShareMode fileShareMode, CancellationToken cancellationToken) { - var chunked = response.SendChunked; - - if (!chunked) - { - await WriteAsync(_emptyBuffer, 0, 0, cancellationToken).ConfigureAwait(false); - } - using (var fs = _fileSystem.GetFileStream(path, FileOpenMode.Open, FileAccessMode.Read, fileShareMode, true)) { if (offset > 0) @@ -358,7 +351,7 @@ namespace SocketHttpListener.Net fs.Position = offset; } - var targetStream = chunked ? this : stream; + var targetStream = this; if (count > 0) { @@ -374,14 +367,23 @@ namespace SocketHttpListener.Net private static async Task CopyToInternalAsync(Stream source, Stream destination, long copyLength, CancellationToken cancellationToken) { var array = new byte[81920]; - int count; - while ((count = await source.ReadAsync(array, 0, array.Length, cancellationToken).ConfigureAwait(false)) != 0) + int bytesRead; + + while ((bytesRead = await source.ReadAsync(array, 0, array.Length, cancellationToken).ConfigureAwait(false)) != 0) { - var bytesToCopy = Math.Min(count, copyLength); + if (bytesRead == 0) + { + break; + } + + var bytesToWrite = Math.Min(bytesRead, copyLength); - await destination.WriteAsync(array, 0, Convert.ToInt32(bytesToCopy), cancellationToken).ConfigureAwait(false); + if (bytesToWrite > 0) + { + await destination.WriteAsync(array, 0, Convert.ToInt32(bytesToWrite), cancellationToken).ConfigureAwait(false); + } - copyLength -= bytesToCopy; + copyLength -= bytesToWrite; if (copyLength <= 0) { |
