Skip to content

WebSocket server + HTTP upgrade handoff #130

@resetius

Description

@resetius

WebSocket server + HTTP upgrade handoff (lib split, no std::function)

Goal

Add server-side WebSocket support and integrate it with THttpServer via a clean connection takeover mechanism, while keeping ws optional and avoiding std::function (single virtual dispatch only).

High-level design

  • Keep ws as a standalone library (users of core/http must not link it).
  • http must be able to hand off an upgraded TCP connection (socket + prefetched bytes) to an external handler without knowing anything about WebSocket.
  • HTTP → WS integration is done via a small bridge library.
  • Use virtual interfaces (one dispatch point), no type-erasure callbacks.

Library split

  • coroio_core
  • coroio_http (generic upgrade/takeover hook, no WS dependency)
  • coroio_ws (WebSocket protocol + server session)
  • coroio_http_ws (HTTP<->WS bridge)

Checklist

WebSocket server (ws)

  • Add server-side WebSocket session support
  • Support accepting an already-upgraded connection (socket + prefetch)
  • Provide minimal public API for running a WS session loop

HTTP upgrade / takeover (http)

  • Introduce a generic connection takeover mechanism
  • Allow router to stop HTTP processing and transfer socket ownership
  • Do not introduce std::function in hot paths

HTTP<->WS bridge (http_ws)

  • Implement WebSocket upgrade handler using virtual interface
  • Perform handshake and start WS session
  • Allow routing upgrade requests by path

Testing / validation

  • Standalone WebSocket server example (no HTTP)
  • Integration test: HTTP upgrade → WebSocket session

Non-goals

  • Forcing ws dependency on core/http users
  • Adding multiple layers of dynamic dispatch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions