Proxing WebSockets and SPDY
SPDY is the precursor to HTTP/2 and is commonly used in Kubernetes environments.
WebSockets and SPDY are built on top of HTTP/1.1 using a feature called connection upgrades. YARP proxies the initial request, and if the destination server responds with
101 Switching Protocols, upgrades the connection to an opaque, bidirectional stream using the new protocol. YARP does not support upgrading to other protocols like HTTP/2 this way.
YARP supports WebSockets over HTTP/2 starting in .NET 7 and YARP 2.0. Kestrel is the only available AspNetCore server that will accept incoming HTTP/2 WebSocket requests and that support is automatically enabled. Browsers can detect this support advertised by the server and automatically switch to HTTP/2.
The incoming and outgoing protocol versions do not need to match. The incoming WebSocket request can be HTTP/1.1 or 2. There is no configuration specific to WebSockets for outgoing requests, YARP will use the ForwarderRequestConfig's Version and VersionPolicy to determine the outbound version to use. These default to HTTP/2 and RequestVersionOrLower.
WebSockets require different HTTP headers for HTTP/2 so YARP will add and remove these headers as needed when adapting between the different versions.
After the initial handshake WebSockets function the same way over both HTTP versions.