Skip to content

Commit

Permalink
Fix sending large grpc-web-text requests
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Feb 12, 2020
1 parent 7c01479 commit 62f7672
Show file tree
Hide file tree
Showing 12 changed files with 966 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Grpc.Net.Client.Web/Internal/Base64RequestStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ public override async ValueTask WriteAsync(ReadOnlyMemory<byte> data, Cancellati

while (data.Length >= 3)
{
// Final encoded data length could exceed buffer length
// When this happens the data will be encoded and WriteAsync in a loop
var encodeLength = Math.Min(data.Length, localBuffer.Length / 4 * 3);

EnsureSuccess(
Base64.EncodeToUtf8(data.Span, localBuffer.Span, out var bytesConsumed, out var bytesWritten, isFinalBlock: false),
Base64.EncodeToUtf8(data.Span.Slice(0, encodeLength), localBuffer.Span, out var bytesConsumed, out var bytesWritten, isFinalBlock: false),
OperationStatus.NeedMoreData);

var base64Remainder = _buffer.Length - localBuffer.Length;
Expand Down
Loading

0 comments on commit 62f7672

Please sign in to comment.