public void SetStream(HttpContentReadStream stream) { Debug.Assert(stream != null); Debug.Assert(stream.CanRead); _stream = stream; }
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); } }
private HttpContentReadStream ConsumeStream() { if (_stream == null) { throw new InvalidOperationException("content already consumed"); } HttpContentReadStream stream = _stream; _stream = null; return(stream); }
protected override void Dispose(bool disposing) { if (disposing) { if (_stream != null) { _stream.Dispose(); _stream = null; } } base.Dispose(disposing); }
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(); }