ContentPreviewingService extends SimpleDecoratingHttpService { public static Function<? super HttpService, ContentPreviewingService> newDecorator(int maxLength) { final ContentPreviewerFactory factory = ContentPreviewerFactory.text(maxLength); return delegate -> new ContentPreviewingService(delegate, factory); } private  ContentPreviewingService(HttpService delegate, ContentPreviewerFactory contentPreviewerFactory); static Function<? super HttpService, ContentPreviewingService> newDecorator(int maxLength); static Function<? super HttpService, ContentPreviewingService> newDecorator(
            int maxLength, Charset defaultCharset); static Function<? super HttpService, ContentPreviewingService> newDecorator(
            ContentPreviewerFactory contentPreviewerFactory); @Override HttpResponse serve(ServiceRequestContext ctx, HttpRequest req);  }
@Test void contentPreviewBeforeEncoding() { final WebClient client = WebClient.builder(server.httpUri()) .decorator(DecodingClient.newDecorator()) .build(); final RequestHeaders headers = RequestHeaders.of(HttpMethod.POST, "/beforeEncoding", HttpHeaderNames.CONTENT_TYPE, "text/plain"); assertThat(client.execute(headers, "Armeria").aggregate().join().contentUtf8()) .isEqualTo("Hello Armeria!"); final RequestLog requestLog = contextCaptor.get().log().whenComplete().join(); assertThat(requestLog.requestContentPreview()).isEqualTo("Armeria"); assertThat(requestLog.responseContentPreview()).isEqualTo("Hello Armeria!"); }
@Test void encodedContentPreviewIsDecodedInPreviewer() { final WebClient client = WebClient.builder(server.httpUri()) .decorator(DecodingClient.newDecorator()) .build(); final RequestHeaders headers = RequestHeaders.of(HttpMethod.POST, "/encoded", HttpHeaderNames.CONTENT_TYPE, "text/plain"); final AggregatedHttpResponse res = client.execute(headers, "Armeria").aggregate().join(); assertThat(res.contentUtf8()).isEqualTo("Hello Armeria!"); assertThat(res.headers().get(HttpHeaderNames.CONTENT_ENCODING)).isEqualTo("gzip"); final RequestLog requestLog = contextCaptor.get().log().whenComplete().join(); assertThat(requestLog.requestContentPreview()).isEqualTo("Armeria"); assertThat(requestLog.responseContentPreview()).isEqualTo("Hello Armeria!"); }