Skip to content

Commit 3d3d612

Browse files
committed
some comments
1 parent 7140281 commit 3d3d612

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

pkgs/shelf_router/lib/src/router.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,23 +197,32 @@ class Router {
197197
Future<Response> _invokeMountedHandler(
198198
Request request, Function handler, List<String> pathParams) async {
199199
final paramsMap = request.params;
200+
final effectivePath = _replaceParamsInPath(request.url.path, paramsMap);
200201

202+
return await Function.apply(handler, [
203+
request.change(path: effectivePath),
204+
...pathParams.map((param) => paramsMap[param]),
205+
]) as Response;
206+
}
207+
208+
/// Replaces the variable slots (<someVar>) from [path] with the
209+
/// values from [paramsMap]
210+
String _replaceParamsInPath(
211+
String urlPath,
212+
Map<String, String> paramsMap,
213+
) {
201214
final pathParamSegment = paramsMap[_kRestPathParam];
202-
final urlPath = request.url.path;
203215
late final String effectivePath;
204216
if (pathParamSegment != null && pathParamSegment.isNotEmpty) {
205217
/// If we encounter the "rest path" parameter we remove it
206218
/// from the request path that shelf will handle.
207219
effectivePath =
208220
urlPath.substring(0, urlPath.length - pathParamSegment.length);
209221
} else {
222+
// No parameters in the requested path
210223
effectivePath = urlPath;
211224
}
212-
213-
return await Function.apply(handler, [
214-
request.change(path: effectivePath),
215-
...pathParams.map((param) => paramsMap[param]),
216-
]) as Response;
225+
return effectivePath;
217226
}
218227

219228
/// Route incoming requests to registered handlers.

0 commit comments

Comments
 (0)