Set the Transfer-Encoding header instead of adding
Motivation: HttpUtil.setTransferEncodingChunked could add a second Transfer-Encoding header if one was already present. While this is technically valid, it does not appear to be the intent of the method. Result: Only one Transfer-Encoding header is present after calling this method.
This commit is contained in:
parent
d509365974
commit
9bec25a6eb
@ -312,7 +312,7 @@ public final class HttpUtil {
|
|||||||
*/
|
*/
|
||||||
public static void setTransferEncodingChunked(HttpMessage m, boolean chunked) {
|
public static void setTransferEncodingChunked(HttpMessage m, boolean chunked) {
|
||||||
if (chunked) {
|
if (chunked) {
|
||||||
m.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
|
m.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
|
||||||
m.headers().remove(HttpHeaderNames.CONTENT_LENGTH);
|
m.headers().remove(HttpHeaderNames.CONTENT_LENGTH);
|
||||||
} else {
|
} else {
|
||||||
List<String> encodings = m.headers().getAll(HttpHeaderNames.TRANSFER_ENCODING);
|
List<String> encodings = m.headers().getAll(HttpHeaderNames.TRANSFER_ENCODING);
|
||||||
|
@ -18,6 +18,7 @@ package io.netty.handler.codec.http;
|
|||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
|
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
|
||||||
@ -108,4 +109,13 @@ public class HttpUtilTest {
|
|||||||
assertEquals("bar", message.headers().get(HttpHeaderNames.CONTENT_LENGTH));
|
assertEquals("bar", message.headers().get(HttpHeaderNames.CONTENT_LENGTH));
|
||||||
assertEquals(1L, HttpUtil.getContentLength(message, 1L));
|
assertEquals(1L, HttpUtil.getContentLength(message, 1L));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDoubleChunkedHeader() {
|
||||||
|
HttpMessage message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
||||||
|
message.headers().add(HttpHeaderNames.TRANSFER_ENCODING, "chunked");
|
||||||
|
HttpUtil.setTransferEncodingChunked(message, true);
|
||||||
|
List<String> expected = Collections.singletonList("chunked");
|
||||||
|
assertEquals(expected, message.headers().getAll(HttpHeaderNames.TRANSFER_ENCODING));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user