private LiveHttpResponse removeRedundantContentLengthHeader(LiveHttpResponse response) { if (contentValidation && response.contentLength().isPresent() && response.chunked()) { return response.newBuilder() .removeHeader(CONTENT_LENGTH) .build(); } return response; }
private ChannelFuture writeHeaders(LiveHttpResponse response) { io.netty.handler.codec.http.HttpResponse nettyResponse = responseTranslator.toNettyResponse(response); if (!(response.contentLength().isPresent() || response.chunked())) { setTransferEncodingChunked(nettyResponse); } return nettyWriteAndFlush(nettyResponse); }
@Test public void shouldNotFailToRemoveNonExistentContentLength() { LiveHttpResponse response = response().build(); LiveHttpResponse chunkedResponse = response.newBuilder().setChunked().build(); assertThat(chunkedResponse.chunked(), is(true)); assertThat(chunkedResponse.header(CONTENT_LENGTH).isPresent(), is(false)); }
@Test public void shouldRemoveContentLengthFromChunkedMessages() { LiveHttpResponse response = response().header(CONTENT_LENGTH, 5).build(); LiveHttpResponse chunkedResponse = response.newBuilder().setChunked().build(); assertThat(chunkedResponse.chunked(), is(true)); assertThat(chunkedResponse.header(CONTENT_LENGTH).isPresent(), is(false)); }