extract method
Produces the value, or the rejection that stops the handler.
Implementation
@override
Future<Result<FormMap, Rejection>> extract(Request request) async {
final parts = RequestParts.of(request);
if (parts.method == 'GET' || parts.method == 'HEAD') {
return Ok(FormMap(request.url.queryParameters));
}
if (parts.mediaType != 'application/x-www-form-urlencoded') {
return const Err(
Rejection.unsupportedMediaType(
'expected application/x-www-form-urlencoded',
),
);
}
switch (await readBody(request, limit: limit)) {
case Err(:final error):
return Err(error);
case Ok(:final value):
try {
return Ok(FormMap(Uri.splitQueryString(utf8.decode(value))));
} on FormatException catch (error) {
return Err(
Rejection.badRequest('malformed form body: ${error.message}'),
);
}
}
}