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
This commit is contained in:
parent
c8fb2a84c5
commit
b6a4f5de9d
@ -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()}.
|
|
||||||
* <ul>
|
|
||||||
* <li>If the connection is kept alive by default:
|
|
||||||
* <ul>
|
|
||||||
* <li>set to {@code "close"} if {@code keepAlive} is {@code false}.</li>
|
|
||||||
* <li>remove otherwise.</li>
|
|
||||||
* </ul></li>
|
|
||||||
* <li>If the connection is closed by default:
|
|
||||||
* <ul>
|
|
||||||
* <li>set to {@code "keep-alive"} if {@code keepAlive} is {@code true}.</li>
|
|
||||||
* <li>remove otherwise.</li>
|
|
||||||
* </ul></li>
|
|
||||||
* </ul>
|
|
||||||
*/
|
|
||||||
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<String> encodings = m.headers().getAll(HttpHeaderNames.TRANSFER_ENCODING);
|
|
||||||
if (encodings.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<CharSequence> values = new ArrayList<CharSequence>(encodings);
|
|
||||||
Iterator<CharSequence> 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() { }
|
|
||||||
}
|
|
@ -488,7 +488,7 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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
|
* Returns {@code true} if and only if the connection can remain open and
|
||||||
* thus 'kept alive'. This methods respects the value of the
|
* thus 'kept alive'. This methods respects the value of the
|
||||||
@ -497,11 +497,11 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static boolean isKeepAlive(HttpMessage message) {
|
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
|
* Sets the value of the {@code "Connection"} header depending on the
|
||||||
* protocol version of the specified message. This getMethod sets or removes
|
* protocol version of the specified message. This getMethod sets or removes
|
||||||
@ -523,7 +523,7 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void setKeepAlive(HttpMessage message, boolean keepAlive) {
|
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<Map.Entry<String, String>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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
|
* Returns the length of the content. Please note that this value is
|
||||||
* not retrieved from {@link HttpContent#content()} but from the
|
* not retrieved from {@link HttpContent#content()} but from the
|
||||||
@ -954,11 +954,11 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static long getContentLength(HttpMessage message) {
|
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
|
* Returns the length of the content. Please note that this value is
|
||||||
* not retrieved from {@link HttpContent#content()} but from the
|
* not retrieved from {@link HttpContent#content()} but from the
|
||||||
@ -971,15 +971,15 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static long getContentLength(HttpMessage message, long defaultValue) {
|
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
|
@Deprecated
|
||||||
public static void setContentLength(HttpMessage message, long length) {
|
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<Map.Entry<String, String>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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
|
* Returns {@code true} if and only if the specified message contains the
|
||||||
* {@code "Expect: 100-continue"} header.
|
* {@code "Expect: 100-continue"} header.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static boolean is100ContinueExpected(HttpMessage message) {
|
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.
|
* Sets the {@code "Expect: 100-continue"} header to the specified message.
|
||||||
* If there is any existing {@code "Expect"} header, they are replaced with
|
* If there is any existing {@code "Expect"} header, they are replaced with
|
||||||
@ -1078,11 +1078,11 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void set100ContinueExpected(HttpMessage message) {
|
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
|
* Sets or removes the {@code "Expect: 100-continue"} header to / from the
|
||||||
* specified message. If the specified {@code value} is {@code true},
|
* specified message. If the specified {@code value} is {@code true},
|
||||||
@ -1092,11 +1092,11 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void set100ContinueExpected(HttpMessage message, boolean set) {
|
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
|
* Checks to see if the transfer encoding in a specified {@link HttpMessage} is chunked
|
||||||
*
|
*
|
||||||
@ -1105,31 +1105,31 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static boolean isTransferEncodingChunked(HttpMessage message) {
|
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
|
@Deprecated
|
||||||
public static void removeTransferEncodingChunked(HttpMessage m) {
|
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
|
@Deprecated
|
||||||
public static void setTransferEncodingChunked(HttpMessage m) {
|
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
|
@Deprecated
|
||||||
public static boolean isContentLengthSet(HttpMessage m) {
|
public static boolean isContentLengthSet(HttpMessage m) {
|
||||||
return HttpHeaderUtil.isContentLengthSet(m);
|
return HttpUtil.isContentLengthSet(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1153,14 +1153,7 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
|
|||||||
if (seq instanceof AsciiString) {
|
if (seq instanceof AsciiString) {
|
||||||
ByteBufUtil.copy((AsciiString) seq, 0, buf, seq.length());
|
ByteBufUtil.copy((AsciiString) seq, 0, buf, seq.length());
|
||||||
} else {
|
} else {
|
||||||
encodeAscii0(seq, buf);
|
HttpUtil.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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ import io.netty.util.internal.logging.InternalLogger;
|
|||||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;
|
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}
|
* A {@link ChannelHandler} that aggregates an {@link HttpMessage}
|
||||||
@ -119,7 +119,7 @@ public class HttpObjectAggregator
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object newContinueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline) {
|
protected Object newContinueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline) {
|
||||||
if (HttpHeaderUtil.is100ContinueExpected(start)) {
|
if (HttpUtil.is100ContinueExpected(start)) {
|
||||||
if (getContentLength(start, -1) <= maxContentLength) {
|
if (getContentLength(start, -1) <= maxContentLength) {
|
||||||
return CONTINUE.duplicate().retain();
|
return CONTINUE.duplicate().retain();
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ public class HttpObjectAggregator
|
|||||||
protected FullHttpMessage beginAggregation(HttpMessage start, ByteBuf content) throws Exception {
|
protected FullHttpMessage beginAggregation(HttpMessage start, ByteBuf content) throws Exception {
|
||||||
assert !(start instanceof FullHttpMessage);
|
assert !(start instanceof FullHttpMessage);
|
||||||
|
|
||||||
HttpHeaderUtil.setTransferEncodingChunked(start, false);
|
HttpUtil.setTransferEncodingChunked(start, false);
|
||||||
|
|
||||||
AggregatedFullHttpMessage ret;
|
AggregatedFullHttpMessage ret;
|
||||||
if (start instanceof HttpRequest) {
|
if (start instanceof HttpRequest) {
|
||||||
@ -174,7 +174,7 @@ public class HttpObjectAggregator
|
|||||||
// transmitted if a GET would have been used.
|
// transmitted if a GET would have been used.
|
||||||
//
|
//
|
||||||
// See rfc2616 14.13 Content-Length
|
// See rfc2616 14.13 Content-Length
|
||||||
if (!HttpHeaderUtil.isContentLengthSet(aggregated)) {
|
if (!HttpUtil.isContentLengthSet(aggregated)) {
|
||||||
aggregated.headers().set(
|
aggregated.headers().set(
|
||||||
HttpHeaderNames.CONTENT_LENGTH,
|
HttpHeaderNames.CONTENT_LENGTH,
|
||||||
String.valueOf(aggregated.content().readableBytes()));
|
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 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 keep-alive is off and 'Expect: 100-continue' is missing, no need to leave the connection open.
|
||||||
if (oversized instanceof FullHttpMessage ||
|
if (oversized instanceof FullHttpMessage ||
|
||||||
!HttpHeaderUtil.is100ContinueExpected(oversized) && !HttpHeaderUtil.isKeepAlive(oversized)) {
|
!HttpUtil.is100ContinueExpected(oversized) && !HttpUtil.isKeepAlive(oversized)) {
|
||||||
future.addListener(ChannelFutureListener.CLOSE);
|
future.addListener(ChannelFutureListener.CLOSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,7 +398,7 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder {
|
|||||||
|
|
||||||
// Handle the last unfinished message.
|
// Handle the last unfinished message.
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
boolean chunked = HttpHeaderUtil.isTransferEncodingChunked(message);
|
boolean chunked = HttpUtil.isTransferEncodingChunked(message);
|
||||||
if (currentState == State.READ_VARIABLE_LENGTH_CONTENT && !in.isReadable() && !chunked) {
|
if (currentState == State.READ_VARIABLE_LENGTH_CONTENT && !in.isReadable() && !chunked) {
|
||||||
// End of connection.
|
// End of connection.
|
||||||
out.add(LastHttpContent.EMPTY_LAST_CONTENT);
|
out.add(LastHttpContent.EMPTY_LAST_CONTENT);
|
||||||
@ -588,9 +588,9 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder {
|
|||||||
State nextState;
|
State nextState;
|
||||||
|
|
||||||
if (isContentAlwaysEmpty(message)) {
|
if (isContentAlwaysEmpty(message)) {
|
||||||
HttpHeaderUtil.setTransferEncodingChunked(message, false);
|
HttpUtil.setTransferEncodingChunked(message, false);
|
||||||
nextState = State.SKIP_CONTROL_CHARS;
|
nextState = State.SKIP_CONTROL_CHARS;
|
||||||
} else if (HttpHeaderUtil.isTransferEncodingChunked(message)) {
|
} else if (HttpUtil.isTransferEncodingChunked(message)) {
|
||||||
nextState = State.READ_CHUNK_SIZE;
|
nextState = State.READ_CHUNK_SIZE;
|
||||||
} else if (contentLength() >= 0) {
|
} else if (contentLength() >= 0) {
|
||||||
nextState = State.READ_FIXED_LENGTH_CONTENT;
|
nextState = State.READ_FIXED_LENGTH_CONTENT;
|
||||||
@ -602,7 +602,7 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder {
|
|||||||
|
|
||||||
private long contentLength() {
|
private long contentLength() {
|
||||||
if (contentLength == Long.MIN_VALUE) {
|
if (contentLength == Long.MIN_VALUE) {
|
||||||
contentLength = HttpHeaderUtil.getContentLength(message, -1);
|
contentLength = HttpUtil.getContentLength(message, -1);
|
||||||
}
|
}
|
||||||
return contentLength;
|
return contentLength;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ public abstract class HttpObjectEncoder<H extends HttpMessage> extends MessageTo
|
|||||||
encodeInitialLine(buf, m);
|
encodeInitialLine(buf, m);
|
||||||
encodeHeaders(m.headers(), buf);
|
encodeHeaders(m.headers(), buf);
|
||||||
buf.writeBytes(CRLF);
|
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:
|
// Bypass the encoder in case of an empty buffer, so that the following idiom works:
|
||||||
@ -220,7 +220,7 @@ public abstract class HttpObjectEncoder<H extends HttpMessage> extends MessageTo
|
|||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
protected static void encodeAscii(String s, ByteBuf buf) {
|
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;
|
protected abstract void encodeInitialLine(ByteBuf buf, H message) throws Exception;
|
||||||
|
@ -670,9 +670,9 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
|
|||||||
|
|
||||||
void encode(ByteBuf buf) {
|
void encode(ByteBuf buf) {
|
||||||
if (bytes == null) {
|
if (bytes == null) {
|
||||||
HttpHeaders.encodeAscii0(String.valueOf(code()), buf);
|
HttpUtil.encodeAscii0(String.valueOf(code()), buf);
|
||||||
buf.writeByte(SP);
|
buf.writeByte(SP);
|
||||||
HttpHeaders.encodeAscii0(String.valueOf(reasonPhrase()), buf);
|
HttpUtil.encodeAscii0(String.valueOf(reasonPhrase()), buf);
|
||||||
} else {
|
} else {
|
||||||
buf.writeBytes(bytes);
|
buf.writeBytes(bytes);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility methods useful in the HTTP context.
|
* 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.getHost() == null && uri.getAuthority() == null && uri.getQuery() == null &&
|
||||||
uri.getFragment() == 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()}.
|
||||||
|
* <ul>
|
||||||
|
* <li>If the connection is kept alive by default:
|
||||||
|
* <ul>
|
||||||
|
* <li>set to {@code "close"} if {@code keepAlive} is {@code false}.</li>
|
||||||
|
* <li>remove otherwise.</li>
|
||||||
|
* </ul></li>
|
||||||
|
* <li>If the connection is closed by default:
|
||||||
|
* <ul>
|
||||||
|
* <li>set to {@code "keep-alive"} if {@code keepAlive} is {@code true}.</li>
|
||||||
|
* <li>remove otherwise.</li>
|
||||||
|
* </ul></li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
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<String> encodings = m.headers().getAll(HttpHeaderNames.TRANSFER_ENCODING);
|
||||||
|
if (encodings.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<CharSequence> values = new ArrayList<CharSequence>(encodings);
|
||||||
|
Iterator<CharSequence> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ public class HttpVersion implements Comparable<HttpVersion> {
|
|||||||
|
|
||||||
void encode(ByteBuf buf) {
|
void encode(ByteBuf buf) {
|
||||||
if (bytes == null) {
|
if (bytes == null) {
|
||||||
HttpHeaders.encodeAscii0(text, buf);
|
HttpUtil.encodeAscii0(text, buf);
|
||||||
} else {
|
} else {
|
||||||
buf.writeBytes(bytes);
|
buf.writeBytes(bytes);
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ import io.netty.handler.codec.http.FullHttpRequest;
|
|||||||
import io.netty.handler.codec.http.HttpConstants;
|
import io.netty.handler.codec.http.HttpConstants;
|
||||||
import io.netty.handler.codec.http.HttpContent;
|
import io.netty.handler.codec.http.HttpContent;
|
||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
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.HttpHeaderValues;
|
||||||
import io.netty.handler.codec.http.HttpHeaders;
|
import io.netty.handler.codec.http.HttpHeaders;
|
||||||
import io.netty.handler.codec.http.HttpMethod;
|
import io.netty.handler.codec.http.HttpMethod;
|
||||||
@ -760,7 +760,7 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HttpHeaderUtil.setTransferEncodingChunked(request, true);
|
HttpUtil.setTransferEncodingChunked(request, true);
|
||||||
|
|
||||||
// wrap to hide the possible content
|
// wrap to hide the possible content
|
||||||
return new WrappedHttpRequest(request);
|
return new WrappedHttpRequest(request);
|
||||||
|
@ -20,7 +20,7 @@ import io.netty.channel.ChannelFuture;
|
|||||||
import io.netty.channel.ChannelPromise;
|
import io.netty.channel.ChannelPromise;
|
||||||
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
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.HttpRequest;
|
||||||
import io.netty.handler.codec.http.HttpResponse;
|
import io.netty.handler.codec.http.HttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
@ -159,7 +159,7 @@ public class WebSocketServerHandshakerFactory {
|
|||||||
HttpVersion.HTTP_1_1,
|
HttpVersion.HTTP_1_1,
|
||||||
HttpResponseStatus.UPGRADE_REQUIRED);
|
HttpResponseStatus.UPGRADE_REQUIRED);
|
||||||
res.headers().set(HttpHeaderNames.SEC_WEBSOCKET_VERSION, WebSocketVersion.V13.toHttpHeaderValue());
|
res.headers().set(HttpHeaderNames.SEC_WEBSOCKET_VERSION, WebSocketVersion.V13.toHttpHeaderValue());
|
||||||
HttpHeaderUtil.setContentLength(res, 0);
|
HttpUtil.setContentLength(res, 0);
|
||||||
return channel.writeAndFlush(res, promise);
|
return channel.writeAndFlush(res, promise);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ import io.netty.handler.codec.http.HttpRequest;
|
|||||||
import io.netty.handler.codec.http.HttpResponse;
|
import io.netty.handler.codec.http.HttpResponse;
|
||||||
import io.netty.handler.ssl.SslHandler;
|
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.HttpMethod.*;
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
||||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
|
@ -25,7 +25,7 @@ import io.netty.handler.codec.http.FullHttpMessage;
|
|||||||
import io.netty.handler.codec.http.FullHttpRequest;
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
import io.netty.handler.codec.http.FullHttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
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.HttpMethod;
|
||||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
import io.netty.handler.codec.http.HttpVersion;
|
import io.netty.handler.codec.http.HttpVersion;
|
||||||
@ -240,7 +240,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
|
|||||||
httpResponseWithEntity.headers().setInt(Names.STREAM_ID, streamId);
|
httpResponseWithEntity.headers().setInt(Names.STREAM_ID, streamId);
|
||||||
|
|
||||||
if (spdySynReplyFrame.isLast()) {
|
if (spdySynReplyFrame.isLast()) {
|
||||||
HttpHeaderUtil.setContentLength(httpResponseWithEntity, 0);
|
HttpUtil.setContentLength(httpResponseWithEntity, 0);
|
||||||
out.add(httpResponseWithEntity);
|
out.add(httpResponseWithEntity);
|
||||||
} else {
|
} else {
|
||||||
// Response body will follow in a series of Data Frames
|
// Response body will follow in a series of Data Frames
|
||||||
@ -280,7 +280,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
|
|||||||
fullHttpMessage.headers().setInt(Names.STREAM_ID, streamId);
|
fullHttpMessage.headers().setInt(Names.STREAM_ID, streamId);
|
||||||
|
|
||||||
if (spdyHeadersFrame.isLast()) {
|
if (spdyHeadersFrame.isLast()) {
|
||||||
HttpHeaderUtil.setContentLength(fullHttpMessage, 0);
|
HttpUtil.setContentLength(fullHttpMessage, 0);
|
||||||
out.add(fullHttpMessage);
|
out.add(fullHttpMessage);
|
||||||
} else {
|
} else {
|
||||||
// Response body will follow in a series of Data Frames
|
// Response body will follow in a series of Data Frames
|
||||||
@ -305,7 +305,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (spdyHeadersFrame.isLast()) {
|
if (spdyHeadersFrame.isLast()) {
|
||||||
HttpHeaderUtil.setContentLength(fullHttpMessage, fullHttpMessage.content().readableBytes());
|
HttpUtil.setContentLength(fullHttpMessage, fullHttpMessage.content().readableBytes());
|
||||||
removeMessage(streamId);
|
removeMessage(streamId);
|
||||||
out.add(fullHttpMessage);
|
out.add(fullHttpMessage);
|
||||||
}
|
}
|
||||||
@ -333,7 +333,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
|
|||||||
content.writeBytes(spdyDataFrameData, spdyDataFrameData.readerIndex(), spdyDataFrameDataLen);
|
content.writeBytes(spdyDataFrameData, spdyDataFrameData.readerIndex(), spdyDataFrameDataLen);
|
||||||
|
|
||||||
if (spdyDataFrame.isLast()) {
|
if (spdyDataFrame.isLast()) {
|
||||||
HttpHeaderUtil.setContentLength(fullHttpMessage, content.readableBytes());
|
HttpUtil.setContentLength(fullHttpMessage, content.readableBytes());
|
||||||
removeMessage(streamId);
|
removeMessage(streamId);
|
||||||
out.add(fullHttpMessage);
|
out.add(fullHttpMessage);
|
||||||
}
|
}
|
||||||
@ -372,7 +372,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The Connection and Keep-Alive headers are no longer valid
|
// The Connection and Keep-Alive headers are no longer valid
|
||||||
HttpHeaderUtil.setKeepAlive(req, true);
|
HttpUtil.setKeepAlive(req, true);
|
||||||
|
|
||||||
// Transfer-Encoding header is not valid
|
// Transfer-Encoding header is not valid
|
||||||
req.headers().remove(HttpHeaderNames.TRANSFER_ENCODING);
|
req.headers().remove(HttpHeaderNames.TRANSFER_ENCODING);
|
||||||
@ -396,7 +396,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The Connection and Keep-Alive headers are no longer valid
|
// The Connection and Keep-Alive headers are no longer valid
|
||||||
HttpHeaderUtil.setKeepAlive(res, true);
|
HttpUtil.setKeepAlive(res, true);
|
||||||
|
|
||||||
// Transfer-Encoding header is not valid
|
// Transfer-Encoding header is not valid
|
||||||
res.headers().remove(HttpHeaderNames.TRANSFER_ENCODING);
|
res.headers().remove(HttpHeaderNames.TRANSFER_ENCODING);
|
||||||
|
@ -105,7 +105,7 @@ public class DefaultHttpHeadersTest {
|
|||||||
HttpMessage message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
HttpMessage message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
||||||
message.headers().set(HttpHeaderNames.TRANSFER_ENCODING, "Chunked");
|
message.headers().set(HttpHeaderNames.TRANSFER_ENCODING, "Chunked");
|
||||||
assertFalse(message.headers().isEmpty());
|
assertFalse(message.headers().isEmpty());
|
||||||
HttpHeaderUtil.setTransferEncodingChunked(message, false);
|
HttpUtil.setTransferEncodingChunked(message, false);
|
||||||
assertTrue(message.headers().isEmpty());
|
assertTrue(message.headers().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ public class HttpHeadersTest {
|
|||||||
HttpMessage message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
HttpMessage message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
||||||
message.headers().set(HttpHeaderNames.TRANSFER_ENCODING, "Chunked");
|
message.headers().set(HttpHeaderNames.TRANSFER_ENCODING, "Chunked");
|
||||||
assertFalse(message.headers().isEmpty());
|
assertFalse(message.headers().isEmpty());
|
||||||
HttpHeaderUtil.setTransferEncodingChunked(message, false);
|
HttpUtil.setTransferEncodingChunked(message, false);
|
||||||
assertTrue(message.headers().isEmpty());
|
assertTrue(message.headers().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public class HttpObjectAggregatorTest {
|
|||||||
assertNotNull(aggratedMessage);
|
assertNotNull(aggratedMessage);
|
||||||
|
|
||||||
assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(),
|
assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(),
|
||||||
HttpHeaderUtil.getContentLength(aggratedMessage));
|
HttpUtil.getContentLength(aggratedMessage));
|
||||||
assertEquals(aggratedMessage.headers().get("X-Test"), Boolean.TRUE.toString());
|
assertEquals(aggratedMessage.headers().get("X-Test"), Boolean.TRUE.toString());
|
||||||
checkContentBuffer(aggratedMessage);
|
checkContentBuffer(aggratedMessage);
|
||||||
assertNull(embedder.readInbound());
|
assertNull(embedder.readInbound());
|
||||||
@ -87,7 +87,7 @@ public class HttpObjectAggregatorTest {
|
|||||||
EmbeddedChannel embedder = new EmbeddedChannel(aggr);
|
EmbeddedChannel embedder = new EmbeddedChannel(aggr);
|
||||||
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost");
|
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost");
|
||||||
message.headers().set("X-Test", true);
|
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 chunk1 = new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII));
|
||||||
HttpContent chunk2 = new DefaultHttpContent(Unpooled.copiedBuffer("test2", CharsetUtil.US_ASCII));
|
HttpContent chunk2 = new DefaultHttpContent(Unpooled.copiedBuffer("test2", CharsetUtil.US_ASCII));
|
||||||
LastHttpContent trailer = new DefaultLastHttpContent();
|
LastHttpContent trailer = new DefaultLastHttpContent();
|
||||||
@ -104,7 +104,7 @@ public class HttpObjectAggregatorTest {
|
|||||||
assertNotNull(aggratedMessage);
|
assertNotNull(aggratedMessage);
|
||||||
|
|
||||||
assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(),
|
assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(),
|
||||||
HttpHeaderUtil.getContentLength(aggratedMessage));
|
HttpUtil.getContentLength(aggratedMessage));
|
||||||
assertEquals(aggratedMessage.headers().get("X-Test"), Boolean.TRUE.toString());
|
assertEquals(aggratedMessage.headers().get("X-Test"), Boolean.TRUE.toString());
|
||||||
assertEquals(aggratedMessage.trailingHeaders().get("X-Trailer"), Boolean.TRUE.toString());
|
assertEquals(aggratedMessage.trailingHeaders().get("X-Trailer"), Boolean.TRUE.toString());
|
||||||
checkContentBuffer(aggratedMessage);
|
checkContentBuffer(aggratedMessage);
|
||||||
@ -142,14 +142,14 @@ public class HttpObjectAggregatorTest {
|
|||||||
public void testOversizedRequestWithoutKeepAlive() {
|
public void testOversizedRequestWithoutKeepAlive() {
|
||||||
// send a HTTP/1.0 request with no keep-alive header
|
// send a HTTP/1.0 request with no keep-alive header
|
||||||
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.PUT, "http://localhost");
|
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.PUT, "http://localhost");
|
||||||
HttpHeaderUtil.setContentLength(message, 5);
|
HttpUtil.setContentLength(message, 5);
|
||||||
checkOversizedRequest(message);
|
checkOversizedRequest(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOversizedRequestWithContentLength() {
|
public void testOversizedRequestWithContentLength() {
|
||||||
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "http://localhost");
|
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "http://localhost");
|
||||||
HttpHeaderUtil.setContentLength(message, 5);
|
HttpUtil.setContentLength(message, 5);
|
||||||
checkOversizedRequest(message);
|
checkOversizedRequest(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,10 +172,10 @@ public class HttpObjectAggregatorTest {
|
|||||||
private static boolean serverShouldCloseConnection(HttpRequest message) {
|
private static boolean serverShouldCloseConnection(HttpRequest message) {
|
||||||
// The connection should only be kept open if Expect: 100-continue is set,
|
// The connection should only be kept open if Expect: 100-continue is set,
|
||||||
// or if keep-alive is on.
|
// or if keep-alive is on.
|
||||||
if (HttpHeaderUtil.is100ContinueExpected(message)) {
|
if (HttpUtil.is100ContinueExpected(message)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (HttpHeaderUtil.isKeepAlive(message)) {
|
if (HttpUtil.isKeepAlive(message)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -244,7 +244,7 @@ public class HttpObjectAggregatorTest {
|
|||||||
assertNotNull(aggratedMessage);
|
assertNotNull(aggratedMessage);
|
||||||
|
|
||||||
assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(),
|
assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(),
|
||||||
HttpHeaderUtil.getContentLength(aggratedMessage));
|
HttpUtil.getContentLength(aggratedMessage));
|
||||||
assertEquals(aggratedMessage.headers().get("X-Test"), Boolean.TRUE.toString());
|
assertEquals(aggratedMessage.headers().get("X-Test"), Boolean.TRUE.toString());
|
||||||
checkContentBuffer(aggratedMessage);
|
checkContentBuffer(aggratedMessage);
|
||||||
assertNull(embedder.readInbound());
|
assertNull(embedder.readInbound());
|
||||||
@ -278,8 +278,8 @@ public class HttpObjectAggregatorTest {
|
|||||||
|
|
||||||
// Send an oversized request with 100 continue.
|
// Send an oversized request with 100 continue.
|
||||||
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "http://localhost");
|
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "http://localhost");
|
||||||
HttpHeaderUtil.set100ContinueExpected(message, true);
|
HttpUtil.set100ContinueExpected(message, true);
|
||||||
HttpHeaderUtil.setContentLength(message, 16);
|
HttpUtil.setContentLength(message, 16);
|
||||||
|
|
||||||
HttpContent chunk1 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("some", CharsetUtil.US_ASCII)));
|
HttpContent chunk1 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("some", CharsetUtil.US_ASCII)));
|
||||||
HttpContent chunk2 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII)));
|
HttpContent chunk2 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII)));
|
||||||
@ -311,9 +311,9 @@ public class HttpObjectAggregatorTest {
|
|||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
chunk2.content().readableBytes() + chunk3.content().readableBytes(),
|
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();
|
fullMsg.release();
|
||||||
assertFalse(embedder.finish());
|
assertFalse(embedder.finish());
|
||||||
@ -373,8 +373,8 @@ public class HttpObjectAggregatorTest {
|
|||||||
|
|
||||||
// Write first request with Expect: 100-continue.
|
// Write first request with Expect: 100-continue.
|
||||||
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "http://localhost");
|
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "http://localhost");
|
||||||
HttpHeaderUtil.set100ContinueExpected(message, true);
|
HttpUtil.set100ContinueExpected(message, true);
|
||||||
HttpHeaderUtil.setContentLength(message, 16);
|
HttpUtil.setContentLength(message, 16);
|
||||||
|
|
||||||
HttpContent chunk1 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("some", CharsetUtil.US_ASCII)));
|
HttpContent chunk1 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("some", CharsetUtil.US_ASCII)));
|
||||||
HttpContent chunk2 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII)));
|
HttpContent chunk2 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII)));
|
||||||
@ -406,9 +406,9 @@ public class HttpObjectAggregatorTest {
|
|||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
chunk2.content().readableBytes() + chunk3.content().readableBytes(),
|
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();
|
fullMsg.release();
|
||||||
assertFalse(embedder.finish());
|
assertFalse(embedder.finish());
|
||||||
|
@ -24,14 +24,14 @@ import java.util.List;
|
|||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class HttpHeaderUtilTest {
|
public class HttpUtilTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveTransferEncodingIgnoreCase() {
|
public void testRemoveTransferEncodingIgnoreCase() {
|
||||||
HttpMessage message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
HttpMessage message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
||||||
message.headers().set(HttpHeaderNames.TRANSFER_ENCODING, "Chunked");
|
message.headers().set(HttpHeaderNames.TRANSFER_ENCODING, "Chunked");
|
||||||
assertFalse(message.headers().isEmpty());
|
assertFalse(message.headers().isEmpty());
|
||||||
HttpHeaderUtil.setTransferEncodingChunked(message, false);
|
HttpUtil.setTransferEncodingChunked(message, false);
|
||||||
assertTrue(message.headers().isEmpty());
|
assertTrue(message.headers().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
@ -19,7 +19,7 @@ package io.netty.handler.codec.http.websocketx;
|
|||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
import io.netty.handler.codec.http.FullHttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
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.handler.codec.http.HttpResponseStatus;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -43,8 +43,8 @@ public class WebSocketServerHandshakerFactoryTest {
|
|||||||
assertEquals(HttpResponseStatus.UPGRADE_REQUIRED, response.status());
|
assertEquals(HttpResponseStatus.UPGRADE_REQUIRED, response.status());
|
||||||
assertEquals(WebSocketVersion.V13.toHttpHeaderValue(),
|
assertEquals(WebSocketVersion.V13.toHttpHeaderValue(),
|
||||||
response.headers().get(HttpHeaderNames.SEC_WEBSOCKET_VERSION));
|
response.headers().get(HttpHeaderNames.SEC_WEBSOCKET_VERSION));
|
||||||
assertTrue(HttpHeaderUtil.isContentLengthSet(response));
|
assertTrue(HttpUtil.isContentLengthSet(response));
|
||||||
assertEquals(0, HttpHeaderUtil.getContentLength(response));
|
assertEquals(0, HttpUtil.getContentLength(response));
|
||||||
|
|
||||||
ReferenceCountUtil.release(response);
|
ReferenceCountUtil.release(response);
|
||||||
assertFalse(ch.finish());
|
assertFalse(ch.finish());
|
||||||
|
@ -20,7 +20,7 @@ import io.netty.handler.codec.http.FullHttpMessage;
|
|||||||
import io.netty.handler.codec.http.FullHttpRequest;
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
import io.netty.handler.codec.http.FullHttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
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.HttpHeaderValues;
|
||||||
import io.netty.handler.codec.http.HttpHeaders;
|
import io.netty.handler.codec.http.HttpHeaders;
|
||||||
import io.netty.handler.codec.http.HttpMessage;
|
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
|
* 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.
|
* 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 static final AsciiString EMPTY_REQUEST_PATH = new AsciiString("/");
|
||||||
|
|
||||||
private HttpUtil() {
|
private HttpConversionUtil() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -266,7 +266,7 @@ public final class HttpUtil {
|
|||||||
headers.remove(HttpHeaderNames.TRAILER);
|
headers.remove(HttpHeaderNames.TRAILER);
|
||||||
if (!addToTrailer) {
|
if (!addToTrailer) {
|
||||||
headers.setInt(ExtensionHeaderNames.STREAM_ID.text(), streamId);
|
headers.setInt(ExtensionHeaderNames.STREAM_ID.text(), streamId);
|
||||||
HttpHeaderUtil.setKeepAlive(destinationMessage, true);
|
HttpUtil.setKeepAlive(destinationMessage, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -61,7 +61,8 @@ public class HttpToHttp2ConnectionHandler extends Http2ConnectionHandler {
|
|||||||
* @throws Exception If the {@code httpHeaders} object specifies an invalid stream id
|
* @throws Exception If the {@code httpHeaders} object specifies an invalid stream id
|
||||||
*/
|
*/
|
||||||
private int getStreamId(HttpHeaders httpHeaders) throws Exception {
|
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());
|
currentStreamId = getStreamId(httpMsg.headers());
|
||||||
|
|
||||||
// Convert and write the headers.
|
// Convert and write the headers.
|
||||||
Http2Headers http2Headers = HttpUtil.toHttp2Headers(httpMsg);
|
Http2Headers http2Headers = HttpConversionUtil.toHttp2Headers(httpMsg);
|
||||||
endStream = msg instanceof FullHttpMessage && !((FullHttpMessage) msg).content().isReadable();
|
endStream = msg instanceof FullHttpMessage && !((FullHttpMessage) msg).content().isReadable();
|
||||||
encoder.writeHeaders(ctx, currentStreamId, http2Headers, 0, endStream, promiseAggregator.newPromise());
|
encoder.writeHeaders(ctx, currentStreamId, http2Headers, 0, endStream, promiseAggregator.newPromise());
|
||||||
}
|
}
|
||||||
@ -101,7 +102,7 @@ public class HttpToHttp2ConnectionHandler extends Http2ConnectionHandler {
|
|||||||
|
|
||||||
// Convert any trailing headers.
|
// Convert any trailing headers.
|
||||||
final LastHttpContent lastContent = (LastHttpContent) msg;
|
final LastHttpContent lastContent = (LastHttpContent) msg;
|
||||||
trailers = HttpUtil.toHttp2Headers(lastContent.trailingHeaders());
|
trailers = HttpConversionUtil.toHttp2Headers(lastContent.trailingHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the data
|
// Write the data
|
||||||
|
@ -25,7 +25,7 @@ import io.netty.handler.codec.http.FullHttpMessage;
|
|||||||
import io.netty.handler.codec.http.FullHttpRequest;
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
import io.netty.handler.codec.http.FullHttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
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.handler.codec.http.HttpStatusClass;
|
||||||
import io.netty.util.collection.IntObjectHashMap;
|
import io.netty.util.collection.IntObjectHashMap;
|
||||||
import io.netty.util.collection.IntObjectMap;
|
import io.netty.util.collection.IntObjectMap;
|
||||||
@ -168,7 +168,7 @@ public class InboundHttp2ToHttpAdapter extends Http2EventAdapter {
|
|||||||
*/
|
*/
|
||||||
protected void fireChannelRead(ChannelHandlerContext ctx, FullHttpMessage msg, int streamId) {
|
protected void fireChannelRead(ChannelHandlerContext ctx, FullHttpMessage msg, int streamId) {
|
||||||
removeMessage(streamId);
|
removeMessage(streamId);
|
||||||
HttpHeaderUtil.setContentLength(msg, msg.content().readableBytes());
|
HttpUtil.setContentLength(msg, msg.content().readableBytes());
|
||||||
ctx.fireChannelRead(msg);
|
ctx.fireChannelRead(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,8 +186,8 @@ public class InboundHttp2ToHttpAdapter extends Http2EventAdapter {
|
|||||||
*/
|
*/
|
||||||
protected FullHttpMessage newMessage(int streamId, Http2Headers headers, boolean validateHttpHeaders)
|
protected FullHttpMessage newMessage(int streamId, Http2Headers headers, boolean validateHttpHeaders)
|
||||||
throws Http2Exception {
|
throws Http2Exception {
|
||||||
return connection.isServer() ? HttpUtil.toHttpRequest(streamId, headers,
|
return connection.isServer() ? HttpConversionUtil.toHttpRequest(streamId, headers,
|
||||||
validateHttpHeaders) : HttpUtil.toHttpResponse(streamId, headers, validateHttpHeaders);
|
validateHttpHeaders) : HttpConversionUtil.toHttpResponse(streamId, headers, validateHttpHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -221,7 +221,7 @@ public class InboundHttp2ToHttpAdapter extends Http2EventAdapter {
|
|||||||
msg = newMessage(streamId, headers, validateHttpHeaders);
|
msg = newMessage(streamId, headers, validateHttpHeaders);
|
||||||
} else if (allowAppend) {
|
} else if (allowAppend) {
|
||||||
try {
|
try {
|
||||||
HttpUtil.addHttp2ToHttpHeaders(streamId, headers, msg, appendToTrailer);
|
HttpConversionUtil.addHttp2ToHttpHeaders(streamId, headers, msg, appendToTrailer);
|
||||||
} catch (Http2Exception e) {
|
} catch (Http2Exception e) {
|
||||||
removeMessage(streamId);
|
removeMessage(streamId);
|
||||||
throw e;
|
throw e;
|
||||||
@ -320,7 +320,7 @@ public class InboundHttp2ToHttpAdapter extends Http2EventAdapter {
|
|||||||
promisedStreamId);
|
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);
|
processHeadersEnd(ctx, promisedStreamId, msg, false);
|
||||||
}
|
}
|
||||||
|
@ -36,11 +36,11 @@ import static io.netty.handler.codec.http2.Http2Exception.connectionError;
|
|||||||
*/
|
*/
|
||||||
public final class InboundHttp2ToHttpPriorityAdapter extends InboundHttp2ToHttpAdapter {
|
public final class InboundHttp2ToHttpPriorityAdapter extends InboundHttp2ToHttpAdapter {
|
||||||
private static final AsciiString OUT_OF_MESSAGE_SEQUENCE_METHOD = new AsciiString(
|
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(
|
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(
|
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<HttpHeaders> outOfMessageFlowHeaders;
|
private final IntObjectMap<HttpHeaders> outOfMessageFlowHeaders;
|
||||||
|
|
||||||
public static final class Builder extends InboundHttp2ToHttpAdapter.Builder {
|
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
|
* @param headers The headers to remove the priority tree elements from
|
||||||
*/
|
*/
|
||||||
private static void removePriorityRelatedHeaders(HttpHeaders headers) {
|
private static void removePriorityRelatedHeaders(HttpHeaders headers) {
|
||||||
headers.remove(HttpUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text());
|
headers.remove(HttpConversionUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text());
|
||||||
headers.remove(HttpUtil.ExtensionHeaderNames.STREAM_WEIGHT.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.
|
// and the HTTP message flow exists in OPEN.
|
||||||
if (parent != null && !parent.equals(connection.connectionStream())) {
|
if (parent != null && !parent.equals(connection.connectionStream())) {
|
||||||
HttpHeaders headers = new DefaultHttpHeaders();
|
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);
|
importOutOfMessageFlowHeaders(stream.id(), headers);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -178,7 +178,7 @@ public final class InboundHttp2ToHttpPriorityAdapter extends InboundHttp2ToHttpA
|
|||||||
removePriorityRelatedHeaders(msg.trailingHeaders());
|
removePriorityRelatedHeaders(msg.trailingHeaders());
|
||||||
} else if (!parent.equals(connection.connectionStream())) {
|
} else if (!parent.equals(connection.connectionStream())) {
|
||||||
HttpHeaders headers = getActiveHeaders(msg);
|
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 {
|
} else {
|
||||||
headers = getActiveHeaders(msg);
|
headers = getActiveHeaders(msg);
|
||||||
}
|
}
|
||||||
headers.setShort(HttpUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), stream.weight());
|
headers.setShort(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), stream.weight());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -123,11 +123,10 @@ public class HttpToHttp2ConnectionHandlerTest {
|
|||||||
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET,
|
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET,
|
||||||
"http://my-user_name@www.example.org:5555/example");
|
"http://my-user_name@www.example.org:5555/example");
|
||||||
final HttpHeaders httpHeaders = request.headers();
|
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,
|
httpHeaders.set(HttpHeaderNames.HOST, "my-user_name@www.example.org:5555");
|
||||||
"my-user_name@www.example.org:5555");
|
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.AUTHORITY.text(), "www.example.org:5555");
|
||||||
httpHeaders.set(HttpUtil.ExtensionHeaderNames.AUTHORITY.text(), "www.example.org:5555");
|
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "http");
|
||||||
httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "http");
|
|
||||||
httpHeaders.add("foo", "goo");
|
httpHeaders.add("foo", "goo");
|
||||||
httpHeaders.add("foo", "goo2");
|
httpHeaders.add("foo", "goo2");
|
||||||
httpHeaders.add("foo2", "goo2");
|
httpHeaders.add("foo2", "goo2");
|
||||||
@ -147,8 +146,8 @@ public class HttpToHttp2ConnectionHandlerTest {
|
|||||||
bootstrapEnv(2, 1, 0);
|
bootstrapEnv(2, 1, 0);
|
||||||
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/where?q=now&f=then#section1");
|
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/where?q=now&f=then#section1");
|
||||||
final HttpHeaders httpHeaders = request.headers();
|
final HttpHeaders httpHeaders = request.headers();
|
||||||
httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
|
httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
|
||||||
httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "http");
|
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "http");
|
||||||
final Http2Headers http2Headers =
|
final Http2Headers http2Headers =
|
||||||
new DefaultHttp2Headers().method(new AsciiString("GET"))
|
new DefaultHttp2Headers().method(new AsciiString("GET"))
|
||||||
.path(new AsciiString("/where?q=now&f=then#section1"))
|
.path(new AsciiString("/where?q=now&f=then#section1"))
|
||||||
@ -163,12 +162,11 @@ public class HttpToHttp2ConnectionHandlerTest {
|
|||||||
bootstrapEnv(2, 1, 0);
|
bootstrapEnv(2, 1, 0);
|
||||||
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/pub/WWW/TheProject.html");
|
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/pub/WWW/TheProject.html");
|
||||||
final HttpHeaders httpHeaders = request.headers();
|
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,
|
httpHeaders.set(HttpHeaderNames.HOST, "foouser@www.example.org:5555");
|
||||||
"foouser@www.example.org:5555");
|
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.PATH.text(), "ignored_path");
|
||||||
httpHeaders.set(HttpUtil.ExtensionHeaderNames.PATH.text(), "ignored_path");
|
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.AUTHORITY.text(), "ignored_authority");
|
||||||
httpHeaders.set(HttpUtil.ExtensionHeaderNames.AUTHORITY.text(), "ignored_authority");
|
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "https");
|
||||||
httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "https");
|
|
||||||
final Http2Headers http2Headers =
|
final Http2Headers http2Headers =
|
||||||
new DefaultHttp2Headers().method(new AsciiString("GET"))
|
new DefaultHttp2Headers().method(new AsciiString("GET"))
|
||||||
.path(new AsciiString("/pub/WWW/TheProject.html"))
|
.path(new AsciiString("/pub/WWW/TheProject.html"))
|
||||||
@ -183,10 +181,10 @@ public class HttpToHttp2ConnectionHandlerTest {
|
|||||||
bootstrapEnv(2, 1, 0);
|
bootstrapEnv(2, 1, 0);
|
||||||
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/pub/WWW/TheProject.html");
|
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/pub/WWW/TheProject.html");
|
||||||
final HttpHeaders httpHeaders = request.headers();
|
final HttpHeaders httpHeaders = request.headers();
|
||||||
httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
|
httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
|
||||||
httpHeaders.set(HttpUtil.ExtensionHeaderNames.PATH.text(), "ignored_path");
|
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.PATH.text(), "ignored_path");
|
||||||
httpHeaders.set(HttpUtil.ExtensionHeaderNames.AUTHORITY.text(), "www.example.org:5555");
|
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.AUTHORITY.text(), "www.example.org:5555");
|
||||||
httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "https");
|
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "https");
|
||||||
final Http2Headers http2Headers =
|
final Http2Headers http2Headers =
|
||||||
new DefaultHttp2Headers().method(new AsciiString("GET"))
|
new DefaultHttp2Headers().method(new AsciiString("GET"))
|
||||||
.path(new AsciiString("/pub/WWW/TheProject.html"))
|
.path(new AsciiString("/pub/WWW/TheProject.html"))
|
||||||
@ -202,7 +200,7 @@ public class HttpToHttp2ConnectionHandlerTest {
|
|||||||
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET,
|
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET,
|
||||||
"http://foouser@www.example.org:5555/pub/WWW/TheProject.html");
|
"http://foouser@www.example.org:5555/pub/WWW/TheProject.html");
|
||||||
final HttpHeaders httpHeaders = request.headers();
|
final HttpHeaders httpHeaders = request.headers();
|
||||||
httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
|
httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
|
||||||
final Http2Headers http2Headers =
|
final Http2Headers http2Headers =
|
||||||
new DefaultHttp2Headers().method(new AsciiString("GET"))
|
new DefaultHttp2Headers().method(new AsciiString("GET"))
|
||||||
.path(new AsciiString("/pub/WWW/TheProject.html"))
|
.path(new AsciiString("/pub/WWW/TheProject.html"))
|
||||||
@ -217,7 +215,7 @@ public class HttpToHttp2ConnectionHandlerTest {
|
|||||||
bootstrapEnv(2, 1, 0);
|
bootstrapEnv(2, 1, 0);
|
||||||
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, CONNECT, "http://www.example.com:80");
|
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, CONNECT, "http://www.example.com:80");
|
||||||
final HttpHeaders httpHeaders = request.headers();
|
final HttpHeaders httpHeaders = request.headers();
|
||||||
httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
|
httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
|
||||||
final Http2Headers http2Headers =
|
final Http2Headers http2Headers =
|
||||||
new DefaultHttp2Headers().method(new AsciiString("CONNECT")).path(new AsciiString("/"))
|
new DefaultHttp2Headers().method(new AsciiString("CONNECT")).path(new AsciiString("/"))
|
||||||
.scheme(new AsciiString("http")).authority(new AsciiString("www.example.com:80"));
|
.scheme(new AsciiString("http")).authority(new AsciiString("www.example.com:80"));
|
||||||
@ -231,9 +229,9 @@ public class HttpToHttp2ConnectionHandlerTest {
|
|||||||
bootstrapEnv(2, 1, 0);
|
bootstrapEnv(2, 1, 0);
|
||||||
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, OPTIONS, "*");
|
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, OPTIONS, "*");
|
||||||
final HttpHeaders httpHeaders = request.headers();
|
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(HttpHeaderNames.HOST, "www.example.com:80");
|
||||||
httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "http");
|
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "http");
|
||||||
final Http2Headers http2Headers =
|
final Http2Headers http2Headers =
|
||||||
new DefaultHttp2Headers().method(new AsciiString("OPTIONS")).path(new AsciiString("*"))
|
new DefaultHttp2Headers().method(new AsciiString("OPTIONS")).path(new AsciiString("*"))
|
||||||
.scheme(new AsciiString("http")).authority(new AsciiString("www.example.com:80"));
|
.scheme(new AsciiString("http")).authority(new AsciiString("www.example.com:80"));
|
||||||
@ -249,9 +247,9 @@ public class HttpToHttp2ConnectionHandlerTest {
|
|||||||
bootstrapEnv(2, 1, 0);
|
bootstrapEnv(2, 1, 0);
|
||||||
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/");
|
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/");
|
||||||
final HttpHeaders httpHeaders = request.headers();
|
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(HttpHeaderNames.HOST, "[::1]:80");
|
||||||
httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "http");
|
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "http");
|
||||||
final Http2Headers http2Headers =
|
final Http2Headers http2Headers =
|
||||||
new DefaultHttp2Headers().method(new AsciiString("GET")).path(new AsciiString("/"))
|
new DefaultHttp2Headers().method(new AsciiString("GET")).path(new AsciiString("/"))
|
||||||
.scheme(new AsciiString("http")).authority(new AsciiString("[::1]:80"));
|
.scheme(new AsciiString("http")).authority(new AsciiString("[::1]:80"));
|
||||||
@ -265,9 +263,9 @@ public class HttpToHttp2ConnectionHandlerTest {
|
|||||||
bootstrapEnv(2, 1, 0);
|
bootstrapEnv(2, 1, 0);
|
||||||
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/");
|
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/");
|
||||||
final HttpHeaders httpHeaders = request.headers();
|
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(HttpHeaderNames.HOST, "localhost:80");
|
||||||
httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "http");
|
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "http");
|
||||||
final Http2Headers http2Headers =
|
final Http2Headers http2Headers =
|
||||||
new DefaultHttp2Headers().method(new AsciiString("GET")).path(new AsciiString("/"))
|
new DefaultHttp2Headers().method(new AsciiString("GET")).path(new AsciiString("/"))
|
||||||
.scheme(new AsciiString("http")).authority(new AsciiString("localhost:80"));
|
.scheme(new AsciiString("http")).authority(new AsciiString("localhost:80"));
|
||||||
@ -281,9 +279,9 @@ public class HttpToHttp2ConnectionHandlerTest {
|
|||||||
bootstrapEnv(2, 1, 0);
|
bootstrapEnv(2, 1, 0);
|
||||||
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/");
|
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/");
|
||||||
final HttpHeaders httpHeaders = request.headers();
|
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(HttpHeaderNames.HOST, "1.2.3.4:80");
|
||||||
httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "http");
|
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "http");
|
||||||
final Http2Headers http2Headers =
|
final Http2Headers http2Headers =
|
||||||
new DefaultHttp2Headers().method(new AsciiString("GET")).path(new AsciiString("/"))
|
new DefaultHttp2Headers().method(new AsciiString("GET")).path(new AsciiString("/"))
|
||||||
.scheme(new AsciiString("http")).authority(new AsciiString("1.2.3.4:80"));
|
.scheme(new AsciiString("http")).authority(new AsciiString("1.2.3.4:80"));
|
||||||
@ -297,7 +295,7 @@ public class HttpToHttp2ConnectionHandlerTest {
|
|||||||
bootstrapEnv(2, 1, 0);
|
bootstrapEnv(2, 1, 0);
|
||||||
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/");
|
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/");
|
||||||
final HttpHeaders httpHeaders = request.headers();
|
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");
|
httpHeaders.set(HttpHeaderNames.HOST, "localhost");
|
||||||
ChannelPromise writePromise = newPromise();
|
ChannelPromise writePromise = newPromise();
|
||||||
ChannelFuture writeFuture = clientChannel.writeAndFlush(request, writePromise);
|
ChannelFuture writeFuture = clientChannel.writeAndFlush(request, writePromise);
|
||||||
|
@ -208,9 +208,9 @@ public class InboundHttp2ToHttpAdapterTest {
|
|||||||
"/some/path/resource2", true);
|
"/some/path/resource2", true);
|
||||||
try {
|
try {
|
||||||
HttpHeaders httpHeaders = request.headers();
|
HttpHeaders httpHeaders = request.headers();
|
||||||
httpHeaders.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "https");
|
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "https");
|
||||||
httpHeaders.set(HttpUtil.ExtensionHeaderNames.AUTHORITY.text(), "example.org");
|
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.AUTHORITY.text(), "example.org");
|
||||||
httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
|
httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
|
||||||
httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
|
httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
|
||||||
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).
|
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).
|
||||||
scheme(new AsciiString("https")).authority(new AsciiString("example.org"))
|
scheme(new AsciiString("https")).authority(new AsciiString("example.org"))
|
||||||
@ -260,7 +260,7 @@ public class InboundHttp2ToHttpAdapterTest {
|
|||||||
"/some/path/resource2", content, true);
|
"/some/path/resource2", content, true);
|
||||||
try {
|
try {
|
||||||
HttpHeaders httpHeaders = request.headers();
|
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.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
|
||||||
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path(
|
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path(
|
||||||
new AsciiString("/some/path/resource2"));
|
new AsciiString("/some/path/resource2"));
|
||||||
@ -290,7 +290,7 @@ public class InboundHttp2ToHttpAdapterTest {
|
|||||||
"/some/path/resource2", content, true);
|
"/some/path/resource2", content, true);
|
||||||
try {
|
try {
|
||||||
HttpHeaders httpHeaders = request.headers();
|
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.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
|
||||||
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path(
|
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path(
|
||||||
new AsciiString("/some/path/resource2"));
|
new AsciiString("/some/path/resource2"));
|
||||||
@ -324,7 +324,7 @@ public class InboundHttp2ToHttpAdapterTest {
|
|||||||
"/some/path/resource2", content, true);
|
"/some/path/resource2", content, true);
|
||||||
try {
|
try {
|
||||||
HttpHeaders httpHeaders = request.headers();
|
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.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
|
||||||
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path(
|
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path(
|
||||||
new AsciiString("/some/path/resource2"));
|
new AsciiString("/some/path/resource2"));
|
||||||
@ -358,7 +358,7 @@ public class InboundHttp2ToHttpAdapterTest {
|
|||||||
"/some/path/resource2", content, true);
|
"/some/path/resource2", content, true);
|
||||||
try {
|
try {
|
||||||
HttpHeaders httpHeaders = request.headers();
|
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.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
|
||||||
HttpHeaders trailingHeaders = request.trailingHeaders();
|
HttpHeaders trailingHeaders = request.trailingHeaders();
|
||||||
trailingHeaders.set("FoO", "goo");
|
trailingHeaders.set("FoO", "goo");
|
||||||
@ -397,7 +397,7 @@ public class InboundHttp2ToHttpAdapterTest {
|
|||||||
"/some/path/resource2", content, true);
|
"/some/path/resource2", content, true);
|
||||||
try {
|
try {
|
||||||
HttpHeaders httpHeaders = request.headers();
|
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.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
|
||||||
HttpHeaders trailingHeaders = request.trailingHeaders();
|
HttpHeaders trailingHeaders = request.trailingHeaders();
|
||||||
trailingHeaders.set("Foo", "goo");
|
trailingHeaders.set("Foo", "goo");
|
||||||
@ -441,12 +441,12 @@ public class InboundHttp2ToHttpAdapterTest {
|
|||||||
"/some/path/resource2", content2, true);
|
"/some/path/resource2", content2, true);
|
||||||
try {
|
try {
|
||||||
HttpHeaders httpHeaders = request.headers();
|
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.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
|
||||||
HttpHeaders httpHeaders2 = request2.headers();
|
HttpHeaders httpHeaders2 = request2.headers();
|
||||||
httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
|
httpHeaders2.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
|
||||||
httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text(), 3);
|
httpHeaders2.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text(), 3);
|
||||||
httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), 123);
|
httpHeaders2.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), 123);
|
||||||
httpHeaders2.setInt(HttpHeaderNames.CONTENT_LENGTH, text2.length());
|
httpHeaders2.setInt(HttpHeaderNames.CONTENT_LENGTH, text2.length());
|
||||||
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("PUT")).path(
|
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("PUT")).path(
|
||||||
new AsciiString("/some/path/resource"));
|
new AsciiString("/some/path/resource"));
|
||||||
@ -487,22 +487,23 @@ public class InboundHttp2ToHttpAdapterTest {
|
|||||||
final FullHttpMessage request2 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT,
|
final FullHttpMessage request2 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT,
|
||||||
"/some/path/resource2", content2, true);
|
"/some/path/resource2", content2, true);
|
||||||
final FullHttpMessage request3 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
|
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 {
|
try {
|
||||||
HttpHeaders httpHeaders = request.headers();
|
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.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
|
||||||
HttpHeaders httpHeaders2 = request2.headers();
|
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());
|
httpHeaders2.setInt(HttpHeaderNames.CONTENT_LENGTH, text2.length());
|
||||||
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("PUT")).path(
|
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("PUT")).path(
|
||||||
new AsciiString("/some/path/resource"));
|
new AsciiString("/some/path/resource"));
|
||||||
final Http2Headers http2Headers2 = new DefaultHttp2Headers().method(new AsciiString("PUT")).path(
|
final Http2Headers http2Headers2 = new DefaultHttp2Headers().method(new AsciiString("PUT")).path(
|
||||||
new AsciiString("/some/path/resource2"));
|
new AsciiString("/some/path/resource2"));
|
||||||
HttpHeaders httpHeaders3 = request3.headers();
|
HttpHeaders httpHeaders3 = request3.headers();
|
||||||
httpHeaders3.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
|
httpHeaders3.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
|
||||||
httpHeaders3.setInt(HttpUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text(), 3);
|
httpHeaders3.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text(), 3);
|
||||||
httpHeaders3.setInt(HttpUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), 222);
|
httpHeaders3.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), 222);
|
||||||
httpHeaders3.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
|
httpHeaders3.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
|
||||||
runInChannel(clientChannel, new Http2Runnable() {
|
runInChannel(clientChannel, new Http2Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -544,17 +545,17 @@ public class InboundHttp2ToHttpAdapterTest {
|
|||||||
true);
|
true);
|
||||||
try {
|
try {
|
||||||
HttpHeaders httpHeaders = response.headers();
|
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.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
|
||||||
HttpHeaders httpHeaders2 = response2.headers();
|
HttpHeaders httpHeaders2 = response2.headers();
|
||||||
httpHeaders2.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "https");
|
httpHeaders2.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "https");
|
||||||
httpHeaders2.set(HttpUtil.ExtensionHeaderNames.AUTHORITY.text(), "example.org");
|
httpHeaders2.set(HttpConversionUtil.ExtensionHeaderNames.AUTHORITY.text(), "example.org");
|
||||||
httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
|
httpHeaders2.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
|
||||||
httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_PROMISE_ID.text(), 3);
|
httpHeaders2.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_PROMISE_ID.text(), 3);
|
||||||
httpHeaders2.setInt(HttpHeaderNames.CONTENT_LENGTH, text2.length());
|
httpHeaders2.setInt(HttpHeaderNames.CONTENT_LENGTH, text2.length());
|
||||||
|
|
||||||
httpHeaders = request.headers();
|
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);
|
httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
|
||||||
final Http2Headers http2Headers3 = new DefaultHttp2Headers().method(new AsciiString("GET"))
|
final Http2Headers http2Headers3 = new DefaultHttp2Headers().method(new AsciiString("GET"))
|
||||||
.path(new AsciiString("/push/test"));
|
.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",
|
final FullHttpMessage request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "/info/test",
|
||||||
true);
|
true);
|
||||||
HttpHeaders httpHeaders = request.headers();
|
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.set(HttpHeaderNames.EXPECT, HttpHeaderValues.CONTINUE);
|
||||||
httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
|
httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
|
||||||
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("PUT"))
|
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("PUT"))
|
||||||
@ -633,7 +634,7 @@ public class InboundHttp2ToHttpAdapterTest {
|
|||||||
reset(serverListener);
|
reset(serverListener);
|
||||||
|
|
||||||
httpHeaders = response.headers();
|
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);
|
httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
|
||||||
final Http2Headers http2HeadersResponse = new DefaultHttp2Headers().status(new AsciiString("100"));
|
final Http2Headers http2HeadersResponse = new DefaultHttp2Headers().status(new AsciiString("100"));
|
||||||
runInChannel(serverConnectedChannel, new Http2Runnable() {
|
runInChannel(serverConnectedChannel, new Http2Runnable() {
|
||||||
@ -670,7 +671,7 @@ public class InboundHttp2ToHttpAdapterTest {
|
|||||||
|
|
||||||
setClientLatch(1);
|
setClientLatch(1);
|
||||||
httpHeaders = response2.headers();
|
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);
|
httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
|
||||||
final Http2Headers http2HeadersResponse2 = new DefaultHttp2Headers().status(new AsciiString("200"));
|
final Http2Headers http2HeadersResponse2 = new DefaultHttp2Headers().status(new AsciiString("200"));
|
||||||
runInChannel(serverConnectedChannel, new Http2Runnable() {
|
runInChannel(serverConnectedChannel, new Http2Runnable() {
|
||||||
|
@ -30,7 +30,7 @@ import io.netty.handler.codec.http.FullHttpRequest;
|
|||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
import io.netty.handler.codec.http.FullHttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpChunkedInput;
|
import io.netty.handler.codec.http.HttpChunkedInput;
|
||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
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.HttpHeaderValues;
|
||||||
import io.netty.handler.codec.http.HttpResponse;
|
import io.netty.handler.codec.http.HttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
@ -175,10 +175,10 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
|
|||||||
long fileLength = raf.length();
|
long fileLength = raf.length();
|
||||||
|
|
||||||
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
|
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
|
||||||
HttpHeaderUtil.setContentLength(response, fileLength);
|
HttpUtil.setContentLength(response, fileLength);
|
||||||
setContentTypeHeader(response, file);
|
setContentTypeHeader(response, file);
|
||||||
setDateAndCacheHeaders(response, file);
|
setDateAndCacheHeaders(response, file);
|
||||||
if (HttpHeaderUtil.isKeepAlive(request)) {
|
if (HttpUtil.isKeepAlive(request)) {
|
||||||
response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
|
response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Decide whether to close the connection or not.
|
// Decide whether to close the connection or not.
|
||||||
if (!HttpHeaderUtil.isKeepAlive(request)) {
|
if (!HttpUtil.isKeepAlive(request)) {
|
||||||
// Close the connection when the whole content is written out.
|
// Close the connection when the whole content is written out.
|
||||||
lastContentFuture.addListener(ChannelFutureListener.CLOSE);
|
lastContentFuture.addListener(ChannelFutureListener.CLOSE);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
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.HttpRequest;
|
import io.netty.handler.codec.http.HttpRequest;
|
||||||
import io.netty.util.AsciiString;
|
import io.netty.util.AsciiString;
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
||||||
@ -45,10 +45,10 @@ public class HttpHelloWorldServerHandler extends ChannelInboundHandlerAdapter {
|
|||||||
if (msg instanceof HttpRequest) {
|
if (msg instanceof HttpRequest) {
|
||||||
HttpRequest req = (HttpRequest) msg;
|
HttpRequest req = (HttpRequest) msg;
|
||||||
|
|
||||||
if (HttpHeaderUtil.is100ContinueExpected(req)) {
|
if (HttpUtil.is100ContinueExpected(req)) {
|
||||||
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
|
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
|
||||||
}
|
}
|
||||||
boolean keepAlive = HttpHeaderUtil.isKeepAlive(req);
|
boolean keepAlive = HttpUtil.isKeepAlive(req);
|
||||||
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(CONTENT));
|
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(CONTENT));
|
||||||
response.headers().set(CONTENT_TYPE, "text/plain");
|
response.headers().set(CONTENT_TYPE, "text/plain");
|
||||||
response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());
|
response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());
|
||||||
|
@ -18,7 +18,7 @@ package io.netty.example.http.snoop;
|
|||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import io.netty.handler.codec.http.HttpContent;
|
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.HttpObject;
|
||||||
import io.netty.handler.codec.http.HttpResponse;
|
import io.netty.handler.codec.http.HttpResponse;
|
||||||
import io.netty.handler.codec.http.LastHttpContent;
|
import io.netty.handler.codec.http.LastHttpContent;
|
||||||
@ -44,7 +44,7 @@ public class HttpSnoopClientHandler extends SimpleChannelInboundHandler<HttpObje
|
|||||||
System.err.println();
|
System.err.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HttpHeaderUtil.isTransferEncodingChunked(response)) {
|
if (HttpUtil.isTransferEncodingChunked(response)) {
|
||||||
System.err.println("CHUNKED CONTENT {");
|
System.err.println("CHUNKED CONTENT {");
|
||||||
} else {
|
} else {
|
||||||
System.err.println("CONTENT {");
|
System.err.println("CONTENT {");
|
||||||
|
@ -25,7 +25,7 @@ import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
|||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
import io.netty.handler.codec.http.FullHttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpContent;
|
import io.netty.handler.codec.http.HttpContent;
|
||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
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.HttpHeaderValues;
|
||||||
import io.netty.handler.codec.http.HttpHeaders;
|
import io.netty.handler.codec.http.HttpHeaders;
|
||||||
import io.netty.handler.codec.http.HttpObject;
|
import io.netty.handler.codec.http.HttpObject;
|
||||||
@ -61,7 +61,7 @@ public class HttpSnoopServerHandler extends SimpleChannelInboundHandler<Object>
|
|||||||
if (msg instanceof HttpRequest) {
|
if (msg instanceof HttpRequest) {
|
||||||
HttpRequest request = this.request = (HttpRequest) msg;
|
HttpRequest request = this.request = (HttpRequest) msg;
|
||||||
|
|
||||||
if (HttpHeaderUtil.is100ContinueExpected(request)) {
|
if (HttpUtil.is100ContinueExpected(request)) {
|
||||||
send100Continue(ctx);
|
send100Continue(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ public class HttpSnoopServerHandler extends SimpleChannelInboundHandler<Object>
|
|||||||
|
|
||||||
private boolean writeResponse(HttpObject currentObj, ChannelHandlerContext ctx) {
|
private boolean writeResponse(HttpObject currentObj, ChannelHandlerContext ctx) {
|
||||||
// Decide whether to close the connection or not.
|
// Decide whether to close the connection or not.
|
||||||
boolean keepAlive = HttpHeaderUtil.isKeepAlive(request);
|
boolean keepAlive = HttpUtil.isKeepAlive(request);
|
||||||
// Build the response object.
|
// Build the response object.
|
||||||
FullHttpResponse response = new DefaultFullHttpResponse(
|
FullHttpResponse response = new DefaultFullHttpResponse(
|
||||||
HTTP_1_1, currentObj.decoderResult().isSuccess()? OK : BAD_REQUEST,
|
HTTP_1_1, currentObj.decoderResult().isSuccess()? OK : BAD_REQUEST,
|
||||||
|
@ -18,7 +18,7 @@ package io.netty.example.http.upload;
|
|||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import io.netty.handler.codec.http.HttpContent;
|
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.HttpObject;
|
||||||
import io.netty.handler.codec.http.HttpResponse;
|
import io.netty.handler.codec.http.HttpResponse;
|
||||||
import io.netty.handler.codec.http.LastHttpContent;
|
import io.netty.handler.codec.http.LastHttpContent;
|
||||||
@ -47,7 +47,7 @@ public class HttpUploadClientHandler extends SimpleChannelInboundHandler<HttpObj
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.status().code() == 200 && HttpHeaderUtil.isTransferEncodingChunked(response)) {
|
if (response.status().code() == 200 && HttpUtil.isTransferEncodingChunked(response)) {
|
||||||
readingChunks = true;
|
readingChunks = true;
|
||||||
System.err.println("CHUNKED CONTENT {");
|
System.err.println("CHUNKED CONTENT {");
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,7 +25,7 @@ import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
|||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
import io.netty.handler.codec.http.FullHttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpContent;
|
import io.netty.handler.codec.http.HttpContent;
|
||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
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.HttpHeaderValues;
|
||||||
import io.netty.handler.codec.http.HttpMethod;
|
import io.netty.handler.codec.http.HttpMethod;
|
||||||
import io.netty.handler.codec.http.HttpObject;
|
import io.netty.handler.codec.http.HttpObject;
|
||||||
@ -162,7 +162,7 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
readingChunks = HttpHeaderUtil.isTransferEncodingChunked(request);
|
readingChunks = HttpUtil.isTransferEncodingChunked(request);
|
||||||
responseContent.append("Is Chunked: " + readingChunks + "\r\n");
|
responseContent.append("Is Chunked: " + readingChunks + "\r\n");
|
||||||
responseContent.append("IsMultipart: " + decoder.isMultipart() + "\r\n");
|
responseContent.append("IsMultipart: " + decoder.isMultipart() + "\r\n");
|
||||||
if (readingChunks) {
|
if (readingChunks) {
|
||||||
|
@ -25,7 +25,7 @@ import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
|||||||
import io.netty.handler.codec.http.FullHttpRequest;
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
import io.netty.handler.codec.http.FullHttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
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.websocketx.BinaryWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
|
||||||
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
|
||||||
import io.netty.handler.codec.http.websocketx.PingWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.PingWebSocketFrame;
|
||||||
@ -82,7 +82,7 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
|
|||||||
FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
|
FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
|
||||||
|
|
||||||
res.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=UTF-8");
|
res.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=UTF-8");
|
||||||
HttpHeaderUtil.setContentLength(res, content.readableBytes());
|
HttpUtil.setContentLength(res, content.readableBytes());
|
||||||
|
|
||||||
sendHttpResponse(ctx, req, res);
|
sendHttpResponse(ctx, req, res);
|
||||||
return;
|
return;
|
||||||
@ -134,12 +134,12 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
|
|||||||
ByteBuf buf = Unpooled.copiedBuffer(res.status().toString(), CharsetUtil.UTF_8);
|
ByteBuf buf = Unpooled.copiedBuffer(res.status().toString(), CharsetUtil.UTF_8);
|
||||||
res.content().writeBytes(buf);
|
res.content().writeBytes(buf);
|
||||||
buf.release();
|
buf.release();
|
||||||
HttpHeaderUtil.setContentLength(res, res.content().readableBytes());
|
HttpUtil.setContentLength(res, res.content().readableBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the response and close the connection if necessary.
|
// Send the response and close the connection if necessary.
|
||||||
ChannelFuture f = ctx.channel().writeAndFlush(res);
|
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);
|
f.addListener(ChannelFutureListener.CLOSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
|||||||
import io.netty.handler.codec.http.FullHttpRequest;
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
import io.netty.handler.codec.http.FullHttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
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.websocketx.CloseWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
|
||||||
import io.netty.handler.codec.http.websocketx.PingWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.PingWebSocketFrame;
|
||||||
import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
|
||||||
@ -81,7 +81,7 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
|
|||||||
FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
|
FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
|
||||||
|
|
||||||
res.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=UTF-8");
|
res.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=UTF-8");
|
||||||
HttpHeaderUtil.setContentLength(res, content.readableBytes());
|
HttpUtil.setContentLength(res, content.readableBytes());
|
||||||
|
|
||||||
sendHttpResponse(ctx, req, res);
|
sendHttpResponse(ctx, req, res);
|
||||||
return;
|
return;
|
||||||
@ -132,12 +132,12 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
|
|||||||
ByteBuf buf = Unpooled.copiedBuffer(res.status().toString(), CharsetUtil.UTF_8);
|
ByteBuf buf = Unpooled.copiedBuffer(res.status().toString(), CharsetUtil.UTF_8);
|
||||||
res.content().writeBytes(buf);
|
res.content().writeBytes(buf);
|
||||||
buf.release();
|
buf.release();
|
||||||
HttpHeaderUtil.setContentLength(res, res.content().readableBytes());
|
HttpUtil.setContentLength(res, res.content().readableBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the response and close the connection if necessary.
|
// Send the response and close the connection if necessary.
|
||||||
ChannelFuture f = ctx.channel().writeAndFlush(res);
|
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);
|
f.addListener(ChannelFutureListener.CLOSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.channel.ChannelPromise;
|
import io.netty.channel.ChannelPromise;
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
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 io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -76,7 +76,7 @@ public class HttpResponseHandler extends SimpleChannelInboundHandler<FullHttpRes
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg) throws Exception {
|
protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg) throws Exception {
|
||||||
Integer streamId = msg.headers().getInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text());
|
Integer streamId = msg.headers().getInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text());
|
||||||
if (streamId == null) {
|
if (streamId == null) {
|
||||||
System.err.println("HttpResponseHandler unexpected message received: " + msg);
|
System.err.println("HttpResponseHandler unexpected message received: " + msg);
|
||||||
return;
|
return;
|
||||||
|
@ -31,7 +31,7 @@ import io.netty.channel.SimpleChannelInboundHandler;
|
|||||||
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
||||||
import io.netty.handler.codec.http.FullHttpRequest;
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
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.HttpHeaderValues;
|
import io.netty.handler.codec.http.HttpHeaderValues;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,10 +46,10 @@ public class HelloWorldHttp1Handler extends SimpleChannelInboundHandler<FullHttp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
|
public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
|
||||||
if (HttpHeaderUtil.is100ContinueExpected(req)) {
|
if (HttpUtil.is100ContinueExpected(req)) {
|
||||||
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
|
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
|
||||||
}
|
}
|
||||||
boolean keepAlive = HttpHeaderUtil.isKeepAlive(req);
|
boolean keepAlive = HttpUtil.isKeepAlive(req);
|
||||||
|
|
||||||
ByteBuf content = ctx.alloc().buffer();
|
ByteBuf content = ctx.alloc().buffer();
|
||||||
content.writeBytes(HelloWorldHttp2Handler.RESPONSE_BYTES.duplicate());
|
content.writeBytes(HelloWorldHttp2Handler.RESPONSE_BYTES.duplicate());
|
||||||
|
@ -31,7 +31,7 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
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.HttpRequest;
|
import io.netty.handler.codec.http.HttpRequest;
|
||||||
import io.netty.handler.codec.http2.Http2CodecUtil;
|
import io.netty.handler.codec.http2.Http2CodecUtil;
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ public final class FallbackRequestHandler extends SimpleChannelInboundHandler<Ht
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void channelRead0(ChannelHandlerContext ctx, HttpRequest req) throws Exception {
|
protected void channelRead0(ChannelHandlerContext ctx, HttpRequest req) throws Exception {
|
||||||
if (HttpHeaderUtil.is100ContinueExpected(req)) {
|
if (HttpUtil.is100ContinueExpected(req)) {
|
||||||
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
|
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package io.netty.example.http2.tiles;
|
package io.netty.example.http2.tiles;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpHeaderNames.CONNECTION;
|
import static io.netty.handler.codec.http.HttpHeaderNames.CONNECTION;
|
||||||
import static io.netty.handler.codec.http.HttpHeaderUtil.isKeepAlive;
|
import static io.netty.handler.codec.http.HttpUtil.isKeepAlive;
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.CONTINUE;
|
import static io.netty.handler.codec.http.HttpResponseStatus.CONTINUE;
|
||||||
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
@ -25,7 +25,7 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
||||||
import io.netty.handler.codec.http.FullHttpRequest;
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
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.HttpHeaderValues;
|
import io.netty.handler.codec.http.HttpHeaderValues;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -37,7 +37,7 @@ public final class Http1RequestHandler extends Http2RequestHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
|
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
|
||||||
if (HttpHeaderUtil.is100ContinueExpected(request)) {
|
if (HttpUtil.is100ContinueExpected(request)) {
|
||||||
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
|
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
|
||||||
}
|
}
|
||||||
super.channelRead0(ctx, request);
|
super.channelRead0(ctx, request);
|
||||||
@ -46,7 +46,7 @@ public final class Http1RequestHandler extends Http2RequestHandler {
|
|||||||
@Override
|
@Override
|
||||||
protected void sendResponse(final ChannelHandlerContext ctx, String streamId, int latency,
|
protected void sendResponse(final ChannelHandlerContext ctx, String streamId, int latency,
|
||||||
final FullHttpResponse response, final FullHttpRequest request) {
|
final FullHttpResponse response, final FullHttpRequest request) {
|
||||||
HttpHeaderUtil.setContentLength(response, response.content().readableBytes());
|
HttpUtil.setContentLength(response, response.content().readableBytes());
|
||||||
ctx.executor().schedule(new Runnable() {
|
ctx.executor().schedule(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -20,7 +20,7 @@ import static io.netty.buffer.Unpooled.EMPTY_BUFFER;
|
|||||||
import static io.netty.example.http2.Http2ExampleUtil.firstValue;
|
import static io.netty.example.http2.Http2ExampleUtil.firstValue;
|
||||||
import static io.netty.example.http2.Http2ExampleUtil.toInt;
|
import static io.netty.example.http2.Http2ExampleUtil.toInt;
|
||||||
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE;
|
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE;
|
||||||
import static io.netty.handler.codec.http.HttpHeaderUtil.setContentLength;
|
import static io.netty.handler.codec.http.HttpUtil.setContentLength;
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;
|
import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
|
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
|
||||||
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
||||||
@ -32,7 +32,7 @@ import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
|||||||
import io.netty.handler.codec.http.FullHttpRequest;
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
import io.netty.handler.codec.http.FullHttpResponse;
|
||||||
import io.netty.handler.codec.http.QueryStringDecoder;
|
import io.netty.handler.codec.http.QueryStringDecoder;
|
||||||
import io.netty.handler.codec.http2.HttpUtil;
|
import io.netty.handler.codec.http2.HttpConversionUtil;
|
||||||
import io.netty.handler.codec.http2.InboundHttp2ToHttpAdapter;
|
import io.netty.handler.codec.http2.InboundHttp2ToHttpAdapter;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -107,11 +107,11 @@ public class Http2RequestHandler extends SimpleChannelInboundHandler<FullHttpReq
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String streamId(FullHttpRequest request) {
|
private String streamId(FullHttpRequest request) {
|
||||||
return request.headers().get(HttpUtil.ExtensionHeaderNames.STREAM_ID.text());
|
return request.headers().get(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void streamId(FullHttpResponse response, String streamId) {
|
private void streamId(FullHttpResponse response, String streamId) {
|
||||||
response.headers().set(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), streamId);
|
response.headers().set(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), streamId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,7 +20,7 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import io.netty.example.http.snoop.HttpSnoopClientHandler;
|
import io.netty.example.http.snoop.HttpSnoopClientHandler;
|
||||||
import io.netty.handler.codec.http.HttpContent;
|
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.HttpObject;
|
||||||
import io.netty.handler.codec.http.HttpResponse;
|
import io.netty.handler.codec.http.HttpResponse;
|
||||||
import io.netty.handler.codec.http.LastHttpContent;
|
import io.netty.handler.codec.http.LastHttpContent;
|
||||||
@ -55,7 +55,7 @@ public class HttpResponseClientHandler extends SimpleChannelInboundHandler<HttpO
|
|||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HttpHeaderUtil.isTransferEncodingChunked(response)) {
|
if (HttpUtil.isTransferEncodingChunked(response)) {
|
||||||
System.out.println("CHUNKED CONTENT {");
|
System.out.println("CHUNKED CONTENT {");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("CONTENT {");
|
System.out.println("CONTENT {");
|
||||||
|
@ -29,7 +29,7 @@ import io.netty.util.CharsetUtil;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpHeaderUtil.*;
|
import static io.netty.handler.codec.http.HttpUtil.*;
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
||||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ import io.netty.util.internal.StringUtil;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
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.HttpMethod.*;
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
||||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
|
Loading…
Reference in New Issue
Block a user