attachToHttpServer method

void attachToHttpServer(
  1. StreamController<HttpRequest> streamController,
  2. Map? options
)
override

Captures upgrade requests for a fennec http.Server.

Implementation

void attachToHttpServer(
    StreamController<HttpRequest> streamController, Map? options) {
  options = options ?? {};
  streamController.stream.listen((event) async {
    var req = event;
    if (WebSocketTransformer.isUpgradeRequest(req) &&
        transports.contains('websocket')) {
      var socket = await WebSocketTransformer.upgrade(req);
      var socketConnect = SocketConnect.fromWebSocket(req, socket);
      socketConnect.dataset['options'] = options;
      handleUpgrade(socketConnect);
      return socketConnect.done;
    } else {
      var socketConnect = SocketConnect(req);
      socketConnect.dataset['options'] = options;
      handleRequest(socketConnect);
      return socketConnect.done;
    }
  });
}