extract method

  1. @override
Future<Result<PeerInfo, Rejection>> extract(
  1. Request request
)
override

Produces the value, or the rejection that stops the handler.

Implementation

@override
Future<Result<PeerInfo, Rejection>> extract(Request request) async {
  final info = request.context[contextKey];
  if (info is PeerInfo) return Ok(info);
  if (info is HttpConnectionInfo) {
    return Ok(
      PeerInfo(
        remoteAddress: info.remoteAddress.address,
        remotePort: info.remotePort,
        localPort: info.localPort,
      ),
    );
  }
  return const Err(
    Rejection.internal('connection information is unavailable'),
  );
}