private async Task SerializeTextToStreamAsync(Stream stream) { using var base64RequestStream = new Base64RequestStream(stream); await _inner.CopyToAsync(base64RequestStream).ConfigureAwait(false); // Any remaining content needs to be written when SerializeToStreamAsync finishes. // We want to avoid unnecessary flush calls so a custom method is used to write // ramining content rather than calling FlushAsync. await base64RequestStream.WriteRemainderAsync(CancellationToken.None).ConfigureAwait(false); }
protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context) { Base64RequestStream?base64RequestStream = null; try { if (_mode == GrpcWebMode.GrpcWebText) { base64RequestStream = new Base64RequestStream(stream); stream = base64RequestStream; } await _inner.CopyToAsync(stream).ConfigureAwait(false); } finally { base64RequestStream?.Dispose(); } }