Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
30da832
downgrade proposal for HttpClient
May 24, 2022
7b03bc8
HttpClient to handle ws over h2
Jun 7, 2022
e7b8332
ClientWebSocket to handle ws over h2
Jun 7, 2022
a5e991a
Add property for protocol header and remove it from known headers
Jun 17, 2022
264c802
Update src/libraries/System.Net.Http/src/System/Net/Http/HttpRequestM…
Jun 18, 2022
08d1f8c
Address review feedback
Jun 18, 2022
71cc887
Rename HttpVersion and HttpVersionPolicy
Jun 20, 2022
8019a3c
Apply suggestions from code review
Jun 21, 2022
8ef8b4c
address review feedback
Jun 21, 2022
ac966a8
Merge branch 'main' into ws-h2-draft
Jun 23, 2022
f6de72a
address review feedback
Jun 24, 2022
9221483
address review feedback
Jun 28, 2022
fafc84b
Apply suggestions from code review
Jun 28, 2022
0d8f8f7
fix race condition on setting enable connect
Jun 29, 2022
9be5b95
inherit h2 read and writes streams
Jun 29, 2022
502b051
Apply suggestions from code review
Jun 30, 2022
e635439
fix H2PACK encoding issue
Jun 30, 2022
ad66857
add timeout for waiting settings task
Jun 30, 2022
c58d993
generalized settings received task
Jun 30, 2022
76c9e20
Update src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpH…
Jul 1, 2022
2467449
Fixing HttpStream tests
Jul 1, 2022
d9248a6
Apply suggestions from code review
Jul 4, 2022
baf52d4
address review feedback
Jul 4, 2022
afaf5be
Apply suggestions from code review
Jul 8, 2022
918c6a8
Address review feedback
Jul 8, 2022
9734075
Adapt test to ValueTask.FromException
Jul 8, 2022
efdcdba
Apply suggestions from code review
Jul 10, 2022
6f7b101
Adding connect tests
Jul 10, 2022
595642c
Apply suggestions from code review
Jul 10, 2022
e05db11
feedback + skip tests on browser
Jul 10, 2022
54d0b08
Merge branch 'main' into ws-h2-draft
Jul 10, 2022
b7f543b
Feedback + test for websocket stream
Jul 12, 2022
73968ec
Update src/libraries/System.Net.Http/src/Resources/Strings.resx
Jul 12, 2022
4dbe1c2
Address review feedback
Jul 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
inherit h2 read and writes streams
  • Loading branch information
Katya Sokolova committed Jun 29, 2022
commit 9be5b959d08131430fec2919c34a7c88b9144200
Original file line number Diff line number Diff line change
Expand Up @@ -1432,134 +1432,40 @@ private enum StreamCompletionState : byte
Failed
}

private sealed class Http2ReadStream : HttpBaseStream
private sealed class Http2ReadStream : Http2ReadWriteStream
{
private Http2Stream? _http2Stream;
private readonly HttpResponseMessage _responseMessage;

public Http2ReadStream(Http2Stream http2Stream)
{
Debug.Assert(http2Stream != null);
Debug.Assert(http2Stream._response != null);
_http2Stream = http2Stream;
_responseMessage = _http2Stream._response;
}

~Http2ReadStream()
{
if (NetEventSource.Log.IsEnabled()) _http2Stream?.Trace("");
try
{
Dispose(disposing: false);
}
catch (Exception e)
{
if (NetEventSource.Log.IsEnabled()) _http2Stream?.Trace($"Error: {e}");
}
}

protected override void Dispose(bool disposing)
{
Http2Stream? http2Stream = Interlocked.Exchange(ref _http2Stream, null);
if (http2Stream == null)
{
return;
}

// Technically we shouldn't be doing the following work when disposing == false,
// as the following work relies on other finalizable objects. But given the HTTP/2
// protocol, we have little choice: if someone drops the Http2ReadStream without
// disposing of it, we need to a) signal to the server that the stream is being
// canceled, and b) clean up the associated state in the Http2Connection.

http2Stream.CloseResponseBody();

base.Dispose(disposing);
}
public Http2ReadStream(Http2Stream http2Stream) : base(http2Stream) { }

public override bool CanRead => _http2Stream != null;
public override bool CanWrite => false;

public override int Read(Span<byte> destination)
{
Http2Stream http2Stream = _http2Stream ?? throw new ObjectDisposedException(nameof(Http2ReadStream));

return http2Stream.ReadData(destination, _responseMessage);
}

public override ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken)
{
Http2Stream? http2Stream = _http2Stream;

if (http2Stream == null)
{
return ValueTask.FromException<int>(ExceptionDispatchInfo.SetCurrentStackTrace(new ObjectDisposedException(nameof(Http2ReadStream))));
}

if (cancellationToken.IsCancellationRequested)
{
return ValueTask.FromCanceled<int>(cancellationToken);
}

return http2Stream.ReadDataAsync(destination, _responseMessage, cancellationToken);
}

