This commit is contained in:
thosakwe 2017-01-25 17:51:33 -05:00
parent 81a4081441
commit 84f84f9b3b
2 changed files with 4 additions and 3 deletions

View file

@ -9,7 +9,7 @@ RequestMiddleware parseUserAgent({bool strict: true}) {
return (RequestContext req, res) async { return (RequestContext req, res) async {
var agentString = req.headers.value('user-agent'); var agentString = req.headers.value('user-agent');
if (agentString == null) { if (agentString == null && strict) {
throw new AngelHttpException.badRequest( throw new AngelHttpException.badRequest(
message: 'User-Agent header is required.'); message: 'User-Agent header is required.');
} else if (agentString != null) { } else if (agentString != null) {
@ -17,7 +17,8 @@ RequestMiddleware parseUserAgent({bool strict: true}) {
req.headers.forEach((k, v) => map[k] = v); req.headers.forEach((k, v) => map[k] = v);
req.inject(UserAgent, new UserAgent(agentString, headers: map)); req.inject(UserAgent, new UserAgent(agentString, headers: map));
} } else
req.inject(UserAgent, null);
return true; return true;
}; };

View file

@ -1,5 +1,5 @@
name: angel_user_agent name: angel_user_agent
version: 1.0.0 version: 1.0.1
description: Middleware to inject a User Agent object into requests. description: Middleware to inject a User Agent object into requests.
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/user_agent homepage: https://github.com/angel-dart/user_agent