예제 #1
0
            public void SetStream(HttpContentReadStream stream)
            {
                Debug.Assert(stream != null);
                Debug.Assert(stream.CanRead);

                _stream = stream;
            }
예제 #2
0
            protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
            {
                Debug.Assert(stream != null);

                using (HttpContentReadStream contentStream = ConsumeStream())
                {
                    const int BufferSize = 8192;
                    await contentStream.CopyToAsync(stream, BufferSize, _cancellationToken).ConfigureAwait(false);
                }
            }
예제 #3
0
            private HttpContentReadStream ConsumeStream()
            {
                if (_stream == null)
                {
                    throw new InvalidOperationException("content already consumed");
                }

                HttpContentReadStream stream = _stream;

                _stream = null;
                return(stream);
            }
예제 #4
0
            protected override void Dispose(bool disposing)
            {
                if (disposing)
                {
                    if (_stream != null)
                    {
                        _stream.Dispose();
                        _stream = null;
                    }
                }

                base.Dispose(disposing);
            }
예제 #5
0
        private static async Task ExecuteRequestAsync(BufferedStream bufferedStream, HttpParser parser)
        {
            // Send request
            await bufferedStream.WriteAsync(s_requestMessage, 0, s_requestMessage.Length, CancellationToken.None);

            await bufferedStream.FlushAsync(CancellationToken.None);

            // Parse response message
            HttpContentReadStream body = await parser.ParseResponseAndGetBodyAsync(bufferedStream, null, CancellationToken.None);

            await body.DrainAsync(CancellationToken.None);

            body.Dispose();
        }