title: Spring Cloud gateway send response in filter
body: <p>I am using spring cloud gateway as edge server. 
  This is the flow</p>
  
  <p>If request has a header named 'x-foo' then find the header value, get a string from another server and send that string as response instead of actually proxying the request.</p>
  
  <p>Here is code for Filter DSL</p>
  
  <pre><code>@Bean
      public RouteLocator routes(RouteLocatorBuilder builder) {
          return builder.routes()
                  .route("foo-filter", r -&gt; r.header('x-foo').and().header("x-intercepted").negate()
                          .filters(f -&gt; f.filter(fooFilter))
                          .uri("http://localhost:8081")) // 8081 is self port, there are other proxy related configurations too
                  .build();
      }
  </code></pre>
  
  <p>Code for Foo filter</p>
  
  <pre><code>@Component
  @Slf4j
  public class FooFilter implements GatewayFilter {
  
      @Autowired
      private ReactiveRedisOperations&lt;String, String&gt; redisOps;
  
      @Value("${header-name}")
      private String headerName;
  
      @Override
      public Mono&lt;Void&gt; filter(ServerWebExchange exchange, GatewayFilterChain chain) {
          ServerHttpRequest request = exchange.getRequest();
          var foo = request.getHeaders().getFirst(headerName);
  
          return redisOps.opsForHash()
                  .get("foo:" + foo, "response")
                  .doOnSuccess(s -&gt; {
                      log.info("data on success");
                      log.info(s.toString()); // I am getting proper response here
                      if (s != null) {
                          ServerHttpResponse response = exchange.getResponse();
                          response.setStatusCode(HttpStatus.OK);
                          response.getHeaders().set("x-intercepted", "true");
  
                          byte[] bytes = s.toString().getBytes(StandardCharsets.UTF_8);
  
                          DataBuffer buffer = response.bufferFactory().wrap(bytes);
  
                          response.writeWith(Mono.just(buffer));
  
                          response.setComplete();
                      }
                  })
                  .then(chain.filter(exchange));
      }
  
  }
  </code></pre>
  
  <p>The problem is, the response has the response is getting proper 200 code, the injected header is present on response but the data is not available in response. </p>