title: Spring Cloud Zuul: Apply filter only to specific route
body: <p>I'm using Spring Cloud's Zuul to proxy some API requests to a few external servers. The proxying itself works well, but each service requires a (different) token provided in the request header.</p>
  
  <p>I've successfully written a simple pre filter for each token that applies the appropriate header. However, I now have a problem. Even after pouring through the documentation, I can't figure out how to make each filter apply only to the proper route. I don't want to perform url-matching as the url changes across environments. Ideally, I'd have some way to get the name of the route in the filter.</p>
  
  <p>My application.yml:</p>
  
  <pre><code>zuul:
    routes:
      foo:
        path: /foo/**
        url: https://fooserver.com
      bar:
        path: /bar/**
        url: https://barserver.com
  </code></pre>
  
  <p>Ideally I'd like to do something like this in FooFilter.java (a prefilter):</p>
  
  <pre><code>public bool shouldFilter() {
      return RequestContext.getCurrentContext().getRouteName().equals("foo");
  }
  </code></pre>
  
  <p>but I can't seem to find any way to do this.</p>