public override void CopyTo(Stream destination, int bufferSize)
{
ValidateCopyToArguments(destination, bufferSize);
Http2Stream http2Stream = _http2Stream ?? throw ExceptionDispatchInfo.SetCurrentStackTrace(new ObjectDisposedException(nameof(Http2ReadStream)));
http2Stream.CopyTo(_responseMessage, destination, bufferSize);
}

public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
{
ValidateCopyToArguments(destination, bufferSize);
Http2Stream? http2Stream = _http2Stream;
return
http2Stream is null ? Task.FromException<int>(ExceptionDispatchInfo.SetCurrentStackTrace(new ObjectDisposedException(nameof(Http2ReadStream)))) :
cancellationToken.IsCancellationRequested ? Task.FromCanceled<int>(cancellationToken) :
http2Stream.CopyToAsync(_responseMessage, destination, bufferSize, cancellationToken);
}

public override void Write(ReadOnlySpan<byte> buffer) => throw new NotSupportedException(SR.net_http_content_readonly_stream);

public override ValueTask WriteAsync(ReadOnlyMemory<byte> destination, CancellationToken cancellationToken) => throw new NotSupportedException();
}

private sealed class Http2WriteStream : HttpBaseStream
private sealed class Http2WriteStream : Http2ReadWriteStream
{
private Http2Stream? _http2Stream;

public long BytesWritten { get; private set; }

public long ContentLength { get; private set; }

public Http2WriteStream(Http2Stream http2Stream, long contentLength)
public Http2WriteStream(Http2Stream http2Stream, long contentLength) : base(http2Stream)
{
Debug.Assert(http2Stream != null);
Debug.Assert(contentLength >= -1);
_http2Stream = http2Stream;
ContentLength = contentLength;
}

protected override void Dispose(bool disposing)
{
Http2Stream? http2Stream = Interlocked.Exchange(ref _http2Stream, null);
if (http2Stream == null)
{
return;
}

base.Dispose(disposing);
}

public override bool CanRead => false;
public override bool CanWrite => _http2Stream != null;

public override int Read(Span<byte> buffer) => throw new NotSupportedException();

public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken) => throw new NotSupportedException();

public override void CopyTo(Stream destination, int bufferSize) => throw new NotSupportedException();

public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) => throw new NotSupportedException();

public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
{
BytesWritten += buffer.Length;
Expand All @@ -1569,38 +1475,11 @@ public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationTo
return ValueTask.FromException(new HttpRequestException(SR.net_http_content_write_larger_than_content_length));
}

Http2Stream? http2Stream = _http2Stream;

if (http2Stream == null)
{
return ValueTask.FromException(new ObjectDisposedException(nameof(Http2WriteStream)));
}

return http2Stream.SendDataAsync(buffer, cancellationToken);
}

public override Task FlushAsync(CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled(cancellationToken);
}

Http2Stream? http2Stream = _http2Stream;

if (http2Stream == null)
{
return Task.CompletedTask;
}

// In order to flush this stream's previous writes, we need to flush the connection. We
// really only need to do any work here if the connection's buffer has any pending writes
// from this stream, but we currently lack a good/efficient/safe way of doing that.
return http2Stream._connection.FlushAsync(cancellationToken);
return base.WriteAsync(buffer, cancellationToken);
}
}

public sealed class Http2ReadWriteStream : HttpBaseStream
public class Http2ReadWriteStream : HttpBaseStream
{
private Http2Stream? _http2Stream;
// should be removed
Expand Down