verify method

void verify(
  1. SocketConnect connect,
  2. bool upgrade,
  3. dynamic fn
)

Verifies a request.

Implementation

void verify(SocketConnect connect, bool upgrade, fn) {
  // transport check
  var req = connect.request;
  var transport = req.uri.queryParameters['transport'];
  if (!transports.contains(transport)) {
    fn(ServerErrors.unknownTransport, false);
    return;
  }
  var sid = req.uri.queryParameters['sid'];
  if (sid != null) {
    if (!clients.containsKey(sid)) {
      fn(ServerErrors.unknownSid, false);
      return;
    }
    if (!upgrade && clients[sid].transport.name != transport) {
      fn(ServerErrors.badRequest, false);
      return;
    }
  } else {
    if ('GET' != req.method) {
      fn(ServerErrors.badHandshakeMethod, false);
      return;
    }
    if (allowRequest == null) {
      fn(null, true);
      return;
    }
    allowRequest!(req, fn);
    return;
  }

  fn(null, true);
  return;
}