from static method
Magically transforms an HttpRequest into a RequestContext.
Implementation
static Future<HttpRequestContext> from(
HttpRequest request,
Angel app,
String path,
) {
var ctx = HttpRequestContext().._container = app.container.createChild();
var override = request.method;
if (app.allowMethodOverrides == true) {
override =
request.headers.value('x-http-method-override')?.toUpperCase() ??
request.method;
}
ctx.app = app;
if (request.headers.contentType != null) {
try {
ctx._contentType = MediaType.parse(
request.headers.contentType.toString(),
);
} on FormatException catch (e) {
// Keep the text/plain default, as RequestContext.contentType does.
app.logger.warning(
'Invalid media type [${request.headers.contentType}]',
e,
);
}
}
ctx._override = override;
ctx._path = path;
ctx._io = request;
try {
ctx._clientCertificate = request.certificate;
} catch (_) {
// The connection closed already, so the request has no one to answer:
// dart:io throws a StateError once the socket is destroyed, and a
// TypeError once it is only closed.
}
return Future.value(ctx);
}