title: How to send a portion of the requests to another url
body: <p>I have a web service which handles GET/POST/PUT HTTP requests using a Spring Rest Controller (using Netty and not Apache Tomcat). I wish to filter all the requests coming in my service, and when a request has a certain header configured, I want to send this specific request to a whole different URL, while returning the response to the same entity which sent the original request.</p>
  <p>Here is my code:</p>
  <pre class="lang-java prettyprint-override"><code>@Component
  public class MyWebFilter implements WebFilter {
  
      @Autowired
      private SomeService someService;
      private final Logger log = LoggerFactory.getLogger(MyWebFilter.class);
  
      @Override
      public Mono&lt;Void&gt; filter(ServerWebExchange serverWebExchange, WebFilterChain webFilterChain) {
          HttpHeaders headers = serverWebExchange.getRequest().getHeaders();
          if (headers.containsKey(&quot;someHeader&quot;)) {
              if (someService.askSomething(Objects.requireNonNull(headers.get(&quot;someHeader&quot;)))) {
                  URI originalUri = serverWebExchange.getRequest().getURI();
                  log.info(&quot;Redirecting request with URI {} to some service&quot;, originalUri.getPath());
                  try {
                      URI someUri = new URI(&quot;http&quot;,
                              originalUri.getUserInfo(),
                              someService.getHost(),
                              someService.getPort(),
                              originalUri.getPath(),
                              originalUri.getQuery(),
                              originalUri.getFragment());
                      ServerHttpRequest newRequest =  serverWebExchange.getRequest().mutate().uri(someUri).build();
                      ServerWebExchange newExchange = serverWebExchange.mutate().request(newRequest).build();
                      return webFilterChain.filter(newExchange);
                  } catch (URISyntaxException e) {
                      throw new IllegalStateException(e.getMessage(), e);
                  }
              }
          }
          return webFilterChain.filter(serverWebExchange);
      }
  }
  </code></pre>
  <p>With this implementation the request is simply passed through to my normal rest controller and does not reach the other service. What am I missing here?</p>