[#1321] HttpHeaders.removeTransferEncodingChunked(..) must handle the value in case insensitive manner

This commit is contained in:
Norman Maurer 2013-04-30 20:41:20 +02:00
parent 6646db171e
commit 57a8a9fd98
3 changed files with 69 additions and 2 deletions

View File

@ -1141,7 +1141,16 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
public static void removeTransferEncodingChunked(HttpMessage m) {
List<String> values = m.headers().getAll(Names.TRANSFER_ENCODING);
values.remove(Values.CHUNKED);
if (values.isEmpty()) {
return;
}
Iterator<String> valuesIt = values.iterator();
while(valuesIt.hasNext()) {
String value = valuesIt.next();
if (value.equalsIgnoreCase(Values.CHUNKED)) {
valuesIt.remove();
}
}
if (values.isEmpty()) {
m.headers().remove(Names.TRANSFER_ENCODING);
} else {

View File

@ -0,0 +1,30 @@
/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.handler.codec.http;
import org.junit.Assert;
import org.junit.Test;
public class HttpHeadersTest {
@Test
public void testRemoveTransferEncodingIgnoreCase() {
HttpMessage message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
message.headers().set(HttpHeaders.Names.TRANSFER_ENCODING, "Chunked");
HttpHeaders.removeTransferEncodingChunked(message);
Assert.assertTrue(message.headers().isEmpty());
}
}

View File

@ -59,7 +59,7 @@ public class HttpObjecctAggregatorTest {
assertNull(embedder.readInbound());
}
private static void checkContentBuffer(DefaultFullHttpRequest aggregatedMessage) {
private static void checkContentBuffer(FullHttpRequest aggregatedMessage) {
CompositeByteBuf buffer = (CompositeByteBuf) aggregatedMessage.data();
assertEquals(2, buffer.numComponents());
List<ByteBuf> buffers = buffer.decompose(0, buffer.capacity());
@ -135,4 +135,32 @@ public class HttpObjecctAggregatorTest {
aggr.handlerAdded(ctx);
aggr.setMaxCumulationBufferComponents(10);
}
@Test
public void testAggregateTransferEncodingChunked() {
HttpObjectAggregator aggr = new HttpObjectAggregator(1024 * 1024);
EmbeddedMessageChannel embedder = new EmbeddedMessageChannel(aggr);
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1,
HttpMethod.GET, "http://localhost");
HttpHeaders.setHeader(message, "X-Test", true);
HttpHeaders.setHeader(message, "Transfer-Encoding", "Chunked");
HttpContent chunk1 = new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII));
HttpContent chunk2 = new DefaultHttpContent(Unpooled.copiedBuffer("test2", CharsetUtil.US_ASCII));
HttpContent chunk3 = LastHttpContent.EMPTY_LAST_CONTENT;
assertFalse(embedder.writeInbound(message));
assertFalse(embedder.writeInbound(chunk1));
assertFalse(embedder.writeInbound(chunk2));
// this should trigger a messageReceived event so return true
assertTrue(embedder.writeInbound(chunk3));
assertTrue(embedder.finish());
FullHttpRequest aggratedMessage = (FullHttpRequest) embedder.readInbound();
assertNotNull(aggratedMessage);
assertEquals(chunk1.data().readableBytes() + chunk2.data().readableBytes(), HttpHeaders.getContentLength(aggratedMessage));
assertEquals(aggratedMessage.headers().get("X-Test"), Boolean.TRUE.toString());
checkContentBuffer(aggratedMessage);
assertNull(embedder.readInbound());
}
}