diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaderUtil.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaderUtil.java
deleted file mode 100644
index 52b246dc1c..0000000000
--- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaderUtil.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * Copyright 2014 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.buffer.ByteBuf;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-public final class HttpHeaderUtil {
-
- /**
- * 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()}.
- *
- *
If the connection is kept alive by default:
- *
- *
set to {@code "close"} if {@code keepAlive} is {@code false}.
- *
remove otherwise.
- *
- *
If the connection is closed by default:
- *
- *
set to {@code "keep-alive"} if {@code keepAlive} is {@code true}.
- *
remove otherwise.
- *
- *
- */
- 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) {
- String value = message.headers().get(HttpHeaderNames.CONTENT_LENGTH);
- if (value != null) {
- return Long.parseLong(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) {
- String value = message.headers().get(HttpHeaderNames.CONTENT_LENGTH);
- if (value != null) {
- return Long.parseLong(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().set(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 encodings = m.headers().getAll(HttpHeaderNames.TRANSFER_ENCODING);
- if (encodings.isEmpty()) {
- return;
- }
- List values = new ArrayList(encodings);
- 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) {
- if (c > 255) {
- return '?';
- }
- return (byte) c;
- }
-
- private HttpHeaderUtil() { }
-}
diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaders.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaders.java
index 6a7057bd26..96951a490f 100644
--- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaders.java
+++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaders.java
@@ -488,7 +488,7 @@ public abstract class HttpHeaders implements Iterable>
}
/**
- * @deprecated Use {@link HttpHeaderUtil#isKeepAlive(HttpMessage)} instead.
+ * @deprecated Use {@link HttpUtil#isKeepAlive(HttpMessage)} instead.
*
* Returns {@code true} if and only if the connection can remain open and
* thus 'kept alive'. This methods respects the value of the
@@ -497,11 +497,11 @@ public abstract class HttpHeaders implements Iterable>
*/
@Deprecated
public static boolean isKeepAlive(HttpMessage message) {
- return HttpHeaderUtil.isKeepAlive(message);
+ return HttpUtil.isKeepAlive(message);
}
/**
- * @deprecated Use {@link HttpHeaderUtil#setKeepAlive(HttpMessage, boolean)} instead.
+ * @deprecated Use {@link HttpUtil#setKeepAlive(HttpMessage, boolean)} instead.
*
* Sets the value of the {@code "Connection"} header depending on the
* protocol version of the specified message. This getMethod sets or removes
@@ -523,7 +523,7 @@ public abstract class HttpHeaders implements Iterable>
*/
@Deprecated
public static void setKeepAlive(HttpMessage message, boolean keepAlive) {
- HttpHeaderUtil.setKeepAlive(message, keepAlive);
+ HttpUtil.setKeepAlive(message, keepAlive);
}
/**
@@ -939,7 +939,7 @@ public abstract class HttpHeaders implements Iterable>
}
/**
- * @deprecated Use {@link HttpHeaderUtil#getContentLength(HttpMessage)} instead.
+ * @deprecated Use {@link HttpUtil#getContentLength(HttpMessage)} instead.
*
* Returns the length of the content. Please note that this value is
* not retrieved from {@link HttpContent#content()} but from the
@@ -954,11 +954,11 @@ public abstract class HttpHeaders implements Iterable>
*/
@Deprecated
public static long getContentLength(HttpMessage message) {
- return HttpHeaderUtil.getContentLength(message);
+ return HttpUtil.getContentLength(message);
}
/**
- * @deprecated Use {@link HttpHeaderUtil#getContentLength(HttpMessage, long)} instead.
+ * @deprecated Use {@link HttpUtil#getContentLength(HttpMessage, long)} instead.
*
* Returns the length of the content. Please note that this value is
* not retrieved from {@link HttpContent#content()} but from the
@@ -971,15 +971,15 @@ public abstract class HttpHeaders implements Iterable>
*/
@Deprecated
public static long getContentLength(HttpMessage message, long defaultValue) {
- return HttpHeaderUtil.getContentLength(message, defaultValue);
+ return HttpUtil.getContentLength(message, defaultValue);
}
/**
- * @deprecated Use {@link HttpHeaderUtil#setContentLength(HttpMessage, long)} instead.
+ * @deprecated Use {@link HttpUtil#setContentLength(HttpMessage, long)} instead.
*/
@Deprecated
public static void setContentLength(HttpMessage message, long length) {
- HttpHeaderUtil.setContentLength(message, length);
+ HttpUtil.setContentLength(message, length);
}
/**
@@ -1059,18 +1059,18 @@ public abstract class HttpHeaders implements Iterable>
}
/**
- * @deprecated Use {@link HttpHeaderUtil#is100ContinueExpected(HttpMessage)} instead.
+ * @deprecated Use {@link HttpUtil#is100ContinueExpected(HttpMessage)} instead.
*
* Returns {@code true} if and only if the specified message contains the
* {@code "Expect: 100-continue"} header.
*/
@Deprecated
public static boolean is100ContinueExpected(HttpMessage message) {
- return HttpHeaderUtil.is100ContinueExpected(message);
+ return HttpUtil.is100ContinueExpected(message);
}
/**
- * @deprecated Use {@link HttpHeaderUtil#set100ContinueExpected(HttpMessage, boolean)} instead.
+ * @deprecated Use {@link HttpUtil#set100ContinueExpected(HttpMessage, boolean)} instead.
*
* Sets the {@code "Expect: 100-continue"} header to the specified message.
* If there is any existing {@code "Expect"} header, they are replaced with
@@ -1078,11 +1078,11 @@ public abstract class HttpHeaders implements Iterable>
*/
@Deprecated
public static void set100ContinueExpected(HttpMessage message) {
- HttpHeaderUtil.set100ContinueExpected(message, true);
+ HttpUtil.set100ContinueExpected(message, true);
}
/**
- * @deprecated Use {@link HttpHeaderUtil#set100ContinueExpected(HttpMessage, boolean)} instead.
+ * @deprecated Use {@link HttpUtil#set100ContinueExpected(HttpMessage, boolean)} instead.
*
* Sets or removes the {@code "Expect: 100-continue"} header to / from the
* specified message. If the specified {@code value} is {@code true},
@@ -1092,11 +1092,11 @@ public abstract class HttpHeaders implements Iterable>
*/
@Deprecated
public static void set100ContinueExpected(HttpMessage message, boolean set) {
- HttpHeaderUtil.set100ContinueExpected(message, set);
+ HttpUtil.set100ContinueExpected(message, set);
}
/**
- * @deprecated Use {@link HttpHeaderUtil#isTransferEncodingChunked(HttpMessage)} instead.
+ * @deprecated Use {@link HttpUtil#isTransferEncodingChunked(HttpMessage)} instead.
*
* Checks to see if the transfer encoding in a specified {@link HttpMessage} is chunked
*
@@ -1105,31 +1105,31 @@ public abstract class HttpHeaders implements Iterable>
*/
@Deprecated
public static boolean isTransferEncodingChunked(HttpMessage message) {
- return HttpHeaderUtil.isTransferEncodingChunked(message);
+ return HttpUtil.isTransferEncodingChunked(message);
}
/**
- * @deprecated Use {@link HttpHeaderUtil#setTransferEncodingChunked(HttpMessage, boolean)} instead.
+ * @deprecated Use {@link HttpUtil#setTransferEncodingChunked(HttpMessage, boolean)} instead.
*/
@Deprecated
public static void removeTransferEncodingChunked(HttpMessage m) {
- HttpHeaderUtil.setTransferEncodingChunked(m, false);
+ HttpUtil.setTransferEncodingChunked(m, false);
}
/**
- * @deprecated Use {@link HttpHeaderUtil#setTransferEncodingChunked(HttpMessage, boolean)} instead.
+ * @deprecated Use {@link HttpUtil#setTransferEncodingChunked(HttpMessage, boolean)} instead.
*/
@Deprecated
public static void setTransferEncodingChunked(HttpMessage m) {
- HttpHeaderUtil.setTransferEncodingChunked(m, true);
+ HttpUtil.setTransferEncodingChunked(m, true);
}
/**
- * @deprecated Use {@link HttpHeaderUtil#isContentLengthSet(HttpMessage)} instead.
+ * @deprecated Use {@link HttpUtil#isContentLengthSet(HttpMessage)} instead.
*/
@Deprecated
public static boolean isContentLengthSet(HttpMessage m) {
- return HttpHeaderUtil.isContentLengthSet(m);
+ return HttpUtil.isContentLengthSet(m);
}
/**
@@ -1153,14 +1153,7 @@ public abstract class HttpHeaders implements Iterable>
if (seq instanceof AsciiString) {
ByteBufUtil.copy((AsciiString) seq, 0, buf, seq.length());
} else {
- encodeAscii0(seq, buf);
- }
- }
-
- static void encodeAscii0(CharSequence seq, ByteBuf buf) {
- int length = seq.length();
- for (int i = 0 ; i < length; i++) {
- buf.writeByte((byte) seq.charAt(i));
+ HttpUtil.encodeAscii0(seq, buf);
}
}
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 d73bc08963..ec72fda2fe 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 4b7248b1da..8136ba7b94 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 7a419e2f66..c3e65dc616 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
@@ -77,7 +77,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:
@@ -220,7 +220,7 @@ public abstract class HttpObjectEncoder extends MessageTo
@Deprecated
protected static void encodeAscii(String s, ByteBuf buf) {
- HttpHeaders.encodeAscii0(s, buf);
+ HttpUtil.encodeAscii0(s, buf);
}
protected abstract void encodeInitialLine(ByteBuf buf, H message) throws Exception;
diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseStatus.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseStatus.java
index d37ef0c9d5..54b57c18a3 100644
--- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseStatus.java
+++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseStatus.java
@@ -670,9 +670,9 @@ public class HttpResponseStatus implements Comparable {
void encode(ByteBuf buf) {
if (bytes == null) {
- HttpHeaders.encodeAscii0(String.valueOf(code()), buf);
+ HttpUtil.encodeAscii0(String.valueOf(code()), buf);
buf.writeByte(SP);
- HttpHeaders.encodeAscii0(String.valueOf(reasonPhrase()), buf);
+ HttpUtil.encodeAscii0(String.valueOf(reasonPhrase()), buf);
} else {
buf.writeBytes(bytes);
}
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..70984ed82a 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,12 @@
*/
package io.netty.handler.codec.http;
+import io.netty.buffer.ByteBuf;
+
import java.net.URI;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
/**
* Utility methods useful in the HTTP context.
@@ -42,4 +47,252 @@ 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()}.
+ *
+ *
If the connection is kept alive by default:
+ *
+ *
set to {@code "close"} if {@code keepAlive} is {@code false}.
+ *
remove otherwise.
+ *
+ *
If the connection is closed by default:
+ *
+ *
set to {@code "keep-alive"} if {@code keepAlive} is {@code true}.
+ *
remove otherwise.
+ *
+ *
+ */
+ 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) {
+ String value = message.headers().get(HttpHeaderNames.CONTENT_LENGTH);
+ if (value != null) {
+ return Long.parseLong(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) {
+ String value = message.headers().get(HttpHeaderNames.CONTENT_LENGTH);
+ if (value != null) {
+ return Long.parseLong(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, 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().set(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 encodings = m.headers().getAll(HttpHeaderNames.TRANSFER_ENCODING);
+ if (encodings.isEmpty()) {
+ return;
+ }
+ List values = new ArrayList(encodings);
+ 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/HttpVersion.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpVersion.java
index 0dbfda8ec0..806a1b7fde 100644
--- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpVersion.java
+++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpVersion.java
@@ -264,7 +264,7 @@ public class HttpVersion implements Comparable {
void encode(ByteBuf buf) {
if (bytes == null) {
- HttpHeaders.encodeAscii0(text, buf);
+ HttpUtil.encodeAscii0(text, buf);
} else {
buf.writeBytes(bytes);
}
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 591c7320cc..e5490704e3 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
@@ -24,7 +24,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;
@@ -760,7 +760,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 2a86d23d05..fef9021253 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;
@@ -159,7 +159,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/http/websocketx/WebSocketServerProtocolHandshakeHandler.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandshakeHandler.java
index 2199ce6837..7839030766 100644
--- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandshakeHandler.java
+++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandshakeHandler.java
@@ -27,7 +27,7 @@ import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.ssl.SslHandler;
-import static io.netty.handler.codec.http.HttpHeaderUtil.*;
+import static io.netty.handler.codec.http.HttpUtil.*;
import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
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 efd5c895dd..d4128707c5 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 0995c3eeb4..89b11273c1 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
@@ -105,7 +105,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
index ac4acec79e..920c1e3401 100644
--- 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
@@ -31,7 +31,7 @@ public class HttpHeadersTest {
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/HttpObjectAggregatorTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpObjectAggregatorTest.java
index 0a9586817b..1b96870504 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().set("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 631c4fbff1..4b67ad5585 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 1c912b2aa1..d53bc16b43 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;
@@ -54,7 +54,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.
*/
@@ -99,7 +99,7 @@ public final class HttpUtil {
*/
private static final AsciiString EMPTY_REQUEST_PATH = new AsciiString("/");
- private HttpUtil() {
+ private HttpConversionUtil() {
}
/**
@@ -266,7 +266,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 53d527dd34..f5e058e022 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
@@ -36,11 +36,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 {
@@ -113,8 +113,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());
}
/**
@@ -169,7 +169,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 {
@@ -178,7 +178,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());
}
}
}
@@ -196,7 +196,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 59f4dabcc8..67e92a1c18 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 1ecbd15cb5..b2a4f33b3b 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
@@ -30,7 +30,7 @@ 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.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.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