Skip to content
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

Implement HTTP/2 WebSockets #70895

Merged
merged 34 commits into from
Jul 12, 2022
Merged

Conversation

greenEkatherine
Copy link
Contributor

Resolves #69669

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Jun 17, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Resolves #69669

Author: greenEkatherine
Assignees: -
Labels:

area-System.Net.Http, new-api-needs-documentation

Milestone: -

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only quickly skimmed it and left a few comments... I'll review in more depth once it's out of draft and TODOs are addressed.

@ghost ghost added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jun 20, 2022
Co-authored-by: Chris Ross <Tratcher@Outlook.com>
@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Jun 21, 2022
@greenEkatherine greenEkatherine added this to the 7.0.0 milestone Jul 8, 2022
Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any tests for the new APIs or functionality. Where are they?

@greenEkatherine
Copy link
Contributor Author

I don't see any tests for the new APIs or functionality. Where are they?

Our external server doesn't support web sockets over H/2, so I can add only loopback. And interop tests with Kestrel after this will be merged

@stephentoub
Copy link
Member

so I can add only loopback

Right, that's what I was expecting.

Co-authored-by: Stephen Toub <stoub@microsoft.com>
Katya Sokolova and others added 2 commits July 10, 2022 18:11
Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com>
{
bool disposeHandler = false;
invoker ??= new HttpMessageInvoker(SetupHandler(options, out disposeHandler));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephentoub is there a reason why we never cached the whole invoker, only the handler? We'd create it and just throw away for finalization

response = await new HttpMessageInvoker(handler).SendAsync(request, externalAndAbortCancellation.Token).ConfigureAwait(false);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to my knowledge.

break;
}
catch (HttpRequestException ex) when
(ex.Data.Contains("SETTINGS_ENABLE_CONNECT_PROTOCOL") &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct me if I'm wrong, but the exception seems to contain SETTINGS_ENABLE_CONNECT_PROTOCOL only when H2 connection is established but settings did not contain enabling extended connect? What will happen if H2 connection was not established at all (if server is H1 only)?

Also, I am a bit concerned about the whole while(true) approach. The conditions on when we exit or continue looping are a bit obscured.
We only have 3 options: try only H2, try H2 and then H1, try only H1. Meaning, we only have 2 steps, and the second will only be called if the first was not allowed or not succeeded in a special way. Can we unwind the loop? Something like

res = null
fail if unexpected versions
if (can try H2)
{
    try
    {
        res = do H2 stuff
    }
    catch when can downgrade
}
if (res == null) // either H2 not requested or it failed with downgrade enabled
{
    res = do H1 stuff
}
do stuff with res

Please let me know if I miss something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if H2 connection was not established at all (if server is H1 only)?

In that case we get HttpRequestException that I cannot separate from other reasons. I'm not sure if I can add Data to the exception that is already in use?

clientSocket.Options.HttpVersionPolicy = Http.HttpVersionPolicy.RequestVersionExact;
using var handler = new SocketsHttpHandler();
handler.SslOptions.RemoteCertificateValidationCallback = delegate { return true; };
await clientSocket.ConnectAsync(uri, new HttpMessageInvoker(handler), cts.Token);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have tests that validate:

  • sending/receiving with HTTP/2 after connecting?
  • downgrading?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Send/receive test for web socket stream is added and now I'm struggling to emulate downgrading, not sure if I can make it today.

await connection.SendResponseDataAsync(streamId, Array.Empty<byte>(), endStream: true);
});

StreamingHttpContent requestContent = new StreamingHttpContent();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed anywhere, is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, I'll remove it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: WebSockets over HTTP/2
7 participants