tokio-rs / axum

Ergonomic and modular web framework built with Tokio, Tower, and Hyper
18.35k stars 1.03k forks source link

Add support for WebSockets over HTTP/2 #2894

Open SabrinaJewson opened 2 weeks ago

SabrinaJewson commented 2 weeks ago

Motivation

WebSockets over HTTP/2 are currently not supported. It is defined in RFC 8441 (websockets over HTTP/3 are defined in RFC 9220 and it is exactly the same as HTTP/2).

Solution

Implement the changes necessary to support them, which just requires looking at the :protocol pseudo-header in the websocket extractor and advertising our support by enabling SETTINGS_ENABLE_CONNECT_PROTOCOL in HTTP/2.

Additionally, I needed to fix the handling of responses to CONNECT requests: Axum was incorrectly adding the Content-Length header to them (see also https://github.com/hyperium/hyper/pull/3748), which was causing things to break.