spring-cloud / spring-cloud/spring-cloud-gateway

WebClient Request/Response bug?

Open
#2,839 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

Describe the bug
Enabling WebClientHttpRoutingFilter & WebClientWriteResponseFilter leaves gateway client hanging. I can confirm that downstream HTTP calls works fine (200 OK with String Response), gateway logs also confirm 200 OK, but client is left hanging. Disabling WebClientHttpRoutingFilter & WebClientWriteResponseFilter beans (i.e., using default Netty routing & response handling) works just fine. We'd like to use a custom WebClient hence looking to get WebClientWriteResponseFilter working.

Appreciate any pointers. thanks

Sample

@Configuration
public class GatewayFilterConfig {
    @Bean
    public WebClient webClient() {
        return WebClient.builder().build();
    }

    @Bean
    public CustomWebClientRoutingFilter customWebClientRoutingFilter
            (WebClient webClient, ObjectProvider<List<HttpHeadersFilter>> headersFilters) {
        return new CustomWebClientRoutingFilter(webClient, headersFilters);
    }

    @Bean
    public CustomWebClientResponseFilter customWebClientResponseFilter () {
        return new CustomWebClientResponseFilter();
    }
}
public class CustomWebClientRoutingFilter extends WebClientHttpRoutingFilter {
    public CustomWebClientRoutingFilter(WebClient webClient, ObjectProvider<List<HttpHeadersFilter>> headersFiltersProvider) {
        super(webClient, headersFiltersProvider);
    }

    @Override
    public int getOrder() {
        return Integer.MAX_VALUE - 1; //Run before the NettyRoutingFilter
    }
}
public class CustomWebClientResponseFilter extends WebClientWriteResponseFilter {
    @Override
    public int getOrder() {
        return Integer.MAX_VALUE;
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with WebClientHttpRoutingFilter and WebClientWriteResponseFilter, then reproduce the supplied GatewayFilterConfig and custom filter order. Compare the WebClient path with the default Netty routing and response handling; the issue is done when a downstream 200 response is delivered to the client instead of leaving it hanging.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.