Update angel.dart
This commit is contained in:
parent
0ae8e81913
commit
794064219a
1 changed files with 4 additions and 4 deletions
|
@ -1,16 +1,16 @@
|
|||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'user_agent.dart';
|
||||
import 'package:user_agent/user_agent.dart' as ua;
|
||||
|
||||
/// Injects a [UserAgent] into requests.
|
||||
/// Injects a [ua.UserAgent] into requests.
|
||||
///
|
||||
/// If [strict] is `true`, then an invalid
|
||||
/// `User-Agent` header will throw a `400 Bad Request`.
|
||||
RequestMiddleware parseUserAgent({bool strict: true}) {
|
||||
return (req, res) async {
|
||||
try {
|
||||
req.inject(UserAgent, parse(req.headers.value('User-Agent')));
|
||||
req.inject(ua.UserAgent, ua.parse(req.headers.value('User-Agent')));
|
||||
} catch (e) {
|
||||
if (e is UserAgentException && strict) {
|
||||
if (e is ua.UserAgentException && strict) {
|
||||
throw new AngelHttpException.BadRequest(message: 'Invalid user agent.');
|
||||
} else {
|
||||
rethrow;
|
||||
|
|
Loading…
Reference in a new issue