title: spring cloud gateway intercept all incoming and outgoing request
body: <p>It going to be one backend application that expose some REST endpoint and can make call to other backend.
  This application run in one host. I want on same host run other application - Sidecar. It should:
  1)Sidecar should receive all outgoing traffic of Backend app to add additional auth header.
  2)Sidecar should receive all incoming traffic and check auth header then forward to Backend app.</p>
  <p>Sidecar should be spring-boot app. I going to choose -Spring cloud gateway.</p>
  <p>To solve 1) I going to call all Backend App request by Proxy - and proxy is Sidecar cloud GW
  To solve 2) I going to expose only Sidecar endpoint /**  that receive all incoming traffic and forward to Backend App</p>
  <p>Next code work for  When Backend App initiate outgoing request and use Sidecar as Proxy</p>
  <pre><code>@SpringBootApplication
  @RestController
  public class DemoApplication {
  
  public static void main(String[] args) {
      SpringApplication.run(DemoApplication.class, args);
  }
  
  @RequestMapping(&quot;/**&quot;)
  public Mono&lt;ResponseEntity&lt;byte[]&gt;&gt; proxy(ProxyExchange&lt;byte[]&gt; proxy, ServerHttpRequest serverHttpRequest) throws Exception {
      return proxy.uri(serverHttpRequest.getURI().toString()).forward();
  }
  }
  </code></pre>
  <p>At same time code above will intercept all external incoming request and send it again to Sidecar that lead to infinite loop.</p>
  <p>Any suggestion haw to write Sidecar(Spring cloud gateway) that from the one hand it will be used as Proxy for outgoing request and from the other hand Forward all incoming request to  Backend App</p>
  <p>Thanks</p>