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

WebSockets over HTTP/2 #1978

Merged
merged 20 commits into from
Jan 4, 2023
Merged

WebSockets over HTTP/2 #1978

merged 20 commits into from
Jan 4, 2023

Conversation

Tratcher
Copy link
Member

@Tratcher Tratcher commented Dec 22, 2022

Fixes #1375

Before this change the forwarder assumed that WebSockets always had to be forwarded using HTTP/1.1. Now it will honor the version and policy settings to decide which outgoing protocol to use. Request and response headers are adapted as needed. If HTTP/2 doesn't work then it can re-try with HTTP/1.1.

Notes:

  • SocketsHttpHandler auto-flushes writes for HTTP/1.1 WebSockets, but not for HTTP/2. We have to manually flush writes.
  • Something is hanging when YARP tries HTTP/2 prior knowledge to a non-TLS HTTP/1.1 endpoint. Hang when HTTP/2 WebSocket connects to a HTTP/1.1 non-TLS kestrel endpoint dotnet/runtime#80056
  • HttpSys is used as a negative test server because it doesn't support H2WS. This requires TLS, so we use the ports registered for IIS Express's certificate.
  • Added a lot of logging infrastructure
  • Updated Docs

@Tratcher Tratcher added this to the YARP 2.0.0 milestone Dec 22, 2022
@Tratcher Tratcher self-assigned this Dec 22, 2022
Copy link
Member

@MihaZupan MihaZupan left a comment

Choose a reason for hiding this comment

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

Nice! I take it the telemetry for H2 WebSockets also "just work ™️" because ASP.NET exposes them the same way as H1?

test/ReverseProxy.FunctionalTests/WebSocketTests.cs Outdated Show resolved Hide resolved
test/ReverseProxy.Tests/Common/XunitLoggerProvider.cs Outdated Show resolved Hide resolved
src/ReverseProxy/Forwarder/StreamCopyHttpContent.cs Outdated Show resolved Hide resolved
src/ReverseProxy/Forwarder/HttpForwarder.cs Outdated Show resolved Hide resolved
src/ReverseProxy/Forwarder/HttpForwarder.cs Outdated Show resolved Hide resolved
src/ReverseProxy/Forwarder/HttpForwarder.cs Outdated Show resolved Hide resolved
src/ReverseProxy/Forwarder/HttpForwarder.cs Show resolved Hide resolved
src/ReverseProxy/Forwarder/HttpForwarder.cs Outdated Show resolved Hide resolved
src/ReverseProxy/Forwarder/ProtocolHelper.cs Show resolved Hide resolved
@Tratcher
Copy link
Member Author

Nice! I take it the telemetry for H2 WebSockets also "just work ™️" because ASP.NET exposes them the same way as H1?

Nope, had to add it there too 😁

@Tratcher Tratcher marked this pull request as ready for review December 28, 2022 01:01
test/ReverseProxy.FunctionalTests/WebSocketTests.cs Outdated Show resolved Hide resolved
src/ReverseProxy/Utilities/EventIds.cs Outdated Show resolved Hide resolved
src/ReverseProxy/Forwarder/HttpForwarder.cs Outdated Show resolved Hide resolved
@Tratcher Tratcher enabled auto-merge (squash) January 4, 2023 19:10
@Tratcher Tratcher merged commit f2ac5db into main Jan 4, 2023
@Tratcher Tratcher deleted the tratcher/h2ws branch January 4, 2023 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebSockets over HTTP/2
3 participants