#2315·mopidy

Serve WebSockets from ASGI apps

Author: jodalCreated Sep 27, 2026Updated Sep 27, 2026
LabelsA-ext-httpready-for-agent

:robot: Summary

An ASGI app registered with http:asgi can serve WebSockets at /<name>/.... A WebSocket bridge that Mopidy owns turns Tornado's WebSocket handler into the ASGI WebSocket protocol.

The bridge rules from the prototype are in the parent spec, under "WebSocket bridge". The most important rules: run the app until its first message before the handshake, and hold every later send() until Tornado calls open().

Parent

mopidy/mopidy#2312

Acceptance criteria

  • WebSocket upgrade requests under /<name>/ reach the app as websocket scopes. Other requests still reach the HTTP bridge.
  • Tornado does not check the origin. The app decides.
  • websocket.accept sets the subprotocol and extra headers of the handshake response.
  • websocket.close before accept gives the client HTTP 403.
  • A close right after accept reaches the client.
  • Text and binary messages go both ways.
  • Close codes and reasons go both ways. The app gets 1005 when the client sent no code.
  • If the app returns without closing, the connection closes with code 1000.
  • send() waits for a slow client (backpressure).
  • Tests use real WebSocket clients through the test seam.

Blocked by

  • mopidy/mopidy#2314