-
Notifications
You must be signed in to change notification settings - Fork 893
Fix duplex request proxying (especially gRPC) #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a776727
Fix gRPC duplex request proxying
davidni 69bec9a
Builds, added unit tests
davidni 494063f
PR feedback
davidni ff0b892
Merge remote-tracking branch 'upstream/master' into davidni/grpc_stre…
davidni e99961b
Only forcefully complete response when streaming
davidni da8691b
GRpc --> Grpc
davidni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.ReverseProxy.Utilities; | ||
|
|
||
| namespace Microsoft.ReverseProxy.Core.Service.Proxy | ||
| { | ||
| /// <summary> | ||
| /// Delegates to a wrapped stream and calls its | ||
| /// <see cref="Stream.Flush"/> or <see cref="Stream.FlushAsync(CancellationToken)"/> | ||
| /// on every write. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This is used by <see cref="StreamCopyHttpContent"/> to work around some undesirable behavior | ||
| /// in the HttpClient machinery (as of .NET Core 3.1.201) where an internal buffer | ||
| /// doesn't get written to the outgoing socket stream when we write to the outgoing stream. | ||
| /// Calling Flush on that stream sends the bytes to the underlying socket, | ||
| /// but does not call flush on the socket, so perf impact is expected to be small. | ||
| /// </remarks> | ||
| internal sealed class AutoFlushingStream : Stream | ||
| { | ||
| private readonly Stream _stream; | ||
|
|
||
| public AutoFlushingStream(Stream stream) | ||
| { | ||
| Contracts.CheckValue(stream, nameof(stream)); | ||
| _stream = stream; | ||
| } | ||
|
|
||
| public override bool CanRead => _stream.CanRead; | ||
|
|
||
| public override bool CanSeek => _stream.CanSeek; | ||
|
|
||
| public override bool CanWrite => _stream.CanWrite; | ||
|
|
||
| public override long Length => _stream.Length; | ||
|
|
||
| public override long Position | ||
| { | ||
| get => _stream.Position; | ||
| set => _stream.Position = value; | ||
| } | ||
|
|
||
| public override void Write(byte[] buffer, int offset, int count) | ||
| { | ||
| _stream.Write(buffer, offset, count); | ||
| _stream.Flush(); | ||
| } | ||
|
|
||
| public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) | ||
| { | ||
| await _stream.WriteAsync(buffer, offset, count, cancellationToken); | ||
| await _stream.FlushAsync(cancellationToken); | ||
| } | ||
|
|
||
| public override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default) | ||
| { | ||
| await _stream.WriteAsync(buffer, cancellationToken); | ||
| await _stream.FlushAsync(cancellationToken); | ||
| } | ||
|
|
||
| public override void Flush() | ||
| { | ||
| _stream.Flush(); | ||
| } | ||
|
|
||
| public override Task FlushAsync(CancellationToken cancellationToken) | ||
| { | ||
| return _stream.FlushAsync(cancellationToken); | ||
| } | ||
|
|
||
| public override int Read(byte[] buffer, int offset, int count) | ||
| { | ||
| return _stream.Read(buffer, offset, count); | ||
| } | ||
|
|
||
| public override long Seek(long offset, SeekOrigin origin) | ||
| { | ||
| return _stream.Seek(offset, origin); | ||
| } | ||
|
|
||
| public override void SetLength(long value) | ||
| { | ||
| _stream.SetLength(value); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.