From fcd8a3ed1e30a5c9c71c2e3ee1a380653c1abff4 Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Sat, 22 Aug 2015 08:25:57 -0700 Subject: [PATCH] Refactor of HttpUtil and HttpHeaderUtil Motivation: There currently exists http.HttpUtil, http2.HttpUtil, and http.HttpHeaderUtil. Having 2 HttpUtil methods can be confusing and the utilty methods in the http package could be consolidated. Modifications: - Rename http2.HttpUtil to http2.HttpConversionUtil - Move http.HttpHeaderUtil methods into http.HttpUtil Result: Consolidated utilities whose names don't overlap. Fixes https://github.com/netty/netty/issues/4120 --- .../codec/http/HttpObjectAggregator.java | 10 +- .../handler/codec/http/HttpObjectDecoder.java | 8 +- .../handler/codec/http/HttpObjectEncoder.java | 2 +- .../io/netty/handler/codec/http/HttpUtil.java | 251 ++++++++++++++++++ .../multipart/HttpPostRequestEncoder.java | 4 +- .../WebSocketServerHandshakerFactory.java | 4 +- .../handler/codec/spdy/SpdyHttpDecoder.java | 14 +- .../codec/http/DefaultHttpHeadersTest.java | 2 +- .../handler/codec/http/HttpHeadersTest.java | 72 +++++ .../codec/http/HttpObjectAggregatorTest.java | 32 +-- ...pHeaderUtilTest.java => HttpUtilTest.java} | 4 +- .../WebSocketServerHandshakerFactoryTest.java | 6 +- ...{HttpUtil.java => HttpConversionUtil.java} | 8 +- .../http2/HttpToHttp2ConnectionHandler.java | 7 +- .../http2/InboundHttp2ToHttpAdapter.java | 12 +- .../InboundHttp2ToHttpPriorityAdapter.java | 16 +- .../HttpToHttp2ConnectionHandlerTest.java | 54 ++-- .../http2/InboundHttp2ToHttpAdapterTest.java | 55 ++-- .../file/HttpStaticFileServerHandler.java | 8 +- .../HttpHelloWorldServerHandler.java | 7 +- .../http/snoop/HttpSnoopClientHandler.java | 4 +- .../http/snoop/HttpSnoopServerHandler.java | 6 +- .../http/upload/HttpUploadClientHandler.java | 4 +- .../http/upload/HttpUploadServerHandler.java | 4 +- .../WebSocketServerHandler.java | 8 +- .../server/WebSocketServerHandler.java | 8 +- .../client/HttpResponseHandler.java | 4 +- .../server/HelloWorldHttp1Handler.java | 6 +- .../http2/tiles/FallbackRequestHandler.java | 4 +- .../http2/tiles/Http1RequestHandler.java | 8 +- .../http2/tiles/Http2RequestHandler.java | 8 +- .../client/HttpResponseClientHandler.java | 4 +- 32 files changed, 483 insertions(+), 161 deletions(-) create mode 100644 codec-http/src/test/java/io/netty/handler/codec/http/HttpHeadersTest.java rename codec-http/src/test/java/io/netty/handler/codec/http/{HttpHeaderUtilTest.java => HttpUtilTest.java} (95%) rename codec-http2/src/main/java/io/netty/handler/codec/http2/{HttpUtil.java => HttpConversionUtil.java} (99%) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java index f4c9b77672..56f0a641a5 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java @@ -30,7 +30,7 @@ import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH; -import static io.netty.handler.codec.http.HttpHeaderUtil.getContentLength; +import static io.netty.handler.codec.http.HttpUtil.getContentLength; /** * A {@link ChannelHandler} that aggregates an {@link HttpMessage} @@ -119,7 +119,7 @@ public class HttpObjectAggregator @Override protected Object newContinueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline) { - if (HttpHeaderUtil.is100ContinueExpected(start)) { + if (HttpUtil.is100ContinueExpected(start)) { if (getContentLength(start, -1) <= maxContentLength) { return CONTINUE.duplicate().retain(); } @@ -145,7 +145,7 @@ public class HttpObjectAggregator protected FullHttpMessage beginAggregation(HttpMessage start, ByteBuf content) throws Exception { assert !(start instanceof FullHttpMessage); - HttpHeaderUtil.setTransferEncodingChunked(start, false); + HttpUtil.setTransferEncodingChunked(start, false); AggregatedFullHttpMessage ret; if (start instanceof HttpRequest) { @@ -174,7 +174,7 @@ public class HttpObjectAggregator // transmitted if a GET would have been used. // // See rfc2616 14.13 Content-Length - if (!HttpHeaderUtil.isContentLengthSet(aggregated)) { + if (!HttpUtil.isContentLengthSet(aggregated)) { aggregated.headers().set( HttpHeaderNames.CONTENT_LENGTH, String.valueOf(aggregated.content().readableBytes())); @@ -199,7 +199,7 @@ public class HttpObjectAggregator // If the client started to send data already, close because it's impossible to recover. // If keep-alive is off and 'Expect: 100-continue' is missing, no need to leave the connection open. if (oversized instanceof FullHttpMessage || - !HttpHeaderUtil.is100ContinueExpected(oversized) && !HttpHeaderUtil.isKeepAlive(oversized)) { + !HttpUtil.is100ContinueExpected(oversized) && !HttpUtil.isKeepAlive(oversized)) { future.addListener(ChannelFutureListener.CLOSE); } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java index 7dff08f33d..f1fafdbd6a 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java @@ -398,7 +398,7 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder { // Handle the last unfinished message. if (message != null) { - boolean chunked = HttpHeaderUtil.isTransferEncodingChunked(message); + boolean chunked = HttpUtil.isTransferEncodingChunked(message); if (currentState == State.READ_VARIABLE_LENGTH_CONTENT && !in.isReadable() && !chunked) { // End of connection. out.add(LastHttpContent.EMPTY_LAST_CONTENT); @@ -588,9 +588,9 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder { State nextState; if (isContentAlwaysEmpty(message)) { - HttpHeaderUtil.setTransferEncodingChunked(message, false); + HttpUtil.setTransferEncodingChunked(message, false); nextState = State.SKIP_CONTROL_CHARS; - } else if (HttpHeaderUtil.isTransferEncodingChunked(message)) { + } else if (HttpUtil.isTransferEncodingChunked(message)) { nextState = State.READ_CHUNK_SIZE; } else if (contentLength() >= 0) { nextState = State.READ_FIXED_LENGTH_CONTENT; @@ -602,7 +602,7 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder { private long contentLength() { if (contentLength == Long.MIN_VALUE) { - contentLength = HttpHeaderUtil.getContentLength(message, -1); + contentLength = HttpUtil.getContentLength(message, -1); } return contentLength; } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java index 8eff14fa51..b8e38e5d71 100755 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java @@ -73,7 +73,7 @@ public abstract class HttpObjectEncoder extends MessageTo encodeInitialLine(buf, m); encodeHeaders(m.headers(), buf); buf.writeBytes(CRLF); - state = HttpHeaderUtil.isTransferEncodingChunked(m) ? ST_CONTENT_CHUNK : ST_CONTENT_NON_CHUNK; + state = HttpUtil.isTransferEncodingChunked(m) ? ST_CONTENT_CHUNK : ST_CONTENT_NON_CHUNK; } // Bypass the encoder in case of an empty buffer, so that the following idiom works: diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpUtil.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpUtil.java index 32ae35ea5e..c7e62f299b 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpUtil.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpUtil.java @@ -15,7 +15,11 @@ */ package io.netty.handler.codec.http; +import io.netty.buffer.ByteBuf; + import java.net.URI; +import java.util.Iterator; +import java.util.List; /** * Utility methods useful in the HTTP context. @@ -42,4 +46,251 @@ public final class HttpUtil { uri.getHost() == null && uri.getAuthority() == null && uri.getQuery() == null && uri.getFragment() == null; } + + /** + * Returns {@code true} if and only if the connection can remain open and + * thus 'kept alive'. This methods respects the value of the + * {@code "Connection"} header first and then the return value of + * {@link HttpVersion#isKeepAliveDefault()}. + */ + public static boolean isKeepAlive(HttpMessage message) { + CharSequence connection = message.headers().get(HttpHeaderNames.CONNECTION); + if (connection != null && HttpHeaderValues.CLOSE.contentEqualsIgnoreCase(connection)) { + return false; + } + + if (message.protocolVersion().isKeepAliveDefault()) { + return !HttpHeaderValues.CLOSE.contentEqualsIgnoreCase(connection); + } else { + return HttpHeaderValues.KEEP_ALIVE.contentEqualsIgnoreCase(connection); + } + } + + /** + * Sets the value of the {@code "Connection"} header depending on the + * protocol version of the specified message. This getMethod sets or removes + * the {@code "Connection"} header depending on what the default keep alive + * mode of the message's protocol version is, as specified by + * {@link HttpVersion#isKeepAliveDefault()}. + * + */ + public static void setKeepAlive(HttpMessage message, boolean keepAlive) { + HttpHeaders h = message.headers(); + if (message.protocolVersion().isKeepAliveDefault()) { + if (keepAlive) { + h.remove(HttpHeaderNames.CONNECTION); + } else { + h.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE); + } + } else { + if (keepAlive) { + h.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); + } else { + h.remove(HttpHeaderNames.CONNECTION); + } + } + } + + /** + * Returns the length of the content. Please note that this value is + * not retrieved from {@link HttpContent#content()} but from the + * {@code "Content-Length"} header, and thus they are independent from each + * other. + * + * @return the content length + * + * @throws NumberFormatException + * if the message does not have the {@code "Content-Length"} header + * or its value is not a number + */ + public static long getContentLength(HttpMessage message) { + Long value = message.headers().getLong(HttpHeaderNames.CONTENT_LENGTH); + if (value != null) { + return value; + } + + // We know the content length if it's a Web Socket message even if + // Content-Length header is missing. + long webSocketContentLength = getWebSocketContentLength(message); + if (webSocketContentLength >= 0) { + return webSocketContentLength; + } + + // Otherwise we don't. + throw new NumberFormatException("header not found: " + HttpHeaderNames.CONTENT_LENGTH); + } + + /** + * Returns the length of the content. Please note that this value is + * not retrieved from {@link HttpContent#content()} but from the + * {@code "Content-Length"} header, and thus they are independent from each + * other. + * + * @return the content length or {@code defaultValue} if this message does + * not have the {@code "Content-Length"} header or its value is not + * a number + */ + public static long getContentLength(HttpMessage message, long defaultValue) { + Long value = message.headers().getLong(HttpHeaderNames.CONTENT_LENGTH); + if (value != null) { + return value; + } + + // We know the content length if it's a Web Socket message even if + // Content-Length header is missing. + long webSocketContentLength = getWebSocketContentLength(message); + if (webSocketContentLength >= 0) { + return webSocketContentLength; + } + + // Otherwise we don't. + return defaultValue; + } + + /** + * Get an {@code int} representation of {@link #getContentLength(HttpMessage, long)}. + * @return the content length or {@code defaultValue} if this message does + * not have the {@code "Content-Length"} header or its value is not + * a number. Not to exceed the boundaries of integer. + */ + public static int getContentLength(HttpMessage message, int defaultValue) { + return (int) Math.min(Integer.MAX_VALUE, HttpHeaderUtil.getContentLength(message, (long) defaultValue)); + } + + /** + * Returns the content length of the specified web socket message. If the + * specified message is not a web socket message, {@code -1} is returned. + */ + private static int getWebSocketContentLength(HttpMessage message) { + // WebSockset messages have constant content-lengths. + HttpHeaders h = message.headers(); + if (message instanceof HttpRequest) { + HttpRequest req = (HttpRequest) message; + if (HttpMethod.GET.equals(req.method()) && + h.contains(HttpHeaderNames.SEC_WEBSOCKET_KEY1) && + h.contains(HttpHeaderNames.SEC_WEBSOCKET_KEY2)) { + return 8; + } + } else if (message instanceof HttpResponse) { + HttpResponse res = (HttpResponse) message; + if (res.status().code() == 101 && + h.contains(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN) && + h.contains(HttpHeaderNames.SEC_WEBSOCKET_LOCATION)) { + return 16; + } + } + + // Not a web socket message + return -1; + } + + /** + * Sets the {@code "Content-Length"} header. + */ + public static void setContentLength(HttpMessage message, long length) { + message.headers().setLong(HttpHeaderNames.CONTENT_LENGTH, length); + } + + public static boolean isContentLengthSet(HttpMessage m) { + return m.headers().contains(HttpHeaderNames.CONTENT_LENGTH); + } + + /** + * Returns {@code true} if and only if the specified message contains the + * {@code "Expect: 100-continue"} header. + */ + public static boolean is100ContinueExpected(HttpMessage message) { + // Expect: 100-continue is for requests only. + if (!(message instanceof HttpRequest)) { + return false; + } + + // It works only on HTTP/1.1 or later. + if (message.protocolVersion().compareTo(HttpVersion.HTTP_1_1) < 0) { + return false; + } + + // In most cases, there will be one or zero 'Expect' header. + CharSequence value = message.headers().get(HttpHeaderNames.EXPECT); + if (value == null) { + return false; + } + if (HttpHeaderValues.CONTINUE.contentEqualsIgnoreCase(value)) { + return true; + } + + // Multiple 'Expect' headers. Search through them. + return message.headers().contains(HttpHeaderNames.EXPECT, HttpHeaderValues.CONTINUE, true); + } + + /** + * Sets or removes the {@code "Expect: 100-continue"} header to / from the + * specified message. If the specified {@code value} is {@code true}, + * the {@code "Expect: 100-continue"} header is set and all other previous + * {@code "Expect"} headers are removed. Otherwise, all {@code "Expect"} + * headers are removed completely. + */ + public static void set100ContinueExpected(HttpMessage message, boolean expected) { + if (expected) { + message.headers().set(HttpHeaderNames.EXPECT, HttpHeaderValues.CONTINUE); + } else { + message.headers().remove(HttpHeaderNames.EXPECT); + } + } + + /** + * Checks to see if the transfer encoding in a specified {@link HttpMessage} is chunked + * + * @param message The message to check + * @return True if transfer encoding is chunked, otherwise false + */ + public static boolean isTransferEncodingChunked(HttpMessage message) { + return message.headers().contains(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED, true); + } + + public static void setTransferEncodingChunked(HttpMessage m, boolean chunked) { + if (chunked) { + m.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED); + m.headers().remove(HttpHeaderNames.CONTENT_LENGTH); + } else { + List values = m.headers().getAll(HttpHeaderNames.TRANSFER_ENCODING); + if (values.isEmpty()) { + return; + } + Iterator valuesIt = values.iterator(); + while (valuesIt.hasNext()) { + CharSequence value = valuesIt.next(); + if (HttpHeaderValues.CHUNKED.contentEqualsIgnoreCase(value)) { + valuesIt.remove(); + } + } + if (values.isEmpty()) { + m.headers().remove(HttpHeaderNames.TRANSFER_ENCODING); + } else { + m.headers().set(HttpHeaderNames.TRANSFER_ENCODING, values); + } + } + } + + static void encodeAscii0(CharSequence seq, ByteBuf buf) { + int length = seq.length(); + for (int i = 0 ; i < length; i++) { + buf.writeByte(c2b(seq.charAt(i))); + } + } + + private static byte c2b(char c) { + return c > 255 ? (byte) '?' : (byte) c; + } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java index 6433c0ef85..e64283b55f 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java @@ -25,7 +25,7 @@ import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpConstants; import io.netty.handler.codec.http.HttpContent; import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpHeaderUtil; +import io.netty.handler.codec.http.HttpUtil; import io.netty.handler.codec.http.HttpHeaderValues; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpMethod; @@ -761,7 +761,7 @@ public class HttpPostRequestEncoder implements ChunkedInput { } } } - HttpHeaderUtil.setTransferEncodingChunked(request, true); + HttpUtil.setTransferEncodingChunked(request, true); // wrap to hide the possible content return new WrappedHttpRequest(request); diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactory.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactory.java index 3cb4e00054..9be036da07 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactory.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactory.java @@ -20,7 +20,7 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelPromise; import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpHeaderUtil; +import io.netty.handler.codec.http.HttpUtil; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; @@ -151,7 +151,7 @@ public class WebSocketServerHandshakerFactory { HttpVersion.HTTP_1_1, HttpResponseStatus.UPGRADE_REQUIRED); res.headers().set(HttpHeaderNames.SEC_WEBSOCKET_VERSION, WebSocketVersion.V13.toHttpHeaderValue()); - HttpHeaderUtil.setContentLength(res, 0); + HttpUtil.setContentLength(res, 0); return channel.writeAndFlush(res, promise); } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpDecoder.java index 0af0528681..6ec208d41c 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpDecoder.java @@ -25,7 +25,7 @@ import io.netty.handler.codec.http.FullHttpMessage; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpHeaderUtil; +import io.netty.handler.codec.http.HttpUtil; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpVersion; @@ -240,7 +240,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder { httpResponseWithEntity.headers().setInt(Names.STREAM_ID, streamId); if (spdySynReplyFrame.isLast()) { - HttpHeaderUtil.setContentLength(httpResponseWithEntity, 0); + HttpUtil.setContentLength(httpResponseWithEntity, 0); out.add(httpResponseWithEntity); } else { // Response body will follow in a series of Data Frames @@ -280,7 +280,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder { fullHttpMessage.headers().setInt(Names.STREAM_ID, streamId); if (spdyHeadersFrame.isLast()) { - HttpHeaderUtil.setContentLength(fullHttpMessage, 0); + HttpUtil.setContentLength(fullHttpMessage, 0); out.add(fullHttpMessage); } else { // Response body will follow in a series of Data Frames @@ -305,7 +305,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder { } if (spdyHeadersFrame.isLast()) { - HttpHeaderUtil.setContentLength(fullHttpMessage, fullHttpMessage.content().readableBytes()); + HttpUtil.setContentLength(fullHttpMessage, fullHttpMessage.content().readableBytes()); removeMessage(streamId); out.add(fullHttpMessage); } @@ -333,7 +333,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder { content.writeBytes(spdyDataFrameData, spdyDataFrameData.readerIndex(), spdyDataFrameDataLen); if (spdyDataFrame.isLast()) { - HttpHeaderUtil.setContentLength(fullHttpMessage, content.readableBytes()); + HttpUtil.setContentLength(fullHttpMessage, content.readableBytes()); removeMessage(streamId); out.add(fullHttpMessage); } @@ -372,7 +372,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder { } // The Connection and Keep-Alive headers are no longer valid - HttpHeaderUtil.setKeepAlive(req, true); + HttpUtil.setKeepAlive(req, true); // Transfer-Encoding header is not valid req.headers().remove(HttpHeaderNames.TRANSFER_ENCODING); @@ -396,7 +396,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder { } // The Connection and Keep-Alive headers are no longer valid - HttpHeaderUtil.setKeepAlive(res, true); + HttpUtil.setKeepAlive(res, true); // Transfer-Encoding header is not valid res.headers().remove(HttpHeaderNames.TRANSFER_ENCODING); diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/DefaultHttpHeadersTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/DefaultHttpHeadersTest.java index 754f56978b..df69f87cbf 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/DefaultHttpHeadersTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/DefaultHttpHeadersTest.java @@ -104,7 +104,7 @@ public class DefaultHttpHeadersTest { HttpMessage message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); message.headers().set(HttpHeaderNames.TRANSFER_ENCODING, "Chunked"); assertFalse(message.headers().isEmpty()); - HttpHeaderUtil.setTransferEncodingChunked(message, false); + HttpUtil.setTransferEncodingChunked(message, false); assertTrue(message.headers().isEmpty()); } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpHeadersTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpHeadersTest.java new file mode 100644 index 0000000000..63bdc925c4 --- /dev/null +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpHeadersTest.java @@ -0,0 +1,72 @@ +/* + * 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 io.netty.util.AsciiString; + +import org.junit.Test; + +import java.util.List; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +public class HttpHeadersTest { + + @Test + public void testRemoveTransferEncodingIgnoreCase() { + HttpMessage message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); + message.headers().set(HttpHeaderNames.TRANSFER_ENCODING, "Chunked"); + assertFalse(message.headers().isEmpty()); + HttpUtil.setTransferEncodingChunked(message, false); + assertTrue(message.headers().isEmpty()); + } + + // Test for https://github.com/netty/netty/issues/1690 + @Test + public void testGetOperations() { + HttpHeaders headers = new DefaultHttpHeaders(); + headers.add("Foo", "1"); + headers.add("Foo", "2"); + + assertEquals("1", headers.get("Foo")); + + List values = headers.getAll("Foo"); + assertEquals(2, values.size()); + assertEquals("1", values.get(0)); + assertEquals("2", values.get(1)); + } + + @Test + public void testEquansIgnoreCase() { + assertThat(AsciiString.contentEqualsIgnoreCase(null, null), is(true)); + assertThat(AsciiString.contentEqualsIgnoreCase(null, "foo"), is(false)); + assertThat(AsciiString.contentEqualsIgnoreCase("bar", null), is(false)); + assertThat(AsciiString.contentEqualsIgnoreCase("FoO", "fOo"), is(true)); + } + + @Test(expected = NullPointerException.class) + public void testSetNullHeaderValueValidate() { + HttpHeaders headers = new DefaultHttpHeaders(true); + headers.set("test", (CharSequence) null); + } + + @Test(expected = NullPointerException.class) + public void testSetNullHeaderValueNotValidate() { + HttpHeaders headers = new DefaultHttpHeaders(false); + headers.set("test", (CharSequence) null); + } +} diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpObjectAggregatorTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpObjectAggregatorTest.java index b229905fee..2ad3e7b897 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpObjectAggregatorTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpObjectAggregatorTest.java @@ -63,7 +63,7 @@ public class HttpObjectAggregatorTest { assertNotNull(aggratedMessage); assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(), - HttpHeaderUtil.getContentLength(aggratedMessage)); + HttpUtil.getContentLength(aggratedMessage)); assertEquals(aggratedMessage.headers().get("X-Test"), Boolean.TRUE.toString()); checkContentBuffer(aggratedMessage); assertNull(embedder.readInbound()); @@ -87,7 +87,7 @@ public class HttpObjectAggregatorTest { EmbeddedChannel embedder = new EmbeddedChannel(aggr); HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost"); message.headers().setBoolean("X-Test", true); - HttpHeaderUtil.setTransferEncodingChunked(message, true); + HttpUtil.setTransferEncodingChunked(message, true); HttpContent chunk1 = new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII)); HttpContent chunk2 = new DefaultHttpContent(Unpooled.copiedBuffer("test2", CharsetUtil.US_ASCII)); LastHttpContent trailer = new DefaultLastHttpContent(); @@ -104,7 +104,7 @@ public class HttpObjectAggregatorTest { assertNotNull(aggratedMessage); assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(), - HttpHeaderUtil.getContentLength(aggratedMessage)); + HttpUtil.getContentLength(aggratedMessage)); assertEquals(aggratedMessage.headers().get("X-Test"), Boolean.TRUE.toString()); assertEquals(aggratedMessage.trailingHeaders().get("X-Trailer"), Boolean.TRUE.toString()); checkContentBuffer(aggratedMessage); @@ -142,14 +142,14 @@ public class HttpObjectAggregatorTest { public void testOversizedRequestWithoutKeepAlive() { // send a HTTP/1.0 request with no keep-alive header HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.PUT, "http://localhost"); - HttpHeaderUtil.setContentLength(message, 5); + HttpUtil.setContentLength(message, 5); checkOversizedRequest(message); } @Test public void testOversizedRequestWithContentLength() { HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "http://localhost"); - HttpHeaderUtil.setContentLength(message, 5); + HttpUtil.setContentLength(message, 5); checkOversizedRequest(message); } @@ -172,10 +172,10 @@ public class HttpObjectAggregatorTest { private static boolean serverShouldCloseConnection(HttpRequest message) { // The connection should only be kept open if Expect: 100-continue is set, // or if keep-alive is on. - if (HttpHeaderUtil.is100ContinueExpected(message)) { + if (HttpUtil.is100ContinueExpected(message)) { return false; } - if (HttpHeaderUtil.isKeepAlive(message)) { + if (HttpUtil.isKeepAlive(message)) { return false; } return true; @@ -244,7 +244,7 @@ public class HttpObjectAggregatorTest { assertNotNull(aggratedMessage); assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(), - HttpHeaderUtil.getContentLength(aggratedMessage)); + HttpUtil.getContentLength(aggratedMessage)); assertEquals(aggratedMessage.headers().get("X-Test"), Boolean.TRUE.toString()); checkContentBuffer(aggratedMessage); assertNull(embedder.readInbound()); @@ -278,8 +278,8 @@ public class HttpObjectAggregatorTest { // Send an oversized request with 100 continue. HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "http://localhost"); - HttpHeaderUtil.set100ContinueExpected(message, true); - HttpHeaderUtil.setContentLength(message, 16); + HttpUtil.set100ContinueExpected(message, true); + HttpUtil.setContentLength(message, 16); HttpContent chunk1 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("some", CharsetUtil.US_ASCII))); HttpContent chunk2 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII))); @@ -311,9 +311,9 @@ public class HttpObjectAggregatorTest { assertEquals( chunk2.content().readableBytes() + chunk3.content().readableBytes(), - HttpHeaderUtil.getContentLength(fullMsg)); + HttpUtil.getContentLength(fullMsg)); - assertEquals(HttpHeaderUtil.getContentLength(fullMsg), fullMsg.content().readableBytes()); + assertEquals(HttpUtil.getContentLength(fullMsg), fullMsg.content().readableBytes()); fullMsg.release(); assertFalse(embedder.finish()); @@ -373,8 +373,8 @@ public class HttpObjectAggregatorTest { // Write first request with Expect: 100-continue. HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "http://localhost"); - HttpHeaderUtil.set100ContinueExpected(message, true); - HttpHeaderUtil.setContentLength(message, 16); + HttpUtil.set100ContinueExpected(message, true); + HttpUtil.setContentLength(message, 16); HttpContent chunk1 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("some", CharsetUtil.US_ASCII))); HttpContent chunk2 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII))); @@ -406,9 +406,9 @@ public class HttpObjectAggregatorTest { assertEquals( chunk2.content().readableBytes() + chunk3.content().readableBytes(), - HttpHeaderUtil.getContentLength(fullMsg)); + HttpUtil.getContentLength(fullMsg)); - assertEquals(HttpHeaderUtil.getContentLength(fullMsg), fullMsg.content().readableBytes()); + assertEquals(HttpUtil.getContentLength(fullMsg), fullMsg.content().readableBytes()); fullMsg.release(); assertFalse(embedder.finish()); diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpHeaderUtilTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpUtilTest.java similarity index 95% rename from codec-http/src/test/java/io/netty/handler/codec/http/HttpHeaderUtilTest.java rename to codec-http/src/test/java/io/netty/handler/codec/http/HttpUtilTest.java index ca393f2e8d..9b70660b69 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpHeaderUtilTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpUtilTest.java @@ -24,14 +24,14 @@ import java.util.List; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; -public class HttpHeaderUtilTest { +public class HttpUtilTest { @Test public void testRemoveTransferEncodingIgnoreCase() { HttpMessage message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); message.headers().set(HttpHeaderNames.TRANSFER_ENCODING, "Chunked"); assertFalse(message.headers().isEmpty()); - HttpHeaderUtil.setTransferEncodingChunked(message, false); + HttpUtil.setTransferEncodingChunked(message, false); assertTrue(message.headers().isEmpty()); } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactoryTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactoryTest.java index 5ea9bac704..787400bba3 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactoryTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactoryTest.java @@ -19,7 +19,7 @@ package io.netty.handler.codec.http.websocketx; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpHeaderUtil; +import io.netty.handler.codec.http.HttpUtil; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.util.ReferenceCountUtil; import org.junit.Test; @@ -43,8 +43,8 @@ public class WebSocketServerHandshakerFactoryTest { assertEquals(HttpResponseStatus.UPGRADE_REQUIRED, response.status()); assertEquals(WebSocketVersion.V13.toHttpHeaderValue(), response.headers().get(HttpHeaderNames.SEC_WEBSOCKET_VERSION)); - assertTrue(HttpHeaderUtil.isContentLengthSet(response)); - assertEquals(0, HttpHeaderUtil.getContentLength(response)); + assertTrue(HttpUtil.isContentLengthSet(response)); + assertEquals(0, HttpUtil.getContentLength(response)); ReferenceCountUtil.release(response); assertFalse(ch.finish()); diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/HttpUtil.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/HttpConversionUtil.java similarity index 99% rename from codec-http2/src/main/java/io/netty/handler/codec/http2/HttpUtil.java rename to codec-http2/src/main/java/io/netty/handler/codec/http2/HttpConversionUtil.java index a39716cf15..59c1025d19 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/HttpUtil.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/HttpConversionUtil.java @@ -20,7 +20,7 @@ import io.netty.handler.codec.http.FullHttpMessage; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpHeaderUtil; +import io.netty.handler.codec.http.HttpUtil; import io.netty.handler.codec.http.HttpHeaderValues; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpMessage; @@ -53,7 +53,7 @@ import static io.netty.util.internal.StringUtil.length; /** * Provides utility methods and constants for the HTTP/2 to HTTP conversion */ -public final class HttpUtil { +public final class HttpConversionUtil { /** * The set of headers that should not be directly copied when converting headers from HTTP to HTTP/2. */ @@ -98,7 +98,7 @@ public final class HttpUtil { */ private static final AsciiString EMPTY_REQUEST_PATH = new AsciiString("/"); - private HttpUtil() { + private HttpConversionUtil() { } /** @@ -265,7 +265,7 @@ public final class HttpUtil { headers.remove(HttpHeaderNames.TRAILER); if (!addToTrailer) { headers.setInt(ExtensionHeaderNames.STREAM_ID.text(), streamId); - HttpHeaderUtil.setKeepAlive(destinationMessage, true); + HttpUtil.setKeepAlive(destinationMessage, true); } } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandler.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandler.java index 6bb45045dc..8f5da2f129 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandler.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandler.java @@ -61,7 +61,8 @@ public class HttpToHttp2ConnectionHandler extends Http2ConnectionHandler { * @throws Exception If the {@code httpHeaders} object specifies an invalid stream id */ private int getStreamId(HttpHeaders httpHeaders) throws Exception { - return httpHeaders.getInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), connection().local().nextStreamId()); + return httpHeaders.getInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), + connection().local().nextStreamId()); } /** @@ -88,7 +89,7 @@ public class HttpToHttp2ConnectionHandler extends Http2ConnectionHandler { currentStreamId = getStreamId(httpMsg.headers()); // Convert and write the headers. - Http2Headers http2Headers = HttpUtil.toHttp2Headers(httpMsg); + Http2Headers http2Headers = HttpConversionUtil.toHttp2Headers(httpMsg); endStream = msg instanceof FullHttpMessage && !((FullHttpMessage) msg).content().isReadable(); encoder.writeHeaders(ctx, currentStreamId, http2Headers, 0, endStream, promiseAggregator.newPromise()); } @@ -101,7 +102,7 @@ public class HttpToHttp2ConnectionHandler extends Http2ConnectionHandler { // Convert any trailing headers. final LastHttpContent lastContent = (LastHttpContent) msg; - trailers = HttpUtil.toHttp2Headers(lastContent.trailingHeaders()); + trailers = HttpConversionUtil.toHttp2Headers(lastContent.trailingHeaders()); } // Write the data diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapter.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapter.java index 2daef7d178..8c22cb70d1 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapter.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapter.java @@ -25,7 +25,7 @@ import io.netty.handler.codec.http.FullHttpMessage; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpHeaderUtil; +import io.netty.handler.codec.http.HttpUtil; import io.netty.handler.codec.http.HttpStatusClass; import io.netty.util.collection.IntObjectHashMap; import io.netty.util.collection.IntObjectMap; @@ -168,7 +168,7 @@ public class InboundHttp2ToHttpAdapter extends Http2EventAdapter { */ protected void fireChannelRead(ChannelHandlerContext ctx, FullHttpMessage msg, int streamId) { removeMessage(streamId); - HttpHeaderUtil.setContentLength(msg, msg.content().readableBytes()); + HttpUtil.setContentLength(msg, msg.content().readableBytes()); ctx.fireChannelRead(msg); } @@ -186,8 +186,8 @@ public class InboundHttp2ToHttpAdapter extends Http2EventAdapter { */ protected FullHttpMessage newMessage(int streamId, Http2Headers headers, boolean validateHttpHeaders) throws Http2Exception { - return connection.isServer() ? HttpUtil.toHttpRequest(streamId, headers, - validateHttpHeaders) : HttpUtil.toHttpResponse(streamId, headers, validateHttpHeaders); + return connection.isServer() ? HttpConversionUtil.toHttpRequest(streamId, headers, + validateHttpHeaders) : HttpConversionUtil.toHttpResponse(streamId, headers, validateHttpHeaders); } /** @@ -221,7 +221,7 @@ public class InboundHttp2ToHttpAdapter extends Http2EventAdapter { msg = newMessage(streamId, headers, validateHttpHeaders); } else if (allowAppend) { try { - HttpUtil.addHttp2ToHttpHeaders(streamId, headers, msg, appendToTrailer); + HttpConversionUtil.addHttp2ToHttpHeaders(streamId, headers, msg, appendToTrailer); } catch (Http2Exception e) { removeMessage(streamId); throw e; @@ -320,7 +320,7 @@ public class InboundHttp2ToHttpAdapter extends Http2EventAdapter { promisedStreamId); } - msg.headers().setInt(HttpUtil.ExtensionHeaderNames.STREAM_PROMISE_ID.text(), streamId); + msg.headers().setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_PROMISE_ID.text(), streamId); processHeadersEnd(ctx, promisedStreamId, msg, false); } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpPriorityAdapter.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpPriorityAdapter.java index a3963d068d..87ba14e378 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpPriorityAdapter.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpPriorityAdapter.java @@ -35,11 +35,11 @@ import static io.netty.handler.codec.http2.Http2Exception.connectionError; */ public final class InboundHttp2ToHttpPriorityAdapter extends InboundHttp2ToHttpAdapter { private static final AsciiString OUT_OF_MESSAGE_SEQUENCE_METHOD = new AsciiString( - HttpUtil.OUT_OF_MESSAGE_SEQUENCE_METHOD.toString()); + HttpConversionUtil.OUT_OF_MESSAGE_SEQUENCE_METHOD.toString()); private static final AsciiString OUT_OF_MESSAGE_SEQUENCE_PATH = new AsciiString( - HttpUtil.OUT_OF_MESSAGE_SEQUENCE_PATH); + HttpConversionUtil.OUT_OF_MESSAGE_SEQUENCE_PATH); private static final AsciiString OUT_OF_MESSAGE_SEQUENCE_RETURN_CODE = new AsciiString( - HttpUtil.OUT_OF_MESSAGE_SEQUENCE_RETURN_CODE.toString()); + HttpConversionUtil.OUT_OF_MESSAGE_SEQUENCE_RETURN_CODE.toString()); private final IntObjectMap outOfMessageFlowHeaders; public static final class Builder extends InboundHttp2ToHttpAdapter.Builder { @@ -112,8 +112,8 @@ public final class InboundHttp2ToHttpPriorityAdapter extends InboundHttp2ToHttpA * @param headers The headers to remove the priority tree elements from */ private static void removePriorityRelatedHeaders(HttpHeaders headers) { - headers.remove(HttpUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text()); - headers.remove(HttpUtil.ExtensionHeaderNames.STREAM_WEIGHT.text()); + headers.remove(HttpConversionUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text()); + headers.remove(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text()); } /** @@ -166,7 +166,7 @@ public final class InboundHttp2ToHttpPriorityAdapter extends InboundHttp2ToHttpA // and the HTTP message flow exists in OPEN. if (parent != null && !parent.equals(connection.connectionStream())) { HttpHeaders headers = new DefaultHttpHeaders(); - headers.setInt(HttpUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text(), parent.id()); + headers.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text(), parent.id()); importOutOfMessageFlowHeaders(stream.id(), headers); } } else { @@ -175,7 +175,7 @@ public final class InboundHttp2ToHttpPriorityAdapter extends InboundHttp2ToHttpA removePriorityRelatedHeaders(msg.trailingHeaders()); } else if (!parent.equals(connection.connectionStream())) { HttpHeaders headers = getActiveHeaders(msg); - headers.setInt(HttpUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text(), parent.id()); + headers.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text(), parent.id()); } } } @@ -193,7 +193,7 @@ public final class InboundHttp2ToHttpPriorityAdapter extends InboundHttp2ToHttpA } else { headers = getActiveHeaders(msg); } - headers.setShort(HttpUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), stream.weight()); + headers.setShort(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), stream.weight()); } @Override diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandlerTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandlerTest.java index 88e8b3a8d3..0377788887 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandlerTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandlerTest.java @@ -123,11 +123,10 @@ public class HttpToHttp2ConnectionHandlerTest { final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "http://my-user_name@www.example.org:5555/example"); final HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); - httpHeaders.set(HttpHeaderNames.HOST, - "my-user_name@www.example.org:5555"); - httpHeaders.set(HttpUtil.ExtensionHeaderNames.AUTHORITY.text(), "www.example.org:5555"); - httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "http"); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); + httpHeaders.set(HttpHeaderNames.HOST, "my-user_name@www.example.org:5555"); + httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.AUTHORITY.text(), "www.example.org:5555"); + httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "http"); httpHeaders.add("foo", "goo"); httpHeaders.add("foo", "goo2"); httpHeaders.add("foo2", "goo2"); @@ -147,8 +146,8 @@ public class HttpToHttp2ConnectionHandlerTest { bootstrapEnv(2, 1, 0); final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/where?q=now&f=then#section1"); final HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); - httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "http"); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); + httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "http"); final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")) .path(new AsciiString("/where?q=now&f=then#section1")) @@ -163,12 +162,11 @@ public class HttpToHttp2ConnectionHandlerTest { bootstrapEnv(2, 1, 0); final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/pub/WWW/TheProject.html"); final HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); - httpHeaders.set(HttpHeaderNames.HOST, - "foouser@www.example.org:5555"); - httpHeaders.set(HttpUtil.ExtensionHeaderNames.PATH.text(), "ignored_path"); - httpHeaders.set(HttpUtil.ExtensionHeaderNames.AUTHORITY.text(), "ignored_authority"); - httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "https"); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); + httpHeaders.set(HttpHeaderNames.HOST, "foouser@www.example.org:5555"); + httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.PATH.text(), "ignored_path"); + httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.AUTHORITY.text(), "ignored_authority"); + httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "https"); final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")) .path(new AsciiString("/pub/WWW/TheProject.html")) @@ -183,10 +181,10 @@ public class HttpToHttp2ConnectionHandlerTest { bootstrapEnv(2, 1, 0); final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/pub/WWW/TheProject.html"); final HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); - httpHeaders.set(HttpUtil.ExtensionHeaderNames.PATH.text(), "ignored_path"); - httpHeaders.set(HttpUtil.ExtensionHeaderNames.AUTHORITY.text(), "www.example.org:5555"); - httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "https"); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); + httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.PATH.text(), "ignored_path"); + httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.AUTHORITY.text(), "www.example.org:5555"); + httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "https"); final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")) .path(new AsciiString("/pub/WWW/TheProject.html")) @@ -202,7 +200,7 @@ public class HttpToHttp2ConnectionHandlerTest { final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "http://foouser@www.example.org:5555/pub/WWW/TheProject.html"); final HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")) .path(new AsciiString("/pub/WWW/TheProject.html")) @@ -217,7 +215,7 @@ public class HttpToHttp2ConnectionHandlerTest { bootstrapEnv(2, 1, 0); final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, CONNECT, "http://www.example.com:80"); final HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("CONNECT")).path(new AsciiString("/")) .scheme(new AsciiString("http")).authority(new AsciiString("www.example.com:80")); @@ -231,9 +229,9 @@ public class HttpToHttp2ConnectionHandlerTest { bootstrapEnv(2, 1, 0); final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, OPTIONS, "*"); final HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); httpHeaders.set(HttpHeaderNames.HOST, "www.example.com:80"); - httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "http"); + httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "http"); final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("OPTIONS")).path(new AsciiString("*")) .scheme(new AsciiString("http")).authority(new AsciiString("www.example.com:80")); @@ -249,9 +247,9 @@ public class HttpToHttp2ConnectionHandlerTest { bootstrapEnv(2, 1, 0); final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/"); final HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); httpHeaders.set(HttpHeaderNames.HOST, "[::1]:80"); - httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "http"); + httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "http"); final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path(new AsciiString("/")) .scheme(new AsciiString("http")).authority(new AsciiString("[::1]:80")); @@ -265,9 +263,9 @@ public class HttpToHttp2ConnectionHandlerTest { bootstrapEnv(2, 1, 0); final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/"); final HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); httpHeaders.set(HttpHeaderNames.HOST, "localhost:80"); - httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "http"); + httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "http"); final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path(new AsciiString("/")) .scheme(new AsciiString("http")).authority(new AsciiString("localhost:80")); @@ -281,9 +279,9 @@ public class HttpToHttp2ConnectionHandlerTest { bootstrapEnv(2, 1, 0); final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/"); final HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); httpHeaders.set(HttpHeaderNames.HOST, "1.2.3.4:80"); - httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "http"); + httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "http"); final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path(new AsciiString("/")) .scheme(new AsciiString("http")).authority(new AsciiString("1.2.3.4:80")); @@ -297,7 +295,7 @@ public class HttpToHttp2ConnectionHandlerTest { bootstrapEnv(2, 1, 0); final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/"); final HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); httpHeaders.set(HttpHeaderNames.HOST, "localhost"); ChannelPromise writePromise = newPromise(); ChannelFuture writeFuture = clientChannel.writeAndFlush(request, writePromise); diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapterTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapterTest.java index 99e0f8d8e7..cd1af75265 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapterTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapterTest.java @@ -208,9 +208,9 @@ public class InboundHttp2ToHttpAdapterTest { "/some/path/resource2", true); try { HttpHeaders httpHeaders = request.headers(); - httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "https"); - httpHeaders.set(HttpUtil.ExtensionHeaderNames.AUTHORITY.text(), "example.org"); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); + httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "https"); + httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.AUTHORITY.text(), "example.org"); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0); final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")). scheme(new AsciiString("https")).authority(new AsciiString("example.org")) @@ -260,7 +260,7 @@ public class InboundHttp2ToHttpAdapterTest { "/some/path/resource2", content, true); try { HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length()); final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path( new AsciiString("/some/path/resource2")); @@ -290,7 +290,7 @@ public class InboundHttp2ToHttpAdapterTest { "/some/path/resource2", content, true); try { HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length()); final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path( new AsciiString("/some/path/resource2")); @@ -324,7 +324,7 @@ public class InboundHttp2ToHttpAdapterTest { "/some/path/resource2", content, true); try { HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length()); final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path( new AsciiString("/some/path/resource2")); @@ -358,7 +358,7 @@ public class InboundHttp2ToHttpAdapterTest { "/some/path/resource2", content, true); try { HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length()); HttpHeaders trailingHeaders = request.trailingHeaders(); trailingHeaders.set("FoO", "goo"); @@ -397,7 +397,7 @@ public class InboundHttp2ToHttpAdapterTest { "/some/path/resource2", content, true); try { HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length()); HttpHeaders trailingHeaders = request.trailingHeaders(); trailingHeaders.set("Foo", "goo"); @@ -441,12 +441,12 @@ public class InboundHttp2ToHttpAdapterTest { "/some/path/resource2", content2, true); try { HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length()); HttpHeaders httpHeaders2 = request2.headers(); - httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); - httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text(), 3); - httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), 123); + httpHeaders2.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); + httpHeaders2.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text(), 3); + httpHeaders2.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), 123); httpHeaders2.setInt(HttpHeaderNames.CONTENT_LENGTH, text2.length()); final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("PUT")).path( new AsciiString("/some/path/resource")); @@ -487,22 +487,23 @@ public class InboundHttp2ToHttpAdapterTest { final FullHttpMessage request2 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "/some/path/resource2", content2, true); final FullHttpMessage request3 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, - HttpUtil.OUT_OF_MESSAGE_SEQUENCE_METHOD, HttpUtil.OUT_OF_MESSAGE_SEQUENCE_PATH, true); + HttpConversionUtil.OUT_OF_MESSAGE_SEQUENCE_METHOD, + HttpConversionUtil.OUT_OF_MESSAGE_SEQUENCE_PATH, true); try { HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length()); HttpHeaders httpHeaders2 = request2.headers(); - httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); + httpHeaders2.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); httpHeaders2.setInt(HttpHeaderNames.CONTENT_LENGTH, text2.length()); final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("PUT")).path( new AsciiString("/some/path/resource")); final Http2Headers http2Headers2 = new DefaultHttp2Headers().method(new AsciiString("PUT")).path( new AsciiString("/some/path/resource2")); HttpHeaders httpHeaders3 = request3.headers(); - httpHeaders3.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); - httpHeaders3.setInt(HttpUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text(), 3); - httpHeaders3.setInt(HttpUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), 222); + httpHeaders3.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); + httpHeaders3.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text(), 3); + httpHeaders3.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), 222); httpHeaders3.setInt(HttpHeaderNames.CONTENT_LENGTH, 0); runInChannel(clientChannel, new Http2Runnable() { @Override @@ -544,17 +545,17 @@ public class InboundHttp2ToHttpAdapterTest { true); try { HttpHeaders httpHeaders = response.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length()); HttpHeaders httpHeaders2 = response2.headers(); - httpHeaders2.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "https"); - httpHeaders2.set(HttpUtil.ExtensionHeaderNames.AUTHORITY.text(), "example.org"); - httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); - httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_PROMISE_ID.text(), 3); + httpHeaders2.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "https"); + httpHeaders2.set(HttpConversionUtil.ExtensionHeaderNames.AUTHORITY.text(), "example.org"); + httpHeaders2.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5); + httpHeaders2.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_PROMISE_ID.text(), 3); httpHeaders2.setInt(HttpHeaderNames.CONTENT_LENGTH, text2.length()); httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0); final Http2Headers http2Headers3 = new DefaultHttp2Headers().method(new AsciiString("GET")) .path(new AsciiString("/push/test")); @@ -603,7 +604,7 @@ public class InboundHttp2ToHttpAdapterTest { final FullHttpMessage request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "/info/test", true); HttpHeaders httpHeaders = request.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); httpHeaders.set(HttpHeaderNames.EXPECT, HttpHeaderValues.CONTINUE); httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0); final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("PUT")) @@ -633,7 +634,7 @@ public class InboundHttp2ToHttpAdapterTest { reset(serverListener); httpHeaders = response.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0); final Http2Headers http2HeadersResponse = new DefaultHttp2Headers().status(new AsciiString("100")); runInChannel(serverConnectedChannel, new Http2Runnable() { @@ -670,7 +671,7 @@ public class InboundHttp2ToHttpAdapterTest { setClientLatch(1); httpHeaders = response2.headers(); - httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); + httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3); httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0); final Http2Headers http2HeadersResponse2 = new DefaultHttp2Headers().status(new AsciiString("200")); runInChannel(serverConnectedChannel, new Http2Runnable() { diff --git a/example/src/main/java/io/netty/example/http/file/HttpStaticFileServerHandler.java b/example/src/main/java/io/netty/example/http/file/HttpStaticFileServerHandler.java index 9ae3059ee8..242e3fb431 100644 --- a/example/src/main/java/io/netty/example/http/file/HttpStaticFileServerHandler.java +++ b/example/src/main/java/io/netty/example/http/file/HttpStaticFileServerHandler.java @@ -29,7 +29,7 @@ import io.netty.handler.codec.http.DefaultHttpResponse; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpChunkedInput; -import io.netty.handler.codec.http.HttpHeaderUtil; +import io.netty.handler.codec.http.HttpUtil; import io.netty.handler.codec.http.HttpHeaderValues; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; @@ -175,10 +175,10 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler if (msg instanceof HttpRequest) { HttpRequest request = this.request = (HttpRequest) msg; - if (HttpHeaderUtil.is100ContinueExpected(request)) { + if (HttpUtil.is100ContinueExpected(request)) { send100Continue(ctx); } @@ -146,7 +146,7 @@ public class HttpSnoopServerHandler extends SimpleChannelInboundHandler private boolean writeResponse(HttpObject currentObj, ChannelHandlerContext ctx) { // Decide whether to close the connection or not. - boolean keepAlive = HttpHeaderUtil.isKeepAlive(request); + boolean keepAlive = HttpUtil.isKeepAlive(request); // Build the response object. FullHttpResponse response = new DefaultFullHttpResponse( HTTP_1_1, currentObj.decoderResult().isSuccess()? OK : BAD_REQUEST, diff --git a/example/src/main/java/io/netty/example/http/upload/HttpUploadClientHandler.java b/example/src/main/java/io/netty/example/http/upload/HttpUploadClientHandler.java index 2ac9b0a857..4a3b87aec1 100644 --- a/example/src/main/java/io/netty/example/http/upload/HttpUploadClientHandler.java +++ b/example/src/main/java/io/netty/example/http/upload/HttpUploadClientHandler.java @@ -18,7 +18,7 @@ package io.netty.example.http.upload; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.http.HttpContent; -import io.netty.handler.codec.http.HttpHeaderUtil; +import io.netty.handler.codec.http.HttpUtil; import io.netty.handler.codec.http.HttpObject; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.LastHttpContent; @@ -47,7 +47,7 @@ public class HttpUploadClientHandler extends SimpleChannelInboundHandler FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, OK, content); res.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8"); - HttpHeaderUtil.setContentLength(res, content.readableBytes()); + HttpUtil.setContentLength(res, content.readableBytes()); sendHttpResponse(ctx, req, res); return; @@ -134,12 +134,12 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler ByteBuf buf = Unpooled.copiedBuffer(res.status().toString(), CharsetUtil.UTF_8); res.content().writeBytes(buf); buf.release(); - HttpHeaderUtil.setContentLength(res, res.content().readableBytes()); + HttpUtil.setContentLength(res, res.content().readableBytes()); } // Send the response and close the connection if necessary. ChannelFuture f = ctx.channel().writeAndFlush(res); - if (!HttpHeaderUtil.isKeepAlive(req) || res.status().code() != 200) { + if (!HttpUtil.isKeepAlive(req) || res.status().code() != 200) { f.addListener(ChannelFutureListener.CLOSE); } } diff --git a/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServerHandler.java b/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServerHandler.java index ec9f94a392..b655141e2e 100644 --- a/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServerHandler.java +++ b/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServerHandler.java @@ -24,7 +24,7 @@ import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.FullHttpResponse; -import io.netty.handler.codec.http.HttpHeaderUtil; +import io.netty.handler.codec.http.HttpUtil; import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; import io.netty.handler.codec.http.websocketx.PingWebSocketFrame; import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; @@ -81,7 +81,7 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, OK, content); res.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8"); - HttpHeaderUtil.setContentLength(res, content.readableBytes()); + HttpUtil.setContentLength(res, content.readableBytes()); sendHttpResponse(ctx, req, res); return; @@ -132,12 +132,12 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler ByteBuf buf = Unpooled.copiedBuffer(res.status().toString(), CharsetUtil.UTF_8); res.content().writeBytes(buf); buf.release(); - HttpHeaderUtil.setContentLength(res, res.content().readableBytes()); + HttpUtil.setContentLength(res, res.content().readableBytes()); } // Send the response and close the connection if necessary. ChannelFuture f = ctx.channel().writeAndFlush(res); - if (!HttpHeaderUtil.isKeepAlive(req) || res.status().code() != 200) { + if (!HttpUtil.isKeepAlive(req) || res.status().code() != 200) { f.addListener(ChannelFutureListener.CLOSE); } } diff --git a/example/src/main/java/io/netty/example/http2/helloworld/client/HttpResponseHandler.java b/example/src/main/java/io/netty/example/http2/helloworld/client/HttpResponseHandler.java index 617e131bd3..f8cd4786b8 100644 --- a/example/src/main/java/io/netty/example/http2/helloworld/client/HttpResponseHandler.java +++ b/example/src/main/java/io/netty/example/http2/helloworld/client/HttpResponseHandler.java @@ -19,7 +19,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPromise; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.http.FullHttpResponse; -import io.netty.handler.codec.http2.HttpUtil; +import io.netty.handler.codec.http2.HttpConversionUtil; import io.netty.util.CharsetUtil; import java.util.Iterator; @@ -76,7 +76,7 @@ public class HttpResponseHandler extends SimpleChannelInboundHandler