Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Backport #2686 to 1.x-WorkingBranch #2784

Open
wants to merge 1 commit into
base: 1.x-WorkingBranch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 0 additions & 73 deletions src/Nancy/Extensions/StreamExtensions.cs

This file was deleted.

34 changes: 6 additions & 28 deletions src/Nancy/IO/RequestStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
{
using System;
using System.IO;
using System.Threading.Tasks;
using Nancy.Extensions;

/// <summary>
/// A <see cref="Stream"/> decorator that can handle moving the stream out from memory and on to disk when the contents reaches a certain length.
/// </summary>
public class RequestStream : Stream
{
internal const int BufferSize = 4096;

public static long DEFAULT_SWITCHOVER_THRESHOLD = 81920;

private bool disableStreamSwitching;
Expand Down Expand Up @@ -71,40 +71,18 @@ public RequestStream(Stream stream, long expectedLength, long thresholdLength, b

if (!this.stream.CanSeek)
{
var task =
MoveToWritableStream();

task.Wait();

if (task.IsFaulted)
{
throw new InvalidOperationException("Unable to copy stream", task.Exception);
}
this.MoveToWritableStream();
}

this.stream.Position = 0;
}

private Task<object> MoveToWritableStream()
private void MoveToWritableStream()
{
var tcs = new TaskCompletionSource<object>();

var sourceStream = this.stream;
this.stream = new MemoryStream(StreamExtensions.BufferSize);

sourceStream.CopyTo(this, (source, destination, ex) =>
{
if (ex != null)
{
tcs.SetException(ex);
}
else
{
tcs.SetResult(null);
}
});
this.stream = new MemoryStream(BufferSize);

return tcs.Task;
sourceStream.CopyTo(this.stream);
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/Nancy/Nancy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@
<Compile Include="ErrorHandling\RouteExecutionEarlyExitException.cs" />
<Compile Include="Extensions\ModelValidationErrorExtensions.cs" />
<Compile Include="Extensions\RequestStreamExtensions.cs" />
<Compile Include="Extensions\StreamExtensions.cs" />
<Compile Include="Extensions\TypeExtensions.cs" />
<Compile Include="Diagnostics\DefaultRequestTracing.cs" />
<Compile Include="Diagnostics\DescriptionAttribute.cs" />
Expand Down