Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods optional argument to filter #80

Open
tusj opened this issue Mar 7, 2014 · 0 comments
Open

Add methods optional argument to filter #80

tusj opened this issue Mar 7, 2014 · 0 comments

Comments

@tusj
Copy link

tusj commented Mar 7, 2014

I'd like to apply a filter on certain methods. I have an authorization filter which I'd like to only work on GET and POST methods. The solution is not to add that check within the authorization method itself, but I feel that is much uglier.

How it has to be now:

Future<bool> filterAuth(HttpRequest r) {...}
...
var router = new Router(server) 
  ..filter(new RegExp(r'/auth/.*'), (HttpRequest r) {
      if (r.method != 'OPTIONS') {
        return filterAuth(r);
      }
       return new Future.value(true);
    })
...

The cleaner solution:

var router = new Router(server)
  ..filter(new RegExp(r'/auth/.*'), methods: ['GET', 'POST'], filterAuth);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant