title: Spring Cloud Gateway: Request headers seems to be cached when using route level filters
body: <p>I'm experiencing a strange behaviour when using filters with Spring Cloud Gateway, given the following configuration sample:</p>
  <pre><code>@Configuration
  public class SpringCloudConfig {
  
    @Bean
    public RouteLocator gatewayRoutes(RouteLocatorBuilder builder) {
      return builder.routes()
          .route(r -&gt; r.path(&quot;/sample/v1/api&quot;)
              .filters(f -&gt; f.rewritePath(&quot;/sample&quot;, &quot;&quot;).addRequestHeader(&quot;route-random&quot;,
                  (int) Math.floor(Math.random() * 100) + &quot;&quot;)
                  .filter(new AddHeaderCustomFilter().apply(new HeaderConfig(
                      &quot;filter-random&quot;, (int) Math.floor(Math.random() * 100) + &quot;&quot;))))
              .uri(&quot;http://localhost:8085&quot;))
          .build();
    }
  }
  </code></pre>
  <p>If I perform two or more dinstict requests to &quot;/sample/v1/api&quot; the &quot;route-random&quot; and &quot;filter-random&quot; headers will always have the same value i.e. the random value generated for the first request.
  Using a Global filter instead:</p>
  <pre><code>@Component
  public class CustomGlobalFilter {
  
    @Bean
    public GlobalFilter globalFilter() {
      return (exchange, chain) -&gt; {
        exchange.getRequest().mutate()
            .header(&quot;global-random&quot;, (int) Math.floor(Math.random() * 100) + &quot;&quot;).build();
        return chain.filter(exchange);
      };
    }
  }
  </code></pre>
  <p>The &quot;global-random&quot; header seems to be effectly random for each request.
  Can someone explain why the value seems to be cached when using route level filters and a possible solution instead of using global filters?</p>
  <p>Thanks in advance.</p>