【问题标题】:Max number of follow redirects for webClient with ReactorClientHttpConnector使用 ReactorClientHttpConnector 的 webClient 的最大跟踪重定向数
【发布时间】:2021-11-22 20:41:15
【问题描述】:

我在org.apache.http.client 库中的httpClient 中看到了这个概念,我想重现它。 3 次重定向后 WebClient 将如何跟随和停止。

HttpClient client = HttpClient.create()
        .responseTimeout(Duration.ofMillis(2000))
        .followRedirect(true);

WebClient webClient = WebClient.builder()
        .baseUrl("https://test.com")
        .clientConnector(new ReactorClientHttpConnector(client))
        .build();

【问题讨论】:

    标签: redirect spring-webclient reactor-netty


    【解决方案1】:

    这样做的预期方法是使用以下内容并提供谓词:

    reactor.netty.http.client.HttpClient#followRedirect(BiPredicate<HttpClientRequest, HttpClientResponse> predicate)
    

    像这样:

        HttpClient.create()
            .followRedirect((req, res) -> req.redirectedFrom().length < 3);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-15
      • 2010-09-26
      • 1970-01-01
      • 2011-01-30
      • 2014-04-13
      • 1970-01-01
      • 2020-11-17
      相关资源
      最近更新 更多