public async Task AbortCausesReadToCancel()
        {
            var pipeReader = new HttpRequestPipeReader();

            pipeReader.StartAcceptingReads(null);
            pipeReader.Abort();
            await Assert.ThrowsAsync <TaskCanceledException>(() => pipeReader.ReadAsync().AsTask());
        }
        public async Task StopAcceptingReadsCausesReadToThrowObjectDisposedException()
        {
            var pipeReader = new HttpRequestPipeReader();

            pipeReader.StartAcceptingReads(null);
            pipeReader.StopAcceptingReads();

            // Validation for ReadAsync occurs in an async method in ReadOnlyPipeStream.
            await Assert.ThrowsAsync <ObjectDisposedException>(async() => { await pipeReader.ReadAsync(); });
        }
        public async Task AbortWithErrorCausesReadToCancel()
        {
            var pipeReader = new HttpRequestPipeReader();

            pipeReader.StartAcceptingReads(null);
            var error = new Exception();

            pipeReader.Abort(error);
            var exception = await Assert.ThrowsAsync <Exception>(() => pipeReader.ReadAsync().AsTask());

            Assert.Same(error, exception);
        }
Example #4
0
        public (Stream request, Stream response, PipeReader reader, PipeWriter writer) Start(MessageBody body)
        {
            _requestReader.StartAcceptingReads(body);
            _emptyRequestReader.StartAcceptingReads(MessageBody.ZeroContentLengthClose);
            _responseWriter.StartAcceptingWrites();

            if (body.RequestUpgrade)
            {
                // until Upgrade() is called, context.Response.Body should use the normal output stream
                _upgradeableResponse.SetInnerStream(_response);
                // upgradeable requests should never have a request body
                return(_emptyRequest, _upgradeableResponse, _emptyRequestReader, _responseWriter);
            }
            else
            {
                return(_request, _response, _requestReader, _responseWriter);
            }
        }