reactor.netty.http.client.HttpClient.compress()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(202)

本文整理了Java中reactor.netty.http.client.HttpClient.compress()方法的一些代码示例,展示了HttpClient.compress()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.compress()方法的具体详情如下:
包路径:reactor.netty.http.client.HttpClient
类名称:HttpClient
方法名:compress

HttpClient.compress介绍

[英]Specifies whether GZip compression/websocket compression extension is enabled.
[中]指定是否启用GZip压缩/websocket压缩扩展。

代码示例

代码示例来源:origin: codecentric/spring-boot-admin

private static WebClient.Builder createDefaultWebClient(Duration connectTimeout, Duration readTimeout) {
    HttpClient httpClient = HttpClient.create()
                     .compress(true)
                     .tcpConfiguration(tcp -> tcp.bootstrap(bootstrap -> bootstrap.option(
                       ChannelOption.CONNECT_TIMEOUT_MILLIS,
                       (int) connectTimeout.toMillis()
                     )).observe((connection, newState) -> {
                       if (ConnectionObserver.State.CONNECTED.equals(newState)) {
                         connection.addHandlerLast(new ReadTimeoutHandler(readTimeout.toMillis(),
                           TimeUnit.MILLISECONDS
                         ));
                       }
                     }));
    ReactorClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
    return WebClient.builder().clientConnector(connector);
  }
}

代码示例来源:origin: reactor/reactor-netty

.compress(false)
               .wiretap(true);
Tuple2<byte[], HttpHeaders> resp =

代码示例来源:origin: reactor/reactor-netty

@Test
public void compressionActivatedOnClientAddsHeader() {
  AtomicReference<String> zip = new AtomicReference<>("fail");
  HttpServer server = HttpServer.create()
                 .port(0)
                 .compress(true);
  DisposableServer runningServer =
      server.handle((in, out) -> out.sendString(Mono.just("reply")))
         .wiretap(true)
         .bindNow(Duration.ofSeconds(10));
  HttpClient client = HttpClient.create()
                 .addressSupplier(() -> address(runningServer))
                 .wiretap(true)
                 .compress(true);
  ByteBuf resp =
      client.headers(h -> zip.set(h.get("accept-encoding")))
         .get()
         .uri("/test")
         .responseContent()
         .blockLast();
  assertThat(zip.get()).isEqualTo("gzip");
  runningServer.dispose();
  runningServer.onDispose()
      .block();
}

代码示例来源:origin: reactor/reactor-netty

@Test
public void gettingOptionsDuplicates() {
  HttpClient client = HttpClient.create()
                 .tcpConfiguration(tcpClient -> tcpClient.host("foo"))
                 .wiretap(true)
                 .port(123)
                 .compress(true);
  assertThat(client.tcpConfiguration())
      .isNotSameAs(HttpClient.DEFAULT_TCP_CLIENT)
      .isNotSameAs(client.tcpConfiguration());
}

代码示例来源:origin: reactor/reactor-netty

assertThat(clientHandler.get()).isFalse();
StepVerifier.create(client.compress(true)
             .websocket()
             .uri("/")

代码示例来源:origin: reactor/reactor-netty

assertThat(clientHandler.get()).isFalse();
StepVerifier.create(client.compress(true)
             .websocket()
             .uri("/")

代码示例来源:origin: reactor/reactor-netty

@Test
public void compressionServerEnabledClientDisabledIsNone() {
  HttpServer server = HttpServer.create()
                 .port(0)
                 .compress(true);
  String serverReply = "reply";
  DisposableServer runningServer =
      server.handle((in, out) -> out.sendString(Mono.just(serverReply)))
         .wiretap(true)
         .bindNow(Duration.ofSeconds(10));
  HttpClient client = HttpClient.create()
                 .addressSupplier(() -> address(runningServer))
                 .wiretap(true)
                 .compress(false);
  Tuple2<String, HttpHeaders> resp =
      client.get()
         .uri("/test")
         .response((res, buf) -> buf.asString()
                       .zipWith(Mono.just(res.responseHeaders())))
         .blockFirst();
  assertThat(resp.getT2().get("Content-Encoding")).isNull();
  assertThat(resp.getT1()).isEqualTo(serverReply);
  runningServer.dispose();
  runningServer.onDispose()
        .block();
}

代码示例来源:origin: reactor/reactor-netty

private void doTestGzip(boolean gzipEnabled) {
  String expectedResponse = gzipEnabled ? "gzip" : "no gzip";
  DisposableServer server =
      HttpServer.create()
           .port(0)
           .handle((req,res) -> res.sendString(Mono.just(req.requestHeaders()
                                    .get(HttpHeaderNames.ACCEPT_ENCODING,
                                      "no gzip"))))
           .wiretap(true)
           .bindNow();
  HttpClient client = createHttpClientForContextWithPort(server);
  if (gzipEnabled){
    client = client.compress(true);
  }
  StepVerifier.create(client.get()
               .uri("/")
               .response((r, buf) -> buf.asString()
                            .elementAt(0)
                            .zipWith(Mono.just(r))))
        .expectNextMatches(tuple -> expectedResponse.equals(tuple.getT1()))
        .expectComplete()
        .verify(Duration.ofSeconds(30));
  server.disposeNow();
}

代码示例来源:origin: reactor/reactor-netty

client = HttpClient.create()
          .addressSupplier(context::address)
          .compress(true);

代码示例来源:origin: reactor/reactor-netty

@Test
public void trueEnabledIncludeContentEncoding() {
  HttpServer server = HttpServer.create()
                 .port(0)
                 .compress(true);
  DisposableServer runningServer =
      server.handle((in, out) -> out.sendString(Mono.just("reply")))
         .wiretap(true)
         .bindNow(Duration.ofSeconds(10));
  HttpClient client = HttpClient.create()
                 .addressSupplier(() -> address(runningServer))
                 .wiretap(true)
                 .compress(true);
  ByteBuf res =
      client.headers(h -> Assert.assertTrue(h.contains("Accept-Encoding", "gzip", true)))
         .get()
         .uri("/test")
         .responseContent()
         .blockLast();
  runningServer.dispose();
  runningServer.onDispose()
        .block();
}

代码示例来源:origin: reactor/reactor-netty

HttpClient.create()
     .port(server.address().getPort())
     .compress(true)
     .wiretap(true)
     .get()
       .port(server.address().getPort())
       .wiretap(true)
       .compress(true)
       .get()
       .uri("/")

代码示例来源:origin: reactor/reactor-netty

HttpClient.create()
     .port(server.address().getPort())
     .compress(true)
     .post()
     .uri("/hi")
          .compress(true)
          .get()
          .uri("/stream")
HttpClient.create()
     .port(server.address().getPort())
     .compress(true)
     .post()
     .uri("/hi")

代码示例来源:origin: reactor/reactor-netty

HttpClient.create()
     .port(server.address().getPort())
     .compress(true)
     .post()
     .uri("/hi")
          .compress(true)
          .get()
          .uri("/stream")
HttpClient.create()
     .port(server.address().getPort())
     .compress(true)
     .post()
     .uri("/hi")

相关文章