fromRequest static method

Future<HttpStyleRequest> fromRequest({
  1. required HttpRequest req,
  2. required dynamic body,
  3. required BuildContext context,
})

Implementation

static Future<HttpStyleRequest> fromRequest(
    {required HttpRequest req,
    required dynamic body,
    required BuildContext context}) async {
  // print("AUTH:::: "
  //     "${req.uri.queryParameters["token"]
  //     ?? req.headers[HttpHeaders.authorizationHeader]}");

  var q = req.uri.queryParameters;
  var t = req.headers[HttpHeaders.authorizationHeader]?.first ?? q["token"];
  AccessToken? token;
  if (t != null && context.hasService<Authorization>()) {
    token = await Authorization.of(context).verifyToken(t);
  }
  return HttpStyleRequest(
      baseRequest: req,
      contentType: req.headers.contentType,
      method: Methods.values[_m.indexOf(req.method)],
      context: RequestContext(
          requestTime: DateTime.now(),
          cause: Cause.clientRequest,
          agent: Agent.http,
          accessToken: token,
          // TODO: Look cookies for token
          // createContext: context,
          pathController: PathController.fromHttpRequest(req)),
      body: body);
}