diff --git a/src/Http/Http.Abstractions/ref/Microsoft.AspNetCore.Http.Abstractions.netcoreapp3.0.cs b/src/Http/Http.Abstractions/ref/Microsoft.AspNetCore.Http.Abstractions.netcoreapp3.0.cs
index 9dd9e01997..819234838c 100644
--- a/src/Http/Http.Abstractions/ref/Microsoft.AspNetCore.Http.Abstractions.netcoreapp3.0.cs
+++ b/src/Http/Http.Abstractions/ref/Microsoft.AspNetCore.Http.Abstractions.netcoreapp3.0.cs
@@ -250,7 +250,7 @@ namespace Microsoft.AspNetCore.Http
{
protected HttpRequest() { }
public abstract System.IO.Stream Body { get; set; }
- public virtual System.IO.Pipelines.PipeReader BodyReader { get { throw null; } set { } }
+ public virtual System.IO.Pipelines.PipeReader BodyReader { get { throw null; } }
public abstract long? ContentLength { get; set; }
public abstract string ContentType { get; set; }
public abstract Microsoft.AspNetCore.Http.IRequestCookieCollection Cookies { get; set; }
@@ -274,7 +274,7 @@ namespace Microsoft.AspNetCore.Http
{
protected HttpResponse() { }
public abstract System.IO.Stream Body { get; set; }
- public virtual System.IO.Pipelines.PipeWriter BodyWriter { get { throw null; } set { } }
+ public virtual System.IO.Pipelines.PipeWriter BodyWriter { get { throw null; } }
public abstract long? ContentLength { get; set; }
public abstract string ContentType { get; set; }
public abstract Microsoft.AspNetCore.Http.IResponseCookies Cookies { get; }
diff --git a/src/Http/Http.Abstractions/src/HttpRequest.cs b/src/Http/Http.Abstractions/src/HttpRequest.cs
index a63438450b..4a6c58b7e0 100644
--- a/src/Http/Http.Abstractions/src/HttpRequest.cs
+++ b/src/Http/Http.Abstractions/src/HttpRequest.cs
@@ -105,9 +105,9 @@ namespace Microsoft.AspNetCore.Http
public abstract Stream Body { get; set; }
///
- /// Gets or sets the request body pipe .
+ /// Gets the request body pipe .
///
- public virtual PipeReader BodyReader { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
+ public virtual PipeReader BodyReader { get => throw new NotImplementedException(); }
///
/// Checks the Content-Type header for form types.
diff --git a/src/Http/Http.Abstractions/src/HttpResponse.cs b/src/Http/Http.Abstractions/src/HttpResponse.cs
index d5a144dd7d..9df4f095e6 100644
--- a/src/Http/Http.Abstractions/src/HttpResponse.cs
+++ b/src/Http/Http.Abstractions/src/HttpResponse.cs
@@ -45,9 +45,9 @@ namespace Microsoft.AspNetCore.Http
public abstract Stream Body { get; set; }
///
- /// Gets or sets the response body pipe
+ /// Gets the response body pipe
///
- public virtual PipeWriter BodyWriter { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
+ public virtual PipeWriter BodyWriter { get => throw new NotImplementedException(); }
///
/// Gets or sets the value for the Content-Length response header.
diff --git a/src/Http/Http.Abstractions/test/HttpResponseWritingExtensionsTests.cs b/src/Http/Http.Abstractions/test/HttpResponseWritingExtensionsTests.cs
index 70684be914..0591abdce6 100644
--- a/src/Http/Http.Abstractions/test/HttpResponseWritingExtensionsTests.cs
+++ b/src/Http/Http.Abstractions/test/HttpResponseWritingExtensionsTests.cs
@@ -3,8 +3,7 @@
using System;
using System.IO;
-using System.IO.Pipelines;
-using System.IO.Pipelines.Tests;
+using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
@@ -36,15 +35,12 @@ namespace Microsoft.AspNetCore.Http
[MemberData(nameof(Encodings))]
public async Task WritingTextThatRequiresMultipleSegmentsWorks(Encoding encoding)
{
- // Need to change the StreamPipeWriter with a capped MemoryPool
- var memoryPool = new TestMemoryPool(maxBufferSize: 16);
var outputStream = new MemoryStream();
- var streamPipeWriter = new StreamPipeWriter(outputStream, minimumSegmentSize: 0, memoryPool);
HttpContext context = new DefaultHttpContext();
- context.Response.BodyWriter = streamPipeWriter;
+ context.Response.Body = outputStream;
- var inputString = "昨日すき焼きを食べました";
+ var inputString = string.Concat(Enumerable.Repeat("昨日すき焼きを食べました", 1000));
var expected = encoding.GetBytes(inputString);
await context.Response.WriteAsync(inputString, encoding);
@@ -52,11 +48,8 @@ namespace Microsoft.AspNetCore.Http
var actual = new byte[expected.Length];
var length = outputStream.Read(actual);
- var res1 = encoding.GetString(actual);
- var res2 = encoding.GetString(expected);
Assert.Equal(expected.Length, length);
Assert.Equal(expected, actual);
- streamPipeWriter.Complete();
}
[Theory]
diff --git a/src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.netstandard2.0.cs b/src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.netstandard2.0.cs
index 8c0f10b5dc..c97e11f219 100644
--- a/src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.netstandard2.0.cs
+++ b/src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.netstandard2.0.cs
@@ -246,7 +246,7 @@ namespace Microsoft.AspNetCore.Http.Features
}
public partial interface IRequestBodyPipeFeature
{
- System.IO.Pipelines.PipeReader Reader { get; set; }
+ System.IO.Pipelines.PipeReader Reader { get; }
}
public partial interface IRequestCookiesFeature
{
@@ -254,7 +254,7 @@ namespace Microsoft.AspNetCore.Http.Features
}
public partial interface IResponseBodyPipeFeature
{
- System.IO.Pipelines.PipeWriter Writer { get; set; }
+ System.IO.Pipelines.PipeWriter Writer { get; }
}
public partial interface IResponseCookiesFeature
{
diff --git a/src/Http/Http.Features/src/IRequestBodyPipeFeature.cs b/src/Http/Http.Features/src/IRequestBodyPipeFeature.cs
index 9357edb421..99e109b99d 100644
--- a/src/Http/Http.Features/src/IRequestBodyPipeFeature.cs
+++ b/src/Http/Http.Features/src/IRequestBodyPipeFeature.cs
@@ -13,6 +13,6 @@ namespace Microsoft.AspNetCore.Http.Features
///
/// A representing the request body, if any.
///
- PipeReader Reader { get; set; }
+ PipeReader Reader { get; }
}
}
diff --git a/src/Http/Http.Features/src/IResponseBodyPipeFeature.cs b/src/Http/Http.Features/src/IResponseBodyPipeFeature.cs
index 71a55d12b9..45d0e35f0a 100644
--- a/src/Http/Http.Features/src/IResponseBodyPipeFeature.cs
+++ b/src/Http/Http.Features/src/IResponseBodyPipeFeature.cs
@@ -14,6 +14,6 @@ namespace Microsoft.AspNetCore.Http.Features
///
/// A representing the response body, if any.
///
- PipeWriter Writer { get; set; }
+ PipeWriter Writer { get; }
}
}
diff --git a/src/Http/Http/perf/NoopStream.cs b/src/Http/Http/perf/NoopStream.cs
deleted file mode 100644
index 9dcfe8408f..0000000000
--- a/src/Http/Http/perf/NoopStream.cs
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace Microsoft.AspNetCore.Http
-{
- public class NoopStream : Stream
- {
- public override bool CanRead => true;
-
- public override bool CanSeek => throw new NotImplementedException();
-
- public override bool CanWrite => true;
-
- public override long Length => throw new NotImplementedException();
-
- public override long Position { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
-
- public override void Flush()
- {
- }
-
- public override int Read(byte[] buffer, int offset, int count)
- {
- return 0;
- }
-
- public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- return Task.FromResult(0);
- }
-
- public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default)
- {
- return new ValueTask(0);
- }
-
- public override long Seek(long offset, SeekOrigin origin)
- {
- throw new NotImplementedException();
- }
-
- public override void SetLength(long value)
- {
- }
-
- public override void Write(byte[] buffer, int offset, int count)
- {
- }
-
- public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- return Task.CompletedTask;
- }
-
- public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default(CancellationToken))
- {
- return default(ValueTask);
- }
-
- public override Task FlushAsync(CancellationToken cancellationToken)
- {
- return Task.CompletedTask;
- }
- }
-}
diff --git a/src/Http/Http/perf/StreamPipeReaderBenchmark.cs b/src/Http/Http/perf/StreamPipeReaderBenchmark.cs
deleted file mode 100644
index 2b5ef7c24b..0000000000
--- a/src/Http/Http/perf/StreamPipeReaderBenchmark.cs
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.IO.Pipelines;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using BenchmarkDotNet.Attributes;
-
-namespace Microsoft.AspNetCore.Http
-{
- public class StreamPipeReaderBenchmark
- {
- private StreamPipeReader _pipeReaderNoop;
- private StreamPipeReader _pipeReaderHelloWorld;
- private StreamPipeReader _pipeReaderHelloWorldAync;
-
- [IterationSetup]
- public void Setup()
- {
- _pipeReaderNoop = new StreamPipeReader(new NoopStream());
- _pipeReaderHelloWorld = new StreamPipeReader(new HelloWorldStream());
- _pipeReaderHelloWorldAync = new StreamPipeReader(new HelloWorldAsyncStream());
- }
-
- [Benchmark]
- public async Task ReadNoop()
- {
- await _pipeReaderNoop.ReadAsync();
- }
-
- [Benchmark]
- public async Task ReadHelloWorld()
- {
- var result = await _pipeReaderHelloWorld.ReadAsync();
- _pipeReaderHelloWorld.AdvanceTo(result.Buffer.End);
- }
-
- [Benchmark]
- public async Task ReadHelloWorldAsync()
- {
- var result = await _pipeReaderHelloWorldAync.ReadAsync();
- _pipeReaderHelloWorldAync.AdvanceTo(result.Buffer.End);
- }
-
- private class HelloWorldStream : NoopStream
- {
- private static byte[] bytes = Encoding.ASCII.GetBytes("Hello World");
- public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- bytes.CopyTo(buffer, 0);
- return Task.FromResult(11);
- }
-
- public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default)
- {
- bytes.CopyTo(buffer);
-
- return new ValueTask(11);
- }
- }
-
- private class HelloWorldAsyncStream : NoopStream
- {
- private static byte[] bytes = Encoding.ASCII.GetBytes("Hello World");
- public override async Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- await Task.Yield();
- bytes.CopyTo(buffer, 0);
- return 11;
- }
-
- public override async ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default)
- {
- await Task.Yield();
- bytes.CopyTo(buffer);
- return 11;
- }
- }
- }
-}
diff --git a/src/Http/Http/perf/StreamPipeWriterBenchmark.cs b/src/Http/Http/perf/StreamPipeWriterBenchmark.cs
deleted file mode 100644
index dd7836120d..0000000000
--- a/src/Http/Http/perf/StreamPipeWriterBenchmark.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System.IO;
-using System.IO.Pipelines;
-using System.Text;
-using System.Threading.Tasks;
-using BenchmarkDotNet.Attributes;
-
-namespace Microsoft.AspNetCore.Http
-{
- public class StreamPipeWriterBenchmark
- {
- private Stream _memoryStream;
- private StreamPipeWriter _pipeWriter;
- private static byte[] _helloWorldBytes = Encoding.ASCII.GetBytes("Hello World");
- private static byte[] _largeWrite = Encoding.ASCII.GetBytes(new string('a', 50000));
-
- [IterationSetup]
- public void Setup()
- {
- _memoryStream = new NoopStream();
- _pipeWriter = new StreamPipeWriter(_memoryStream);
- }
-
- [Benchmark]
- public async Task WriteHelloWorld()
- {
- await _pipeWriter.WriteAsync(_helloWorldBytes);
- }
-
- [Benchmark]
- public async Task WriteHelloWorldLargeWrite()
- {
- await _pipeWriter.WriteAsync(_largeWrite);
- }
- }
-}
diff --git a/src/Http/Http/ref/Microsoft.AspNetCore.Http.netcoreapp3.0.cs b/src/Http/Http/ref/Microsoft.AspNetCore.Http.netcoreapp3.0.cs
index 16ad1810c3..2c299f83d9 100644
--- a/src/Http/Http/ref/Microsoft.AspNetCore.Http.netcoreapp3.0.cs
+++ b/src/Http/Http/ref/Microsoft.AspNetCore.Http.netcoreapp3.0.cs
@@ -236,7 +236,7 @@ namespace Microsoft.AspNetCore.Http.Features
public partial class RequestBodyPipeFeature : Microsoft.AspNetCore.Http.Features.IRequestBodyPipeFeature
{
public RequestBodyPipeFeature(Microsoft.AspNetCore.Http.HttpContext context) { }
- public System.IO.Pipelines.PipeReader Reader { get { throw null; } set { } }
+ public System.IO.Pipelines.PipeReader Reader { get { throw null; } }
}
public partial class RequestCookiesFeature : Microsoft.AspNetCore.Http.Features.IRequestCookiesFeature
{
@@ -254,7 +254,7 @@ namespace Microsoft.AspNetCore.Http.Features
public partial class ResponseBodyPipeFeature : Microsoft.AspNetCore.Http.Features.IResponseBodyPipeFeature
{
public ResponseBodyPipeFeature(Microsoft.AspNetCore.Http.HttpContext context) { }
- public System.IO.Pipelines.PipeWriter Writer { get { throw null; } set { } }
+ public System.IO.Pipelines.PipeWriter Writer { get { throw null; } }
}
public partial class ResponseCookiesFeature : Microsoft.AspNetCore.Http.Features.IResponseCookiesFeature
{
@@ -326,7 +326,7 @@ namespace Microsoft.AspNetCore.Http.Internal
{
public DefaultHttpRequest(Microsoft.AspNetCore.Http.DefaultHttpContext context) { }
public override System.IO.Stream Body { get { throw null; } set { } }
- public override System.IO.Pipelines.PipeReader BodyReader { get { throw null; } set { } }
+ public override System.IO.Pipelines.PipeReader BodyReader { get { throw null; } }
public override long? ContentLength { get { throw null; } set { } }
public override string ContentType { get { throw null; } set { } }
public override Microsoft.AspNetCore.Http.IRequestCookieCollection Cookies { get { throw null; } set { } }
@@ -353,7 +353,7 @@ namespace Microsoft.AspNetCore.Http.Internal
{
public DefaultHttpResponse(Microsoft.AspNetCore.Http.DefaultHttpContext context) { }
public override System.IO.Stream Body { get { throw null; } set { } }
- public override System.IO.Pipelines.PipeWriter BodyWriter { get { throw null; } set { } }
+ public override System.IO.Pipelines.PipeWriter BodyWriter { get { throw null; } }
public override long? ContentLength { get { throw null; } set { } }
public override string ContentType { get { throw null; } set { } }
public override Microsoft.AspNetCore.Http.IResponseCookies Cookies { get { throw null; } }
@@ -492,93 +492,3 @@ namespace Microsoft.Extensions.DependencyInjection
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddHttpContextAccessor(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) { throw null; }
}
}
-namespace System.IO.Pipelines
-{
- public partial class ReadOnlyPipeStream : System.IO.Stream
- {
- public ReadOnlyPipeStream(System.IO.Pipelines.PipeReader pipeReader) { }
- public ReadOnlyPipeStream(System.IO.Pipelines.PipeReader pipeReader, bool allowSynchronousIO) { }
- public override bool CanRead { get { throw null; } }
- public override bool CanSeek { get { throw null; } }
- public override bool CanWrite { get { throw null; } }
- public System.IO.Pipelines.PipeReader InnerPipeReader { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
- public override long Length { get { throw null; } }
- public override long Position { get { throw null; } set { } }
- public override int WriteTimeout { get { throw null; } set { } }
- public override System.IAsyncResult BeginRead(byte[] buffer, int offset, int count, System.AsyncCallback callback, object state) { throw null; }
- public override System.Threading.Tasks.Task CopyToAsync(System.IO.Stream destination, int bufferSize, System.Threading.CancellationToken cancellationToken) { throw null; }
- public override int EndRead(System.IAsyncResult asyncResult) { throw null; }
- public override void Flush() { }
- public override System.Threading.Tasks.Task FlushAsync(System.Threading.CancellationToken cancellationToken) { throw null; }
- public override int Read(byte[] buffer, int offset, int count) { throw null; }
- public override System.Threading.Tasks.Task ReadAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; }
- public override System.Threading.Tasks.ValueTask ReadAsync(System.Memory destination, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
- public override long Seek(long offset, System.IO.SeekOrigin origin) { throw null; }
- public override void SetLength(long value) { }
- public override void Write(byte[] buffer, int offset, int count) { }
- public override System.Threading.Tasks.Task WriteAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; }
- }
- public partial class StreamPipeReader : System.IO.Pipelines.PipeReader, System.IDisposable
- {
- public StreamPipeReader(System.IO.Stream readingStream) { }
- public StreamPipeReader(System.IO.Stream readingStream, System.IO.Pipelines.StreamPipeReaderAdapterOptions options) { }
- public System.IO.Stream InnerStream { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
- public override void AdvanceTo(System.SequencePosition consumed) { }
- public override void AdvanceTo(System.SequencePosition consumed, System.SequencePosition examined) { }
- public override void CancelPendingRead() { }
- public override void Complete(System.Exception exception = null) { }
- public void Dispose() { }
- public override void OnWriterCompleted(System.Action callback, object state) { }
- [System.Diagnostics.DebuggerStepThroughAttribute]
- public override System.Threading.Tasks.ValueTask ReadAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
- public override bool TryRead(out System.IO.Pipelines.ReadResult result) { throw null; }
- }
- public partial class StreamPipeReaderAdapterOptions
- {
- public const int DefaultMinimumReadThreshold = 256;
- public const int DefaultMinimumSegmentSize = 4096;
- public static System.IO.Pipelines.StreamPipeReaderAdapterOptions DefaultOptions;
- public StreamPipeReaderAdapterOptions() { }
- public StreamPipeReaderAdapterOptions(int minimumSegmentSize, int minimumReadThreshold, System.Buffers.MemoryPool memoryPool) { }
- public System.Buffers.MemoryPool MemoryPool { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- public int MinimumReadThreshold { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- public int MinimumSegmentSize { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- }
- public partial class StreamPipeWriter : System.IO.Pipelines.PipeWriter, System.IDisposable
- {
- public StreamPipeWriter(System.IO.Stream writingStream) { }
- public StreamPipeWriter(System.IO.Stream writingStream, int minimumSegmentSize, System.Buffers.MemoryPool pool = null) { }
- public System.IO.Stream InnerStream { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
- public override void Advance(int count) { }
- public override void CancelPendingFlush() { }
- public override void Complete(System.Exception exception = null) { }
- public void Dispose() { }
- public override System.Threading.Tasks.ValueTask FlushAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
- public override System.Memory GetMemory(int sizeHint = 0) { throw null; }
- public override System.Span GetSpan(int sizeHint = 0) { throw null; }
- public override void OnReaderCompleted(System.Action callback, object state) { }
- }
- public partial class WriteOnlyPipeStream : System.IO.Stream
- {
- public WriteOnlyPipeStream(System.IO.Pipelines.PipeWriter pipeWriter) { }
- public WriteOnlyPipeStream(System.IO.Pipelines.PipeWriter pipeWriter, bool allowSynchronousIO) { }
- public override bool CanRead { get { throw null; } }
- public override bool CanSeek { get { throw null; } }
- public override bool CanWrite { get { throw null; } }
- public System.IO.Pipelines.PipeWriter InnerPipeWriter { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
- public override long Length { get { throw null; } }
- public override long Position { get { throw null; } set { } }
- public override int ReadTimeout { get { throw null; } set { } }
- public override System.IAsyncResult BeginWrite(byte[] buffer, int offset, int count, System.AsyncCallback callback, object state) { throw null; }
- public override void EndWrite(System.IAsyncResult asyncResult) { }
- public override void Flush() { }
- public override System.Threading.Tasks.Task FlushAsync(System.Threading.CancellationToken cancellationToken) { throw null; }
- public override int Read(byte[] buffer, int offset, int count) { throw null; }
- public override System.Threading.Tasks.Task ReadAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; }
- public override long Seek(long offset, System.IO.SeekOrigin origin) { throw null; }
- public override void SetLength(long value) { }
- public override void Write(byte[] buffer, int offset, int count) { }
- public override System.Threading.Tasks.Task WriteAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; }
- public override System.Threading.Tasks.ValueTask WriteAsync(System.ReadOnlyMemory source, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
- }
-}
diff --git a/src/Http/Http/src/Features/RequestBodyPipeFeature.cs b/src/Http/Http/src/Features/RequestBodyPipeFeature.cs
index ee86031fde..61154c5f0a 100644
--- a/src/Http/Http/src/Features/RequestBodyPipeFeature.cs
+++ b/src/Http/Http/src/Features/RequestBodyPipeFeature.cs
@@ -2,14 +2,16 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
+using System.IO;
using System.IO.Pipelines;
+using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Http.Features
{
public class RequestBodyPipeFeature : IRequestBodyPipeFeature
{
- private StreamPipeReader _internalPipeReader;
- private PipeReader _userSetPipeReader;
+ private PipeReader _internalPipeReader;
+ private Stream _streamInstanceWhenWrapped;
private HttpContext _context;
public RequestBodyPipeFeature(HttpContext context)
@@ -25,25 +27,21 @@ namespace Microsoft.AspNetCore.Http.Features
{
get
{
- if (_userSetPipeReader != null)
- {
- return _userSetPipeReader;
- }
-
if (_internalPipeReader == null ||
- !object.ReferenceEquals(_internalPipeReader.InnerStream, _context.Request.Body))
+ !ReferenceEquals(_streamInstanceWhenWrapped, _context.Request.Body))
{
- _internalPipeReader = new StreamPipeReader(_context.Request.Body);
- _context.Response.RegisterForDispose(_internalPipeReader);
+ _streamInstanceWhenWrapped = _context.Request.Body;
+ _internalPipeReader = PipeReader.Create(_context.Request.Body);
+
+ _context.Response.OnCompleted((self) =>
+ {
+ ((PipeReader)self).Complete();
+ return Task.CompletedTask;
+ }, _internalPipeReader);
}
return _internalPipeReader;
}
- set
- {
- _userSetPipeReader = value ?? throw new ArgumentNullException(nameof(value));
- // TODO set the request body Stream to an adapted pipe https://github.com/aspnet/AspNetCore/issues/3971
- }
}
}
}
diff --git a/src/Http/Http/src/Features/ResponseBodyPipeFeature.cs b/src/Http/Http/src/Features/ResponseBodyPipeFeature.cs
index 0699679365..2de8c86b9c 100644
--- a/src/Http/Http/src/Features/ResponseBodyPipeFeature.cs
+++ b/src/Http/Http/src/Features/ResponseBodyPipeFeature.cs
@@ -2,14 +2,16 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
+using System.IO;
using System.IO.Pipelines;
+using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Http.Features
{
public class ResponseBodyPipeFeature : IResponseBodyPipeFeature
{
- private StreamPipeWriter _internalPipeWriter;
- private PipeWriter _userSetPipeWriter;
+ private PipeWriter _internalPipeWriter;
+ private Stream _streamInstanceWhenWrapped;
private HttpContext _context;
public ResponseBodyPipeFeature(HttpContext context)
@@ -25,25 +27,21 @@ namespace Microsoft.AspNetCore.Http.Features
{
get
{
- if (_userSetPipeWriter != null)
- {
- return _userSetPipeWriter;
- }
-
if (_internalPipeWriter == null ||
- !object.ReferenceEquals(_internalPipeWriter.InnerStream, _context.Response.Body))
+ !ReferenceEquals(_streamInstanceWhenWrapped, _context.Response.Body))
{
- _internalPipeWriter = new StreamPipeWriter(_context.Response.Body);
- _context.Response.RegisterForDispose(_internalPipeWriter);
+ _streamInstanceWhenWrapped = _context.Response.Body;
+ _internalPipeWriter = PipeWriter.Create(_context.Response.Body);
+
+ _context.Response.OnCompleted((self) =>
+ {
+ ((PipeWriter)self).Complete();
+ return Task.CompletedTask;
+ }, _internalPipeWriter);
}
return _internalPipeWriter;
}
- set
- {
- _userSetPipeWriter = value ?? throw new ArgumentNullException(nameof(value));
- // TODO set the response body Stream to an adapted pipe https://github.com/aspnet/AspNetCore/issues/3971
- }
}
}
}
diff --git a/src/Http/Http/src/Internal/DefaultHttpRequest.cs b/src/Http/Http/src/Internal/DefaultHttpRequest.cs
index 964a478510..bc0a4c42dc 100644
--- a/src/Http/Http/src/Internal/DefaultHttpRequest.cs
+++ b/src/Http/Http/src/Internal/DefaultHttpRequest.cs
@@ -174,7 +174,6 @@ namespace Microsoft.AspNetCore.Http.Internal
public override PipeReader BodyReader
{
get { return RequestBodyPipeFeature.Reader; }
- set { RequestBodyPipeFeature.Reader = value; }
}
struct FeatureInterfaces
diff --git a/src/Http/Http/src/Internal/DefaultHttpResponse.cs b/src/Http/Http/src/Internal/DefaultHttpResponse.cs
index 068c4ec9bd..19e75c3aa0 100644
--- a/src/Http/Http/src/Internal/DefaultHttpResponse.cs
+++ b/src/Http/Http/src/Internal/DefaultHttpResponse.cs
@@ -112,7 +112,6 @@ namespace Microsoft.AspNetCore.Http.Internal
public override PipeWriter BodyWriter
{
get { return ResponseBodyPipeFeature.Writer; }
- set { ResponseBodyPipeFeature.Writer = value; }
}
public override void OnStarting(Func