RequestFilters { @API(status = MAINTAINED) public static RequestFilter defaultValue() { return defaultValues(RequestFilter.class).stream() .reduce(replaceBody(BodyReplacers.defaultValue()), RequestFilter::merge); } private  RequestFilters(); @API(status = MAINTAINED) static RequestFilter defaultValue(); static RequestFilter replaceBody(final BodyReplacer<HttpRequest> replacer);  }
@Test void shouldReplaceImageBodyByDefault() throws IOException { final RequestFilter filter = RequestFilters.defaultValue(); final HttpRequest request = filter.filter(MockHttpRequest.create() .withContentType("image/png") .withBodyAsString("this is an image")); request.withBody(); assertThat(request.getContentType(), is("image/png")); assertThat(request.getContentType(), is("image/png")); assertThat(request.getBody(), is("<binary>".getBytes(UTF_8))); assertThat(request.getBodyAsString(), is("<binary>")); }
@Test void shouldReplaceImageBodyEvenWithoutBody() throws IOException { final RequestFilter filter = RequestFilters.defaultValue(); final HttpRequest request = filter.filter(MockHttpRequest.create() .withContentType("image/png") .withBodyAsString("this is an image")); request.withoutBody(); assertThat(request.getContentType(), is("image/png")); assertThat(request.getContentType(), is("image/png")); assertThat(request.getBody(), is("<binary>".getBytes(UTF_8))); assertThat(request.getBodyAsString(), is("<binary>")); }
@Test void shouldNotReplaceTextByDefault() throws IOException { final RequestFilter filter = RequestFilters.defaultValue(); final HttpRequest request = filter.filter(MockHttpRequest.create() .withContentType("text/plain") .withBodyAsString("Hello")); request.withBody(); assertThat(request.getBody(), is("Hello".getBytes(UTF_8))); assertThat(request.getBodyAsString(), is("Hello")); }