justinfagnani / route

A client + server routing library for Dart
BSD 3-Clause "New" or "Revised" License
114 stars 40 forks source link

[server] Allow multiple filters per URL pattern #72

Open fpoehler opened 10 years ago

fpoehler commented 10 years ago

Currently only one filter per URL pattern can be applied:

class Router {
  ...
  void filter(Pattern url, Filter filter) {
    _filters[url] = filter;
  }
}

Each filter added for an already existing URL pattern causes the filter applied formerly to be overwritten.

Sometimes it would be very convenient to be able to apply multiple filters for the same URL pattern, e.g. first an authentication and afterwards an authorization filter.

Then the router should apply both filters in the order they were added, i.e. _filters[url] should be a List or a Queue and filter should perform something like

  _filters[url].add(filter);

(The workarounds – either to combine all the applicable filters in a separate function or to create multiple URL patterns which all resolve to the very same route – are both quite ugly and inconvenient.)