handle method

  1. @override
Future<HubResponse> handle(
  1. HubRequest request
)

Handles an ordinary request. The service receives the full request (its path is not stripped of mount).

Implementation

@override
Future<HubResponse> handle(HubRequest request) async {
  var pathMatched = false;
  for (final entry in _entries) {
    final params = entry.pattern.match(request.path);
    if (params == null) continue;
    pathMatched = true;
    if (entry.method == '*' || entry.method == request.method) {
      request.context['params'] = params;
      return entry.handler(request, params);
    }
  }
  // A path matched but no method did => 405; otherwise 404.
  return HubResponse.text(
    pathMatched ? 'Method Not Allowed' : 'Not Found',
    statusCode: pathMatched ? 405 : 404,
  );
}