Fix backward compatibility from the previous backport

Motivation:

The commit 50e06442c3 changed the type of
the constants in HttpHeaders.Names and HttpHeaders.Values, making 4.1
backward-incompatible with 4.0.

It also introduces newer utility classes such as HttpHeaderUtil, which
deprecates most static methods in HttpHeaders.  To ease the migration
between 4.1 and 5.0, we should deprecate all static methods that are
non-existent in 5.0, and provide proper counterpart.

Modification:

- Revert the changes in HttpHeaders.Names and Values
- Deprecate all static methods in HttpHeaders in favor of:
  - HttpHeaderUtil
  - the member methods of HttpHeaders
  - AsciiString
- Add integer and date access methods to HttpHeaders for easier future
  migration to 5.0
- Add HttpHeaderNames and HttpHeaderValues which provide standard HTTP
  constants in AsciiString
  - Deprecate HttpHeaders.Names and Values
  - Make HttpHeaderValues.WEBSOCKET lowercased because it's actually
    lowercased in all WebSocket versions but the oldest one
- Add RtspHeaderNames and RtspHeaderValues which provide standard RTSP
  constants in AsciiString
  - Deprecate RtspHeaders.*
- Do not use AsciiString.equalsIgnoreCase(CharSeq, CharSeq) if one of
  the parameters are AsciiString
- Avoid using AsciiString.toString() repetitively
  - Change the parameter type of some methods from String to
    CharSequence

Result:

Backward compatibility is recovered.  New classes and methods will make
the migration to 5.0 easier, once (Http|Rtsp)Header(Names|Values) are
ported to master.
This commit is contained in:
Trustin Lee 2014-10-31 16:48:28 +09:00
parent 50e06442c3
commit 4ce994dd4f
72 changed files with 2083 additions and 1077 deletions

View File

@ -22,6 +22,7 @@ import io.netty.handler.codec.DefaultTextHeaders;
import io.netty.handler.codec.DefaultTextHeaders.DefaultTextValueTypeConverter;
import io.netty.handler.codec.TextHeaders;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
@ -297,6 +298,12 @@ public class DefaultHttpHeaders extends HttpHeaders {
return this;
}
@Override
public HttpHeaders addInt(CharSequence name, int value) {
headers.addInt(name, value);
return this;
}
@Override
public HttpHeaders remove(String name) {
headers.remove(name);
@ -333,6 +340,12 @@ public class DefaultHttpHeaders extends HttpHeaders {
return this;
}
@Override
public HttpHeaders setInt(CharSequence name, int value) {
headers.setInt(name, value);
return this;
}
@Override
public HttpHeaders clear() {
headers.clear();
@ -349,6 +362,35 @@ public class DefaultHttpHeaders extends HttpHeaders {
return headers.getAndConvert(name);
}
@Override
public Integer getInt(CharSequence name) {
return headers.getInt(name);
}
@Override
public int getInt(CharSequence name, int defaultValue) {
return headers.getInt(name, defaultValue);
}
@Override
public Date getDate(CharSequence name) {
return getDate(name, null);
}
@Override
public Date getDate(CharSequence name, Date defaultValue) {
String value = get(name);
if (value == null) {
return defaultValue;
}
try {
return HttpHeaderDateFormat.get().parse(value);
} catch (ParseException ignored) {
return defaultValue;
}
}
@Override
public List<String> getAll(String name) {
return headers.getAllAndConvert(name);

View File

@ -68,7 +68,7 @@ public abstract class DefaultHttpMessage extends DefaultHttpObject implements Ht
buf.append("(version: ");
buf.append(protocolVersion().text());
buf.append(", keepAlive: ");
buf.append(HttpHeaders.isKeepAlive(this));
buf.append(HttpHeaderUtil.isKeepAlive(this));
buf.append(')');
buf.append(StringUtil.NEWLINE);
appendHeaders(buf);

View File

@ -17,13 +17,10 @@ package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.AsciiString;
import io.netty.util.internal.StringUtil;
import java.util.Map.Entry;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
/**
* The default {@link LastHttpContent} implementation.
*/
@ -119,9 +116,9 @@ public class DefaultLastHttpContent extends DefaultHttpContent implements LastHt
public CharSequence convertName(CharSequence name) {
name = super.convertName(name);
if (validate) {
if (AsciiString.equalsIgnoreCase(CONTENT_LENGTH, name)
|| AsciiString.equalsIgnoreCase(TRANSFER_ENCODING, name)
|| AsciiString.equalsIgnoreCase(TRAILER, name)) {
if (HttpHeaderNames.CONTENT_LENGTH.equalsIgnoreCase(name)
|| HttpHeaderNames.TRANSFER_ENCODING.equalsIgnoreCase(name)
|| HttpHeaderNames.TRAILER.equalsIgnoreCase(name)) {
throw new IllegalArgumentException("prohibited trailing header: " + name);
}
}

View File

@ -16,7 +16,6 @@
package io.netty.handler.codec.http;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.compression.ZlibCodecFactory;
import io.netty.handler.codec.compression.ZlibWrapper;
import io.netty.util.internal.StringUtil;
@ -95,9 +94,9 @@ public class HttpContentCompressor extends HttpContentEncoder {
@Override
protected Result beginEncode(HttpResponse headers, String acceptEncoding) throws Exception {
String contentEncoding = headers.headers().get(HttpHeaders.Names.CONTENT_ENCODING);
String contentEncoding = headers.headers().get(HttpHeaderNames.CONTENT_ENCODING);
if (contentEncoding != null &&
!AsciiString.equalsIgnoreCase(HttpHeaders.Values.IDENTITY, contentEncoding)) {
!HttpHeaderValues.IDENTITY.equalsIgnoreCase(contentEncoding)) {
return null;
}

View File

@ -44,6 +44,8 @@ import java.util.List;
*/
public abstract class HttpContentDecoder extends MessageToMessageDecoder<HttpObject> {
static final String IDENTITY = HttpHeaderValues.IDENTITY.toString();
private EmbeddedChannel decoder;
private HttpMessage message;
private boolean decodeStarted;
@ -87,30 +89,30 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<HttpObj
this.message = null;
// Determine the content encoding.
String contentEncoding = headers.get(HttpHeaders.Names.CONTENT_ENCODING);
String contentEncoding = headers.get(HttpHeaderNames.CONTENT_ENCODING);
if (contentEncoding != null) {
contentEncoding = contentEncoding.trim();
} else {
contentEncoding = HttpHeaders.Values.IDENTITY;
contentEncoding = IDENTITY;
}
if ((decoder = newContentDecoder(contentEncoding)) != null) {
// Decode the content and remove or replace the existing headers
// so that the message looks like a decoded message.
String targetContentEncoding = getTargetContentEncoding(contentEncoding);
if (HttpHeaders.Values.IDENTITY.equals(targetContentEncoding)) {
if (HttpHeaderValues.IDENTITY.contentEquals(targetContentEncoding)) {
// Do NOT set the 'Content-Encoding' header if the target encoding is 'identity'
// as per: http://tools.ietf.org/html/rfc2616#section-14.11
headers.remove(HttpHeaders.Names.CONTENT_ENCODING);
headers.remove(HttpHeaderNames.CONTENT_ENCODING);
} else {
headers.set(HttpHeaders.Names.CONTENT_ENCODING, targetContentEncoding);
headers.set(HttpHeaderNames.CONTENT_ENCODING, targetContentEncoding);
}
out.add(message);
decodeContent(c, out);
// Replace the content length.
if (headers.contains(HttpHeaders.Names.CONTENT_LENGTH)) {
if (headers.contains(HttpHeaderNames.CONTENT_LENGTH)) {
int contentLength = 0;
int size = out.size();
for (int i = 0; i < size; i++) {
@ -120,7 +122,7 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<HttpObj
}
}
headers.set(
HttpHeaders.Names.CONTENT_LENGTH,
HttpHeaderNames.CONTENT_LENGTH,
Integer.toString(contentLength));
}
return;
@ -186,7 +188,7 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<HttpObj
*/
protected String getTargetContentEncoding(
@SuppressWarnings("UnusedParameters") String contentEncoding) throws Exception {
return HttpHeaders.Values.IDENTITY;
return IDENTITY;
}
@Override

View File

@ -20,8 +20,6 @@ import io.netty.buffer.ByteBufHolder;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.MessageToMessageCodec;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaders.Values;
import io.netty.util.ReferenceCountUtil;
import java.util.ArrayDeque;
@ -71,9 +69,9 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpReque
@Override
protected void decode(ChannelHandlerContext ctx, HttpRequest msg, List<Object> out)
throws Exception {
String acceptedEncoding = msg.headers().get(HttpHeaders.Names.ACCEPT_ENCODING);
String acceptedEncoding = msg.headers().get(HttpHeaderNames.ACCEPT_ENCODING);
if (acceptedEncoding == null) {
acceptedEncoding = HttpHeaders.Values.IDENTITY;
acceptedEncoding = HttpContentDecoder.IDENTITY;
}
acceptEncodingQueue.add(acceptedEncoding);
out.add(ReferenceCountUtil.retain(msg));
@ -133,11 +131,11 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpReque
// Encode the content and remove or replace the existing headers
// so that the message looks like a decoded message.
res.headers().set(Names.CONTENT_ENCODING, result.targetContentEncoding());
res.headers().set(HttpHeaderNames.CONTENT_ENCODING, result.targetContentEncoding());
// Make the response chunked to simplify content transformation.
res.headers().remove(Names.CONTENT_LENGTH);
res.headers().set(Names.TRANSFER_ENCODING, Values.CHUNKED);
res.headers().remove(HttpHeaderNames.CONTENT_LENGTH);
res.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
// Output the rewritten response.
if (isFull) {

View File

@ -0,0 +1,351 @@
/*
* 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.handler.codec.AsciiString;
/**
* Standard HTTP header names.
* <p>
* These are all defined as lowercase to support HTTP/2 requirements while also not
* violating HTTP/1.x requirements. New header names should always be lowercase.
*/
public final class HttpHeaderNames {
/**
* {@code "accept"}
*/
public static final AsciiString ACCEPT = new AsciiString("accept");
/**
* {@code "accept-charset"}
*/
public static final AsciiString ACCEPT_CHARSET = new AsciiString("accept-charset");
/**
* {@code "accept-encoding"}
*/
public static final AsciiString ACCEPT_ENCODING = new AsciiString("accept-encoding");
/**
* {@code "accept-language"}
*/
public static final AsciiString ACCEPT_LANGUAGE = new AsciiString("accept-language");
/**
* {@code "accept-ranges"}
*/
public static final AsciiString ACCEPT_RANGES = new AsciiString("accept-ranges");
/**
* {@code "accept-patch"}
*/
public static final AsciiString ACCEPT_PATCH = new AsciiString("accept-patch");
/**
* {@code "access-control-allow-credentials"}
*/
public static final AsciiString ACCESS_CONTROL_ALLOW_CREDENTIALS =
new AsciiString("access-control-allow-credentials");
/**
* {@code "access-control-allow-headers"}
*/
public static final AsciiString ACCESS_CONTROL_ALLOW_HEADERS =
new AsciiString("access-control-allow-headers");
/**
* {@code "access-control-allow-methods"}
*/
public static final AsciiString ACCESS_CONTROL_ALLOW_METHODS =
new AsciiString("access-control-allow-methods");
/**
* {@code "access-control-allow-origin"}
*/
public static final AsciiString ACCESS_CONTROL_ALLOW_ORIGIN =
new AsciiString("access-control-allow-origin");
/**
* {@code "access-control-expose-headers"}
*/
public static final AsciiString ACCESS_CONTROL_EXPOSE_HEADERS =
new AsciiString("access-control-expose-headers");
/**
* {@code "access-control-max-age"}
*/
public static final AsciiString ACCESS_CONTROL_MAX_AGE = new AsciiString("access-control-max-age");
/**
* {@code "access-control-request-headers"}
*/
public static final AsciiString ACCESS_CONTROL_REQUEST_HEADERS =
new AsciiString("access-control-request-headers");
/**
* {@code "access-control-request-method"}
*/
public static final AsciiString ACCESS_CONTROL_REQUEST_METHOD =
new AsciiString("access-control-request-method");
/**
* {@code "age"}
*/
public static final AsciiString AGE = new AsciiString("age");
/**
* {@code "allow"}
*/
public static final AsciiString ALLOW = new AsciiString("allow");
/**
* {@code "authorization"}
*/
public static final AsciiString AUTHORIZATION = new AsciiString("authorization");
/**
* {@code "cache-control"}
*/
public static final AsciiString CACHE_CONTROL = new AsciiString("cache-control");
/**
* {@code "connection"}
*/
public static final AsciiString CONNECTION = new AsciiString("connection");
/**
* {@code "content-base"}
*/
public static final AsciiString CONTENT_BASE = new AsciiString("content-base");
/**
* {@code "content-encoding"}
*/
public static final AsciiString CONTENT_ENCODING = new AsciiString("content-encoding");
/**
* {@code "content-language"}
*/
public static final AsciiString CONTENT_LANGUAGE = new AsciiString("content-language");
/**
* {@code "content-length"}
*/
public static final AsciiString CONTENT_LENGTH = new AsciiString("content-length");
/**
* {@code "content-location"}
*/
public static final AsciiString CONTENT_LOCATION = new AsciiString("content-location");
/**
* {@code "content-transfer-encoding"}
*/
public static final AsciiString CONTENT_TRANSFER_ENCODING = new AsciiString("content-transfer-encoding");
/**
* {@code "content-disposition"}
*/
public static final AsciiString CONTENT_DISPOSITION = new AsciiString("content-disposition");
/**
* {@code "content-md5"}
*/
public static final AsciiString CONTENT_MD5 = new AsciiString("content-md5");
/**
* {@code "content-range"}
*/
public static final AsciiString CONTENT_RANGE = new AsciiString("content-range");
/**
* {@code "content-type"}
*/
public static final AsciiString CONTENT_TYPE = new AsciiString("content-type");
/**
* {@code "cookie"}
*/
public static final AsciiString COOKIE = new AsciiString("cookie");
/**
* {@code "date"}
*/
public static final AsciiString DATE = new AsciiString("date");
/**
* {@code "etag"}
*/
public static final AsciiString ETAG = new AsciiString("etag");
/**
* {@code "expect"}
*/
public static final AsciiString EXPECT = new AsciiString("expect");
/**
* {@code "expires"}
*/
public static final AsciiString EXPIRES = new AsciiString("expires");
/**
* {@code "from"}
*/
public static final AsciiString FROM = new AsciiString("from");
/**
* {@code "host"}
*/
public static final AsciiString HOST = new AsciiString("host");
/**
* {@code "if-match"}
*/
public static final AsciiString IF_MATCH = new AsciiString("if-match");
/**
* {@code "if-modified-since"}
*/
public static final AsciiString IF_MODIFIED_SINCE = new AsciiString("if-modified-since");
/**
* {@code "if-none-match"}
*/
public static final AsciiString IF_NONE_MATCH = new AsciiString("if-none-match");
/**
* {@code "if-range"}
*/
public static final AsciiString IF_RANGE = new AsciiString("if-range");
/**
* {@code "if-unmodified-since"}
*/
public static final AsciiString IF_UNMODIFIED_SINCE = new AsciiString("if-unmodified-since");
/**
* @deprecated use {@link #CONNECTION}
*
* {@code "keep-alive"}
*/
@Deprecated
public static final AsciiString KEEP_ALIVE = new AsciiString("keep-alive");
/**
* {@code "last-modified"}
*/
public static final AsciiString LAST_MODIFIED = new AsciiString("last-modified");
/**
* {@code "location"}
*/
public static final AsciiString LOCATION = new AsciiString("location");
/**
* {@code "max-forwards"}
*/
public static final AsciiString MAX_FORWARDS = new AsciiString("max-forwards");
/**
* {@code "origin"}
*/
public static final AsciiString ORIGIN = new AsciiString("origin");
/**
* {@code "pragma"}
*/
public static final AsciiString PRAGMA = new AsciiString("pragma");
/**
* {@code "proxy-authenticate"}
*/
public static final AsciiString PROXY_AUTHENTICATE = new AsciiString("proxy-authenticate");
/**
* {@code "proxy-authorization"}
*/
public static final AsciiString PROXY_AUTHORIZATION = new AsciiString("proxy-authorization");
/**
* @deprecated use {@link #CONNECTION}
*
* {@code "proxy-connection"}
*/
@Deprecated
public static final AsciiString PROXY_CONNECTION = new AsciiString("proxy-connection");
/**
* {@code "range"}
*/
public static final AsciiString RANGE = new AsciiString("range");
/**
* {@code "referer"}
*/
public static final AsciiString REFERER = new AsciiString("referer");
/**
* {@code "retry-after"}
*/
public static final AsciiString RETRY_AFTER = new AsciiString("retry-after");
/**
* {@code "sec-websocket-key1"}
*/
public static final AsciiString SEC_WEBSOCKET_KEY1 = new AsciiString("sec-websocket-key1");
/**
* {@code "sec-websocket-key2"}
*/
public static final AsciiString SEC_WEBSOCKET_KEY2 = new AsciiString("sec-websocket-key2");
/**
* {@code "sec-websocket-location"}
*/
public static final AsciiString SEC_WEBSOCKET_LOCATION = new AsciiString("sec-websocket-location");
/**
* {@code "sec-websocket-origin"}
*/
public static final AsciiString SEC_WEBSOCKET_ORIGIN = new AsciiString("sec-websocket-origin");
/**
* {@code "sec-websocket-protocol"}
*/
public static final AsciiString SEC_WEBSOCKET_PROTOCOL = new AsciiString("sec-websocket-protocol");
/**
* {@code "sec-websocket-version"}
*/
public static final AsciiString SEC_WEBSOCKET_VERSION = new AsciiString("sec-websocket-version");
/**
* {@code "sec-websocket-key"}
*/
public static final AsciiString SEC_WEBSOCKET_KEY = new AsciiString("sec-websocket-key");
/**
* {@code "sec-websocket-accept"}
*/
public static final AsciiString SEC_WEBSOCKET_ACCEPT = new AsciiString("sec-websocket-accept");
/**
* {@code "sec-websocket-protocol"}
*/
public static final AsciiString SEC_WEBSOCKET_EXTENSIONS = new AsciiString("sec-websocket-extensions");
/**
* {@code "server"}
*/
public static final AsciiString SERVER = new AsciiString("server");
/**
* {@code "set-cookie"}
*/
public static final AsciiString SET_COOKIE = new AsciiString("set-cookie");
/**
* {@code "set-cookie2"}
*/
public static final AsciiString SET_COOKIE2 = new AsciiString("set-cookie2");
/**
* {@code "te"}
*/
public static final AsciiString TE = new AsciiString("te");
/**
* {@code "trailer"}
*/
public static final AsciiString TRAILER = new AsciiString("trailer");
/**
* {@code "transfer-encoding"}
*/
public static final AsciiString TRANSFER_ENCODING = new AsciiString("transfer-encoding");
/**
* {@code "upgrade"}
*/
public static final AsciiString UPGRADE = new AsciiString("upgrade");
/**
* {@code "user-agent"}
*/
public static final AsciiString USER_AGENT = new AsciiString("user-agent");
/**
* {@code "vary"}
*/
public static final AsciiString VARY = new AsciiString("vary");
/**
* {@code "via"}
*/
public static final AsciiString VIA = new AsciiString("via");
/**
* {@code "warning"}
*/
public static final AsciiString WARNING = new AsciiString("warning");
/**
* {@code "websocket-location"}
*/
public static final AsciiString WEBSOCKET_LOCATION = new AsciiString("websocket-location");
/**
* {@code "websocket-origin"}
*/
public static final AsciiString WEBSOCKET_ORIGIN = new AsciiString("websocket-origin");
/**
* {@code "websocket-protocol"}
*/
public static final AsciiString WEBSOCKET_PROTOCOL = new AsciiString("websocket-protocol");
/**
* {@code "www-authenticate"}
*/
public static final AsciiString WWW_AUTHENTICATE = new AsciiString("www-authenticate");
private HttpHeaderNames() { }
}

View File

@ -17,9 +17,6 @@
package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaders.Values;
import java.util.Iterator;
import java.util.List;
@ -33,15 +30,15 @@ public final class HttpHeaderUtil {
* {@link HttpVersion#isKeepAliveDefault()}.
*/
public static boolean isKeepAlive(HttpMessage message) {
CharSequence connection = message.headers().get(Names.CONNECTION);
if (connection != null && AsciiString.equalsIgnoreCase(Values.CLOSE, connection)) {
CharSequence connection = message.headers().get(HttpHeaderNames.CONNECTION);
if (connection != null && HttpHeaderValues.CLOSE.equalsIgnoreCase(connection)) {
return false;
}
if (message.protocolVersion().isKeepAliveDefault()) {
return !AsciiString.equalsIgnoreCase(Values.CLOSE, connection);
return !HttpHeaderValues.CLOSE.equalsIgnoreCase(connection);
} else {
return AsciiString.equalsIgnoreCase(Values.KEEP_ALIVE, connection);
return HttpHeaderValues.KEEP_ALIVE.equalsIgnoreCase(connection);
}
}
@ -68,15 +65,15 @@ public final class HttpHeaderUtil {
HttpHeaders h = message.headers();
if (message.protocolVersion().isKeepAliveDefault()) {
if (keepAlive) {
h.remove(Names.CONNECTION);
h.remove(HttpHeaderNames.CONNECTION);
} else {
h.set(Names.CONNECTION, Values.CLOSE);
h.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
}
} else {
if (keepAlive) {
h.set(Names.CONNECTION, Values.KEEP_ALIVE);
h.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
} else {
h.remove(Names.CONNECTION);
h.remove(HttpHeaderNames.CONNECTION);
}
}
}
@ -94,7 +91,7 @@ public final class HttpHeaderUtil {
* or its value is not a number
*/
public static long getContentLength(HttpMessage message) {
String value = message.headers().get(Names.CONTENT_LENGTH);
String value = message.headers().get(HttpHeaderNames.CONTENT_LENGTH);
if (value != null) {
return Long.parseLong(value);
}
@ -107,7 +104,7 @@ public final class HttpHeaderUtil {
}
// Otherwise we don't.
throw new NumberFormatException("header not found: " + Names.CONTENT_LENGTH);
throw new NumberFormatException("header not found: " + HttpHeaderNames.CONTENT_LENGTH);
}
/**
@ -121,7 +118,7 @@ public final class HttpHeaderUtil {
* a number
*/
public static long getContentLength(HttpMessage message, long defaultValue) {
String value = message.headers().get(Names.CONTENT_LENGTH);
String value = message.headers().get(HttpHeaderNames.CONTENT_LENGTH);
if (value != null) {
return Long.parseLong(value);
}
@ -147,15 +144,15 @@ public final class HttpHeaderUtil {
if (message instanceof HttpRequest) {
HttpRequest req = (HttpRequest) message;
if (HttpMethod.GET.equals(req.method()) &&
h.contains(Names.SEC_WEBSOCKET_KEY1) &&
h.contains(Names.SEC_WEBSOCKET_KEY2)) {
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(Names.SEC_WEBSOCKET_ORIGIN) &&
h.contains(Names.SEC_WEBSOCKET_LOCATION)) {
h.contains(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN) &&
h.contains(HttpHeaderNames.SEC_WEBSOCKET_LOCATION)) {
return 16;
}
}
@ -168,11 +165,11 @@ public final class HttpHeaderUtil {
* Sets the {@code "Content-Length"} header.
*/
public static void setContentLength(HttpMessage message, long length) {
message.headers().set(Names.CONTENT_LENGTH, length);
message.headers().set(HttpHeaderNames.CONTENT_LENGTH, length);
}
public static boolean isContentLengthSet(HttpMessage m) {
return m.headers().contains(Names.CONTENT_LENGTH);
return m.headers().contains(HttpHeaderNames.CONTENT_LENGTH);
}
/**
@ -191,16 +188,16 @@ public final class HttpHeaderUtil {
}
// In most cases, there will be one or zero 'Expect' header.
CharSequence value = message.headers().get(Names.EXPECT);
CharSequence value = message.headers().get(HttpHeaderNames.EXPECT);
if (value == null) {
return false;
}
if (AsciiString.equalsIgnoreCase(Values.CONTINUE, value)) {
if (HttpHeaderValues.CONTINUE.equalsIgnoreCase(value)) {
return true;
}
// Multiple 'Expect' headers. Search through them.
return message.headers().contains(Names.EXPECT, Values.CONTINUE, true);
return message.headers().contains(HttpHeaderNames.EXPECT, HttpHeaderValues.CONTINUE, true);
}
/**
@ -212,9 +209,9 @@ public final class HttpHeaderUtil {
*/
public static void set100ContinueExpected(HttpMessage message, boolean expected) {
if (expected) {
message.headers().set(Names.EXPECT, Values.CONTINUE);
message.headers().set(HttpHeaderNames.EXPECT, HttpHeaderValues.CONTINUE);
} else {
message.headers().remove(Names.EXPECT);
message.headers().remove(HttpHeaderNames.EXPECT);
}
}
@ -225,29 +222,29 @@ public final class HttpHeaderUtil {
* @return True if transfer encoding is chunked, otherwise false
*/
public static boolean isTransferEncodingChunked(HttpMessage message) {
return message.headers().contains(Names.TRANSFER_ENCODING, Values.CHUNKED, true);
return message.headers().contains(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED, true);
}
public static void setTransferEncodingChunked(HttpMessage m, boolean chunked) {
if (chunked) {
m.headers().add(Names.TRANSFER_ENCODING, Values.CHUNKED);
m.headers().remove(Names.CONTENT_LENGTH);
m.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
m.headers().remove(HttpHeaderNames.CONTENT_LENGTH);
} else {
List<String> values = m.headers().getAll(Names.TRANSFER_ENCODING);
List<String> values = m.headers().getAll(HttpHeaderNames.TRANSFER_ENCODING);
if (values.isEmpty()) {
return;
}
Iterator<String> valuesIt = values.iterator();
while (valuesIt.hasNext()) {
CharSequence value = valuesIt.next();
if (AsciiString.equalsIgnoreCase(value, Values.CHUNKED)) {
if (HttpHeaderValues.CHUNKED.equalsIgnoreCase(value)) {
valuesIt.remove();
}
}
if (values.isEmpty()) {
m.headers().remove(Names.TRANSFER_ENCODING);
m.headers().remove(HttpHeaderNames.TRANSFER_ENCODING);
} else {
m.headers().set(Names.TRANSFER_ENCODING, values);
m.headers().set(HttpHeaderNames.TRANSFER_ENCODING, values);
}
}
}

View File

@ -0,0 +1,193 @@
/*
* 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.handler.codec.AsciiString;
/**
* Standard HTTP header values.
*/
public final class HttpHeaderValues {
/**
* {@code "application/x-www-form-urlencoded"}
*/
public static final AsciiString APPLICATION_X_WWW_FORM_URLENCODED =
new AsciiString("application/x-www-form-urlencoded");
/**
* {@code "application/octet-stream"}
*/
public static final AsciiString APPLICATION_OCTET_STREAM = new AsciiString("application/octet-stream");
/**
* {@code "attachment"}
* See {@link HttpHeaderNames#CONTENT_DISPOSITION}
*/
public static final AsciiString ATTACHMENT = new AsciiString("attachment");
/**
* {@code "base64"}
*/
public static final AsciiString BASE64 = new AsciiString("base64");
/**
* {@code "binary"}
*/
public static final AsciiString BINARY = new AsciiString("binary");
/**
* {@code "boundary"}
*/
public static final AsciiString BOUNDARY = new AsciiString("boundary");
/**
* {@code "bytes"}
*/
public static final AsciiString BYTES = new AsciiString("bytes");
/**
* {@code "charset"}
*/
public static final AsciiString CHARSET = new AsciiString("charset");
/**
* {@code "chunked"}
*/
public static final AsciiString CHUNKED = new AsciiString("chunked");
/**
* {@code "close"}
*/
public static final AsciiString CLOSE = new AsciiString("close");
/**
* {@code "compress"}
*/
public static final AsciiString COMPRESS = new AsciiString("compress");
/**
* {@code "100-continue"}
*/
public static final AsciiString CONTINUE = new AsciiString("100-continue");
/**
* {@code "deflate"}
*/
public static final AsciiString DEFLATE = new AsciiString("deflate");
/**
* {@code "file"}
* See {@link HttpHeaderNames#CONTENT_DISPOSITION}
*/
public static final AsciiString FILE = new AsciiString("file");
/**
* {@code "filename"}
* See {@link HttpHeaderNames#CONTENT_DISPOSITION}
*/
public static final AsciiString FILENAME = new AsciiString("filename");
/**
* {@code "form-data"}
* See {@link HttpHeaderNames#CONTENT_DISPOSITION}
*/
public static final AsciiString FORM_DATA = new AsciiString("form-data");
/**
* {@code "gzip"}
*/
public static final AsciiString GZIP = new AsciiString("gzip");
/**
* {@code "identity"}
*/
public static final AsciiString IDENTITY = new AsciiString("identity");
/**
* {@code "keep-alive"}
*/
public static final AsciiString KEEP_ALIVE = new AsciiString("keep-alive");
/**
* {@code "max-age"}
*/
public static final AsciiString MAX_AGE = new AsciiString("max-age");
/**
* {@code "max-stale"}
*/
public static final AsciiString MAX_STALE = new AsciiString("max-stale");
/**
* {@code "min-fresh"}
*/
public static final AsciiString MIN_FRESH = new AsciiString("min-fresh");
/**
* {@code "multipart/form-data"}
*/
public static final AsciiString MULTIPART_FORM_DATA = new AsciiString("multipart/form-data");
/**
* {@code "multipart/mixed"}
*/
public static final AsciiString MULTIPART_MIXED = new AsciiString("multipart/mixed");
/**
* {@code "must-revalidate"}
*/
public static final AsciiString MUST_REVALIDATE = new AsciiString("must-revalidate");
/**
* {@code "name"}
* See {@link HttpHeaderNames#CONTENT_DISPOSITION}
*/
public static final AsciiString NAME = new AsciiString("name");
/**
* {@code "no-cache"}
*/
public static final AsciiString NO_CACHE = new AsciiString("no-cache");
/**
* {@code "no-store"}
*/
public static final AsciiString NO_STORE = new AsciiString("no-store");
/**
* {@code "no-transform"}
*/
public static final AsciiString NO_TRANSFORM = new AsciiString("no-transform");
/**
* {@code "none"}
*/
public static final AsciiString NONE = new AsciiString("none");
/**
* {@code "only-if-cached"}
*/
public static final AsciiString ONLY_IF_CACHED = new AsciiString("only-if-cached");
/**
* {@code "private"}
*/
public static final AsciiString PRIVATE = new AsciiString("private");
/**
* {@code "proxy-revalidate"}
*/
public static final AsciiString PROXY_REVALIDATE = new AsciiString("proxy-revalidate");
/**
* {@code "public"}
*/
public static final AsciiString PUBLIC = new AsciiString("public");
/**
* {@code "quoted-printable"}
*/
public static final AsciiString QUOTED_PRINTABLE = new AsciiString("quoted-printable");
/**
* {@code "s-maxage"}
*/
public static final AsciiString S_MAXAGE = new AsciiString("s-maxage");
/**
* {@code "text/plain"}
*/
public static final AsciiString TEXT_PLAIN = new AsciiString("text/plain");
/**
* {@code "trailers"}
*/
public static final AsciiString TRAILERS = new AsciiString("trailers");
/**
* {@code "Upgrade"}
*/
public static final AsciiString UPGRADE = new AsciiString("Upgrade");
/**
* {@code "websocket"}
*/
public static final AsciiString WEBSOCKET = new AsciiString("websocket");
private HttpHeaderValues() { }
}

View File

@ -58,7 +58,7 @@ public class HttpObjectAggregator
HttpVersion.HTTP_1_1, HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE, Unpooled.EMPTY_BUFFER);
static {
TOO_LARGE.headers().set(HttpHeaders.Names.CONTENT_LENGTH, 0);
TOO_LARGE.headers().set(HttpHeaderNames.CONTENT_LENGTH, 0);
}
/**
@ -96,17 +96,17 @@ public class HttpObjectAggregator
@Override
protected boolean hasContentLength(HttpMessage start) throws Exception {
return HttpHeaders.isContentLengthSet(start);
return HttpHeaderUtil.isContentLengthSet(start);
}
@Override
protected long contentLength(HttpMessage start) throws Exception {
return HttpHeaders.getContentLength(start);
return HttpHeaderUtil.getContentLength(start);
}
@Override
protected Object newContinueResponse(HttpMessage start) throws Exception {
if (HttpHeaders.is100ContinueExpected(start)) {
if (HttpHeaderUtil.is100ContinueExpected(start)) {
return CONTINUE;
} else {
return null;
@ -117,7 +117,7 @@ public class HttpObjectAggregator
protected FullHttpMessage beginAggregation(HttpMessage start, ByteBuf content) throws Exception {
assert !(start instanceof FullHttpMessage);
HttpHeaders.removeTransferEncodingChunked(start);
HttpHeaderUtil.setTransferEncodingChunked(start, false);
AggregatedFullHttpMessage ret;
if (start instanceof HttpRequest) {
@ -142,7 +142,7 @@ public class HttpObjectAggregator
protected void finishAggregation(FullHttpMessage aggregated) throws Exception {
// Set the 'Content-Length' header.
aggregated.headers().set(
HttpHeaders.Names.CONTENT_LENGTH,
HttpHeaderNames.CONTENT_LENGTH,
String.valueOf(aggregated.content().readableBytes()));
}
@ -163,7 +163,7 @@ public class HttpObjectAggregator
// If the client started to send data already, close because it's impossible to recover.
// If keep-alive is off and 'Expect: 100-continue' is missing, no need to leave the connection open.
if (oversized instanceof FullHttpMessage ||
(!HttpHeaders.is100ContinueExpected(oversized) && !HttpHeaders.isKeepAlive(oversized))) {
(!HttpHeaderUtil.is100ContinueExpected(oversized) && !HttpHeaderUtil.isKeepAlive(oversized))) {
future.addListener(ChannelFutureListener.CLOSE);
}

View File

@ -20,7 +20,6 @@ import io.netty.buffer.ByteBufProcessor;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.DecoderResult;
import io.netty.handler.codec.ReplayingDecoder;
import io.netty.handler.codec.TooLongFrameException;
@ -384,7 +383,7 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<State> {
// Handle the last unfinished message.
if (message != null) {
boolean chunked = HttpHeaders.isTransferEncodingChunked(message);
boolean chunked = HttpHeaderUtil.isTransferEncodingChunked(message);
if (state() == State.READ_VARIABLE_LENGTH_CONTENT && !in.isReadable() && !chunked) {
// End of connection.
out.add(LastHttpContent.EMPTY_LAST_CONTENT);
@ -422,7 +421,7 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<State> {
// - https://github.com/netty/netty/issues/222
if (code >= 100 && code < 200) {
// One exception: Hixie 76 websocket handshake response
return !(code == 101 && !res.headers().contains(HttpHeaders.Names.SEC_WEBSOCKET_ACCEPT));
return !(code == 101 && !res.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT));
}
switch (code) {
@ -529,9 +528,9 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<State> {
State nextState;
if (isContentAlwaysEmpty(message)) {
HttpHeaders.removeTransferEncodingChunked(message);
HttpHeaderUtil.setTransferEncodingChunked(message, false);
nextState = State.SKIP_CONTROL_CHARS;
} else if (HttpHeaders.isTransferEncodingChunked(message)) {
} else if (HttpHeaderUtil.isTransferEncodingChunked(message)) {
nextState = State.READ_CHUNK_SIZE;
} else if (contentLength() >= 0) {
nextState = State.READ_FIXED_LENGTH_CONTENT;
@ -543,7 +542,7 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<State> {
private long contentLength() {
if (contentLength == Long.MIN_VALUE) {
contentLength = HttpHeaders.getContentLength(message, -1);
contentLength = HttpHeaderUtil.getContentLength(message, -1);
}
return contentLength;
}
@ -571,9 +570,9 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<State> {
} else {
splitHeader(line);
CharSequence headerName = name;
if (!AsciiString.equalsIgnoreCase(headerName, HttpHeaders.Names.CONTENT_LENGTH) &&
!AsciiString.equalsIgnoreCase(headerName, HttpHeaders.Names.TRANSFER_ENCODING) &&
!AsciiString.equalsIgnoreCase(headerName, HttpHeaders.Names.TRAILER)) {
if (!HttpHeaderNames.CONTENT_LENGTH.equalsIgnoreCase(headerName) &&
!HttpHeaderNames.TRANSFER_ENCODING.equalsIgnoreCase(headerName) &&
!HttpHeaderNames.TRAILER.equalsIgnoreCase(headerName)) {
trailer.trailingHeaders().add(headerName, value);
}
lastHeader = name;

View File

@ -72,7 +72,7 @@ public abstract class HttpObjectEncoder<H extends HttpMessage> extends MessageTo
encodeInitialLine(buf, m);
HttpHeaders.encode(m.headers(), buf);
buf.writeBytes(CRLF);
state = HttpHeaders.isTransferEncodingChunked(m) ? ST_CONTENT_CHUNK : ST_CONTENT_NON_CHUNK;
state = HttpHeaderUtil.isTransferEncodingChunked(m) ? ST_CONTENT_CHUNK : ST_CONTENT_NON_CHUNK;
}
// Bypass the encoder in case of an empty buffer, so that the following idiom works:

View File

@ -16,8 +16,8 @@
package io.netty.handler.codec.http.cors;
import io.netty.handler.codec.http.DefaultHttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.util.internal.StringUtil;
@ -510,8 +510,8 @@ public final class CorsConfig {
*/
public CorsConfig build() {
if (preflightHeaders.isEmpty() && !noPreflightHeaders) {
preflightHeaders.put(Names.DATE, new DateValueGenerator());
preflightHeaders.put(Names.CONTENT_LENGTH, new ConstantValueGenerator("0"));
preflightHeaders.put(HttpHeaderNames.DATE, new DateValueGenerator());
preflightHeaders.put(HttpHeaderNames.CONTENT_LENGTH, new ConstantValueGenerator("0"));
}
return new CorsConfig(this);
}

View File

@ -20,16 +20,16 @@ import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.util.ReferenceCountUtil.release;
import static io.netty.util.ReferenceCountUtil.*;
/**
* Handles <a href="http://www.w3.org/TR/cors/">Cross Origin Resource Sharing</a> (CORS) requests.
@ -88,7 +88,7 @@ public class CorsHandler extends ChannelDuplexHandler {
}
private boolean setOrigin(final HttpResponse response) {
final CharSequence origin = request.headers().get(ORIGIN);
final String origin = request.headers().get(HttpHeaderNames.ORIGIN);
if (origin != null) {
if ("null".equals(origin) && config.isNullOriginAllowed()) {
setAnyOrigin(response);
@ -118,7 +118,7 @@ public class CorsHandler extends ChannelDuplexHandler {
return true;
}
final CharSequence origin = request.headers().get(ORIGIN);
final String origin = request.headers().get(HttpHeaderNames.ORIGIN);
if (origin == null) {
// Not a CORS request so we cannot validate it. It may be a non CORS request.
return true;
@ -132,50 +132,50 @@ public class CorsHandler extends ChannelDuplexHandler {
}
private void echoRequestOrigin(final HttpResponse response) {
setOrigin(response, request.headers().get(ORIGIN));
setOrigin(response, request.headers().get(HttpHeaderNames.ORIGIN));
}
private static void setVaryHeader(final HttpResponse response) {
response.headers().set(VARY, ORIGIN);
response.headers().set(HttpHeaderNames.VARY, HttpHeaderNames.ORIGIN);
}
private static void setAnyOrigin(final HttpResponse response) {
setOrigin(response, "*");
}
private static void setOrigin(final HttpResponse response, final CharSequence origin) {
response.headers().set(ACCESS_CONTROL_ALLOW_ORIGIN, origin);
private static void setOrigin(final HttpResponse response, final String origin) {
response.headers().set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN, origin);
}
private void setAllowCredentials(final HttpResponse response) {
if (config.isCredentialsAllowed()) {
response.headers().set(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
response.headers().set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
}
}
private static boolean isPreflightRequest(final HttpRequest request) {
final HttpHeaders headers = request.headers();
return request.method().equals(OPTIONS) &&
headers.contains(ORIGIN) &&
headers.contains(ACCESS_CONTROL_REQUEST_METHOD);
headers.contains(HttpHeaderNames.ORIGIN) &&
headers.contains(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD);
}
private void setExposeHeaders(final HttpResponse response) {
if (!config.exposedHeaders().isEmpty()) {
response.headers().set(ACCESS_CONTROL_EXPOSE_HEADERS, config.exposedHeaders());
response.headers().set(HttpHeaderNames.ACCESS_CONTROL_EXPOSE_HEADERS, config.exposedHeaders());
}
}
private void setAllowMethods(final HttpResponse response) {
response.headers().set(ACCESS_CONTROL_ALLOW_METHODS, config.allowedRequestMethods());
response.headers().set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_METHODS, config.allowedRequestMethods());
}
private void setAllowHeaders(final HttpResponse response) {
response.headers().set(ACCESS_CONTROL_ALLOW_HEADERS, config.allowedRequestHeaders());
response.headers().set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS, config.allowedRequestHeaders());
}
private void setMaxAge(final HttpResponse response) {
response.headers().set(ACCESS_CONTROL_MAX_AGE, config.maxAge());
response.headers().set(HttpHeaderNames.ACCESS_CONTROL_MAX_AGE, config.maxAge());
}
@Override

View File

@ -17,7 +17,8 @@ package io.netty.handler.codec.http.multipart;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelException;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import java.io.File;
import java.io.IOException;
@ -132,12 +133,12 @@ public class DiskFileUpload extends AbstractDiskHttpData implements FileUpload {
// Should not occur.
}
return HttpPostBodyUtil.CONTENT_DISPOSITION + ": " +
HttpPostBodyUtil.FORM_DATA + "; " + HttpPostBodyUtil.NAME + "=\"" + getName() +
"\"; " + HttpPostBodyUtil.FILENAME + "=\"" + filename + "\"\r\n" +
HttpHeaders.Names.CONTENT_TYPE + ": " + contentType +
(getCharset() != null? "; " + HttpHeaders.Values.CHARSET + '=' + getCharset() + "\r\n" : "\r\n") +
HttpHeaders.Names.CONTENT_LENGTH + ": " + length() + "\r\n" +
return HttpHeaderNames.CONTENT_DISPOSITION + ": " +
HttpHeaderValues.FORM_DATA + "; " + HttpHeaderValues.NAME + "=\"" + getName() +
"\"; " + HttpHeaderValues.FILENAME + "=\"" + filename + "\"\r\n" +
HttpHeaderNames.CONTENT_TYPE + ": " + contentType +
(getCharset() != null? "; " + HttpHeaderValues.CHARSET + '=' + getCharset() + "\r\n" : "\r\n") +
HttpHeaderNames.CONTENT_LENGTH + ": " + length() + "\r\n" +
"Completed: " + isCompleted() +
"\r\nIsInMemory: " + isInMemory() + "\r\nRealFile: " +
(file != null ? file.getAbsolutePath() : "null") + " DefaultDeleteAfter: " +

View File

@ -16,10 +16,6 @@
package io.netty.handler.codec.http.multipart;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.util.CharsetUtil;
import java.nio.charset.Charset;
/**
* Shared Static object between HttpMessageDecoder, HttpPostRequestDecoder and HttpPostRequestEncoder
@ -27,54 +23,16 @@ import java.nio.charset.Charset;
final class HttpPostBodyUtil {
public static final int chunkSize = 8096;
/**
* HTTP content disposition header name.
*/
public static final String CONTENT_DISPOSITION = HttpHeaders.Names.CONTENT_DISPOSITION.toString();
public static final String NAME = HttpHeaders.Values.NAME.toString();
public static final String FILENAME = HttpHeaders.Values.FILENAME.toString();
/**
* Content-disposition value for form data.
*/
public static final String FORM_DATA = HttpHeaders.Values.FORM_DATA.toString();
/**
* Content-disposition value for file attachment.
*/
public static final String ATTACHMENT = HttpHeaders.Values.ATTACHMENT.toString();
/**
* Content-disposition value for file attachment.
*/
public static final String FILE = HttpHeaders.Values.FILE.toString();
/**
* HTTP content type body attribute for multiple uploads.
*/
public static final String MULTIPART_MIXED = HttpHeaders.Values.MULTIPART_MIXED.toString();
/**
* Charset for 8BIT
*/
public static final Charset ISO_8859_1 = CharsetUtil.ISO_8859_1;
/**
* Charset for 7BIT
*/
public static final Charset US_ASCII = CharsetUtil.US_ASCII;
/**
* Default Content-Type in binary form
*/
public static final String DEFAULT_BINARY_CONTENT_TYPE = HttpHeaders.Values.APPLICATION_OCTET_STREAM.toString();
public static final String DEFAULT_BINARY_CONTENT_TYPE = "application/octet-stream";
/**
* Default Content-Type in Text form
*/
public static final String DEFAULT_TEXT_CONTENT_TYPE = HttpHeaders.Values.TEXT_PLAIN.toString();
public static final String DEFAULT_TEXT_CONTENT_TYPE = "text/plain";
/**
* Allowed mechanism for multipart

View File

@ -16,10 +16,10 @@
package io.netty.handler.codec.http.multipart;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.http.HttpConstants;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.handler.codec.http.multipart.HttpPostBodyUtil.SeekAheadNoBackArrayException;
@ -29,6 +29,7 @@ import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.EndOfDataDec
import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.ErrorDataDecoderException;
import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.MultiPartStatus;
import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.NotEnoughDataDecoderException;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.StringUtil;
import java.io.IOException;
@ -182,7 +183,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
this.factory = factory;
// Fill default values
setMultipart(this.request.headers().get(HttpHeaders.Names.CONTENT_TYPE));
setMultipart(this.request.headers().get(HttpHeaderNames.CONTENT_TYPE));
if (request instanceof HttpContent) {
// Offer automatically if the given request is als type of HttpContent
// See #1089
@ -490,7 +491,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
case FIELD: {
// Now get value according to Content-Type and Charset
Charset localCharset = null;
Attribute charsetAttribute = currentFieldAttributes.get(HttpHeaders.Values.CHARSET);
Attribute charsetAttribute = currentFieldAttributes.get(HttpHeaderValues.CHARSET);
if (charsetAttribute != null) {
try {
localCharset = Charset.forName(charsetAttribute.getValue());
@ -498,7 +499,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
throw new ErrorDataDecoderException(e);
}
}
Attribute nameAttribute = currentFieldAttributes.get(HttpPostBodyUtil.NAME);
Attribute nameAttribute = currentFieldAttributes.get(HttpHeaderValues.NAME);
if (currentAttribute == null) {
try {
currentAttribute = factory.createAttribute(request,
@ -662,13 +663,13 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
return null;
}
String[] contents = splitMultipartHeader(newline);
if (contents[0].equalsIgnoreCase(HttpPostBodyUtil.CONTENT_DISPOSITION)) {
if (HttpHeaderNames.CONTENT_DISPOSITION.equalsIgnoreCase(contents[0])) {
boolean checkSecondArg;
if (currentStatus == MultiPartStatus.DISPOSITION) {
checkSecondArg = contents[1].equalsIgnoreCase(HttpPostBodyUtil.FORM_DATA);
checkSecondArg = HttpHeaderValues.FORM_DATA.equalsIgnoreCase(contents[1]);
} else {
checkSecondArg = contents[1].equalsIgnoreCase(HttpPostBodyUtil.ATTACHMENT)
|| contents[1].equalsIgnoreCase(HttpPostBodyUtil.FILE);
checkSecondArg = HttpHeaderValues.ATTACHMENT.equalsIgnoreCase(contents[1])
|| HttpHeaderValues.FILE.equalsIgnoreCase(contents[1]);
}
if (checkSecondArg) {
// read next values and store them in the map as Attribute
@ -680,7 +681,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
String value = values[1];
// See http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html
if (HttpPostBodyUtil.FILENAME.equals(name)) {
if (HttpHeaderValues.FILENAME.contentEquals(name)) {
// filename value is quoted string so strip them
value = value.substring(1, value.length() - 1);
} else {
@ -696,31 +697,31 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
currentFieldAttributes.put(attribute.getName(), attribute);
}
}
} else if (AsciiString.equalsIgnoreCase(contents[0], HttpHeaders.Names.CONTENT_TRANSFER_ENCODING)) {
} else if (HttpHeaderNames.CONTENT_TRANSFER_ENCODING.equalsIgnoreCase(contents[0])) {
Attribute attribute;
try {
attribute = factory.createAttribute(request, HttpHeaders.Names.CONTENT_TRANSFER_ENCODING.toString(),
attribute = factory.createAttribute(request, HttpHeaderNames.CONTENT_TRANSFER_ENCODING.toString(),
cleanString(contents[1]));
} catch (NullPointerException e) {
throw new ErrorDataDecoderException(e);
} catch (IllegalArgumentException e) {
throw new ErrorDataDecoderException(e);
}
currentFieldAttributes.put(HttpHeaders.Names.CONTENT_TRANSFER_ENCODING, attribute);
} else if (AsciiString.equalsIgnoreCase(contents[0], HttpHeaders.Names.CONTENT_LENGTH)) {
currentFieldAttributes.put(HttpHeaderNames.CONTENT_TRANSFER_ENCODING, attribute);
} else if (HttpHeaderNames.CONTENT_LENGTH.equalsIgnoreCase(contents[0])) {
Attribute attribute;
try {
attribute = factory.createAttribute(request, HttpHeaders.Names.CONTENT_LENGTH.toString(),
attribute = factory.createAttribute(request, HttpHeaderNames.CONTENT_LENGTH.toString(),
cleanString(contents[1]));
} catch (NullPointerException e) {
throw new ErrorDataDecoderException(e);
} catch (IllegalArgumentException e) {
throw new ErrorDataDecoderException(e);
}
currentFieldAttributes.put(HttpHeaders.Names.CONTENT_LENGTH, attribute);
} else if (AsciiString.equalsIgnoreCase(contents[0], HttpHeaders.Names.CONTENT_TYPE)) {
currentFieldAttributes.put(HttpHeaderNames.CONTENT_LENGTH, attribute);
} else if (HttpHeaderNames.CONTENT_TYPE.equalsIgnoreCase(contents[0])) {
// Take care of possible "multipart/mixed"
if (contents[1].equalsIgnoreCase(HttpPostBodyUtil.MULTIPART_MIXED)) {
if (HttpHeaderValues.MULTIPART_MIXED.equalsIgnoreCase(contents[1])) {
if (currentStatus == MultiPartStatus.DISPOSITION) {
String values = StringUtil.substringAfter(contents[2], '=');
multipartMixedBoundary = "--" + values;
@ -731,18 +732,18 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
}
} else {
for (int i = 1; i < contents.length; i++) {
if (contents[i].toLowerCase().startsWith(HttpHeaders.Values.CHARSET)) {
if (contents[i].toLowerCase().startsWith(HttpHeaderValues.CHARSET.toString())) {
String values = StringUtil.substringAfter(contents[i], '=');
Attribute attribute;
try {
attribute = factory.createAttribute(request, HttpHeaders.Values.CHARSET,
attribute = factory.createAttribute(request, HttpHeaderValues.CHARSET.toString(),
cleanString(values));
} catch (NullPointerException e) {
throw new ErrorDataDecoderException(e);
} catch (IllegalArgumentException e) {
throw new ErrorDataDecoderException(e);
}
currentFieldAttributes.put(HttpHeaders.Values.CHARSET, attribute);
currentFieldAttributes.put(HttpHeaderValues.CHARSET, attribute);
} else {
Attribute attribute;
try {
@ -762,7 +763,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
}
}
// Is it a FileUpload
Attribute filenameAttribute = currentFieldAttributes.get(HttpPostBodyUtil.FILENAME);
Attribute filenameAttribute = currentFieldAttributes.get(HttpHeaderValues.FILENAME);
if (currentStatus == MultiPartStatus.DISPOSITION) {
if (filenameAttribute != null) {
// FileUpload
@ -799,7 +800,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
protected InterfaceHttpData getFileUpload(String delimiter) {
// eventually restart from existing FileUpload
// Now get value according to Content-Type and Charset
Attribute encoding = currentFieldAttributes.get(HttpHeaders.Names.CONTENT_TRANSFER_ENCODING);
Attribute encoding = currentFieldAttributes.get(HttpHeaderNames.CONTENT_TRANSFER_ENCODING);
Charset localCharset = charset;
// Default
TransferEncodingMechanism mechanism = TransferEncodingMechanism.BIT7;
@ -811,9 +812,9 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
throw new ErrorDataDecoderException(e);
}
if (code.equals(HttpPostBodyUtil.TransferEncodingMechanism.BIT7.value())) {
localCharset = HttpPostBodyUtil.US_ASCII;
localCharset = CharsetUtil.US_ASCII;
} else if (code.equals(HttpPostBodyUtil.TransferEncodingMechanism.BIT8.value())) {
localCharset = HttpPostBodyUtil.ISO_8859_1;
localCharset = CharsetUtil.ISO_8859_1;
mechanism = TransferEncodingMechanism.BIT8;
} else if (code.equals(HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value())) {
// no real charset, so let the default
@ -822,7 +823,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
throw new ErrorDataDecoderException("TransferEncoding Unknown: " + code);
}
}
Attribute charsetAttribute = currentFieldAttributes.get(HttpHeaders.Values.CHARSET);
Attribute charsetAttribute = currentFieldAttributes.get(HttpHeaderValues.CHARSET);
if (charsetAttribute != null) {
try {
localCharset = Charset.forName(charsetAttribute.getValue());
@ -831,13 +832,13 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
}
}
if (currentFileUpload == null) {
Attribute filenameAttribute = currentFieldAttributes.get(HttpPostBodyUtil.FILENAME);
Attribute nameAttribute = currentFieldAttributes.get(HttpPostBodyUtil.NAME);
Attribute contentTypeAttribute = currentFieldAttributes.get(HttpHeaders.Names.CONTENT_TYPE);
Attribute filenameAttribute = currentFieldAttributes.get(HttpHeaderValues.FILENAME);
Attribute nameAttribute = currentFieldAttributes.get(HttpHeaderValues.NAME);
Attribute contentTypeAttribute = currentFieldAttributes.get(HttpHeaderNames.CONTENT_TYPE);
if (contentTypeAttribute == null) {
throw new ErrorDataDecoderException("Content-Type is absent but required");
}
Attribute lengthAttribute = currentFieldAttributes.get(HttpHeaders.Names.CONTENT_LENGTH);
Attribute lengthAttribute = currentFieldAttributes.get(HttpHeaderNames.CONTENT_LENGTH);
long size;
try {
size = lengthAttribute != null ? Long.parseLong(lengthAttribute.getValue()) : 0L;
@ -933,11 +934,11 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
* Mixed mode
*/
private void cleanMixedAttributes() {
currentFieldAttributes.remove(HttpHeaders.Values.CHARSET);
currentFieldAttributes.remove(HttpHeaders.Names.CONTENT_LENGTH);
currentFieldAttributes.remove(HttpHeaders.Names.CONTENT_TRANSFER_ENCODING);
currentFieldAttributes.remove(HttpHeaders.Names.CONTENT_TYPE);
currentFieldAttributes.remove(HttpPostBodyUtil.FILENAME);
currentFieldAttributes.remove(HttpHeaderValues.CHARSET);
currentFieldAttributes.remove(HttpHeaderNames.CONTENT_LENGTH);
currentFieldAttributes.remove(HttpHeaderNames.CONTENT_TRANSFER_ENCODING);
currentFieldAttributes.remove(HttpHeaderNames.CONTENT_TYPE);
currentFieldAttributes.remove(HttpHeaderValues.FILENAME);
}
/**

View File

@ -18,7 +18,8 @@ package io.netty.handler.codec.http.multipart;
import io.netty.handler.codec.DecoderException;
import io.netty.handler.codec.http.HttpConstants;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.util.internal.StringUtil;
@ -139,8 +140,8 @@ public class HttpPostRequestDecoder implements InterfaceHttpPostRequestDecoder {
* @return True if the request is a Multipart request
*/
public static boolean isMultipart(HttpRequest request) {
if (request.headers().contains(HttpHeaders.Names.CONTENT_TYPE)) {
return getMultipartDataBoundary(request.headers().get(HttpHeaders.Names.CONTENT_TYPE)) != null;
if (request.headers().contains(HttpHeaderNames.CONTENT_TYPE)) {
return getMultipartDataBoundary(request.headers().get(HttpHeaderNames.CONTENT_TYPE)) != null;
} else {
return false;
}
@ -155,15 +156,15 @@ public class HttpPostRequestDecoder implements InterfaceHttpPostRequestDecoder {
// Check if Post using "multipart/form-data; boundary=--89421926422648 [; charset=xxx]"
String[] headerContentType = splitHeaderContentType(contentType);
if (headerContentType[0].toLowerCase().startsWith(
HttpHeaders.Values.MULTIPART_FORM_DATA)) {
HttpHeaderValues.MULTIPART_FORM_DATA.toString())) {
int mrank;
int crank;
if (headerContentType[1].toLowerCase().startsWith(
HttpHeaders.Values.BOUNDARY)) {
HttpHeaderValues.BOUNDARY.toString())) {
mrank = 1;
crank = 2;
} else if (headerContentType[2].toLowerCase().startsWith(
HttpHeaders.Values.BOUNDARY)) {
HttpHeaderValues.BOUNDARY.toString())) {
mrank = 2;
crank = 1;
} else {
@ -181,7 +182,7 @@ public class HttpPostRequestDecoder implements InterfaceHttpPostRequestDecoder {
}
}
if (headerContentType[crank].toLowerCase().startsWith(
HttpHeaders.Values.CHARSET)) {
HttpHeaderValues.CHARSET.toString())) {
String charset = StringUtil.substringAfter(headerContentType[crank], '=');
if (charset != null) {
return new String[] {"--" + boundary, charset};

View File

@ -17,13 +17,15 @@ package io.netty.handler.codec.http.multipart;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.DecoderResult;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.DefaultHttpContent;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpConstants;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderUtil;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpRequest;
@ -502,14 +504,14 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
internal.addValue("--" + multipartDataBoundary + "\r\n");
// content-disposition: form-data; name="field1"
Attribute attribute = (Attribute) data;
internal.addValue(HttpPostBodyUtil.CONTENT_DISPOSITION + ": " + HttpPostBodyUtil.FORM_DATA + "; "
+ HttpPostBodyUtil.NAME + "=\"" + attribute.getName() + "\"\r\n");
internal.addValue(HttpHeaderNames.CONTENT_DISPOSITION + ": " + HttpHeaderValues.FORM_DATA + "; "
+ HttpHeaderValues.NAME + "=\"" + attribute.getName() + "\"\r\n");
Charset localcharset = attribute.getCharset();
if (localcharset != null) {
// Content-Type: text/plain; charset=charset
internal.addValue(HttpHeaders.Names.CONTENT_TYPE + ": " +
internal.addValue(HttpHeaderNames.CONTENT_TYPE + ": " +
HttpPostBodyUtil.DEFAULT_TEXT_CONTENT_TYPE + "; " +
HttpHeaders.Values.CHARSET + '='
HttpHeaderValues.CHARSET + '='
+ localcharset + "\r\n");
}
// CRLF between body header and data
@ -584,20 +586,20 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
replacement.append(multipartDataBoundary);
replacement.append("\r\n");
replacement.append(HttpPostBodyUtil.CONTENT_DISPOSITION);
replacement.append(HttpHeaderNames.CONTENT_DISPOSITION);
replacement.append(": ");
replacement.append(HttpPostBodyUtil.FORM_DATA);
replacement.append(HttpHeaderValues.FORM_DATA);
replacement.append("; ");
replacement.append(HttpPostBodyUtil.NAME);
replacement.append(HttpHeaderValues.NAME);
replacement.append("=\"");
replacement.append(fileUpload.getName());
replacement.append("\"\r\n");
replacement.append(HttpHeaders.Names.CONTENT_TYPE);
replacement.append(HttpHeaderNames.CONTENT_TYPE);
replacement.append(": ");
replacement.append(HttpPostBodyUtil.MULTIPART_MIXED);
replacement.append(HttpHeaderValues.MULTIPART_MIXED);
replacement.append("; ");
replacement.append(HttpHeaders.Values.BOUNDARY);
replacement.append(HttpHeaderValues.BOUNDARY);
replacement.append('=');
replacement.append(multipartMixedBoundary);
replacement.append("\r\n\r\n");
@ -606,11 +608,11 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
replacement.append(multipartMixedBoundary);
replacement.append("\r\n");
replacement.append(HttpPostBodyUtil.CONTENT_DISPOSITION);
replacement.append(HttpHeaderNames.CONTENT_DISPOSITION);
replacement.append(": ");
replacement.append(HttpPostBodyUtil.ATTACHMENT);
replacement.append(HttpHeaderValues.ATTACHMENT);
replacement.append("; ");
replacement.append(HttpPostBodyUtil.FILENAME);
replacement.append(HttpHeaderValues.FILENAME);
replacement.append("=\"");
replacement.append(fileUpload.getFilename());
replacement.append("\"\r\n");
@ -642,27 +644,27 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
// Data to multipart list
internal.addValue("--" + multipartMixedBoundary + "\r\n");
// Content-Disposition: attachment; filename="file1.txt"
internal.addValue(HttpPostBodyUtil.CONTENT_DISPOSITION + ": " + HttpPostBodyUtil.ATTACHMENT + "; "
+ HttpPostBodyUtil.FILENAME + "=\"" + fileUpload.getFilename() + "\"\r\n");
internal.addValue(HttpHeaderNames.CONTENT_DISPOSITION + ": " + HttpHeaderValues.ATTACHMENT + "; "
+ HttpHeaderValues.FILENAME + "=\"" + fileUpload.getFilename() + "\"\r\n");
} else {
internal.addValue("--" + multipartDataBoundary + "\r\n");
// Content-Disposition: form-data; name="files";
// filename="file1.txt"
internal.addValue(HttpPostBodyUtil.CONTENT_DISPOSITION + ": " + HttpPostBodyUtil.FORM_DATA + "; "
+ HttpPostBodyUtil.NAME + "=\"" + fileUpload.getName() + "\"; "
+ HttpPostBodyUtil.FILENAME + "=\"" + fileUpload.getFilename() + "\"\r\n");
internal.addValue(HttpHeaderNames.CONTENT_DISPOSITION + ": " + HttpHeaderValues.FORM_DATA + "; "
+ HttpHeaderValues.NAME + "=\"" + fileUpload.getName() + "\"; "
+ HttpHeaderValues.FILENAME + "=\"" + fileUpload.getFilename() + "\"\r\n");
}
// Content-Type: image/gif
// Content-Type: text/plain; charset=ISO-8859-1
// Content-Transfer-Encoding: binary
internal.addValue(HttpHeaders.Names.CONTENT_TYPE + ": " + fileUpload.getContentType());
internal.addValue(HttpHeaderNames.CONTENT_TYPE + ": " + fileUpload.getContentType());
String contentTransferEncoding = fileUpload.getContentTransferEncoding();
if (contentTransferEncoding != null
&& contentTransferEncoding.equals(HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value())) {
internal.addValue("\r\n" + HttpHeaders.Names.CONTENT_TRANSFER_ENCODING + ": "
internal.addValue("\r\n" + HttpHeaderNames.CONTENT_TRANSFER_ENCODING + ": "
+ HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value() + "\r\n\r\n");
} else if (fileUpload.getCharset() != null) {
internal.addValue("; " + HttpHeaders.Values.CHARSET + '=' + fileUpload.getCharset() + "\r\n\r\n");
internal.addValue("; " + HttpHeaderValues.CHARSET + '=' + fileUpload.getCharset() + "\r\n\r\n");
} else {
internal.addValue("\r\n\r\n");
}
@ -708,28 +710,28 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
}
HttpHeaders headers = request.headers();
List<String> contentTypes = headers.getAll(HttpHeaders.Names.CONTENT_TYPE);
List<String> transferEncoding = headers.getAll(HttpHeaders.Names.TRANSFER_ENCODING);
List<String> contentTypes = headers.getAll(HttpHeaderNames.CONTENT_TYPE);
List<String> transferEncoding = headers.getAll(HttpHeaderNames.TRANSFER_ENCODING);
if (contentTypes != null) {
headers.remove(HttpHeaders.Names.CONTENT_TYPE);
headers.remove(HttpHeaderNames.CONTENT_TYPE);
for (String contentType : contentTypes) {
// "multipart/form-data; boundary=--89421926422648"
String lowercased = contentType.toLowerCase();
if (lowercased.startsWith(HttpHeaders.Values.MULTIPART_FORM_DATA) ||
lowercased.startsWith(HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED.toString())) {
if (lowercased.startsWith(HttpHeaderValues.MULTIPART_FORM_DATA.toString()) ||
lowercased.startsWith(HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED.toString())) {
// ignore
} else {
headers.add(HttpHeaders.Names.CONTENT_TYPE, contentType);
headers.add(HttpHeaderNames.CONTENT_TYPE, contentType);
}
}
}
if (isMultipart) {
String value = HttpHeaders.Values.MULTIPART_FORM_DATA + "; " + HttpHeaders.Values.BOUNDARY + '='
String value = HttpHeaderValues.MULTIPART_FORM_DATA + "; " + HttpHeaderValues.BOUNDARY + '='
+ multipartDataBoundary;
headers.add(HttpHeaders.Names.CONTENT_TYPE, value);
headers.add(HttpHeaderNames.CONTENT_TYPE, value);
} else {
// Not multipart
headers.add(HttpHeaders.Names.CONTENT_TYPE, HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED);
headers.add(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED);
}
// Now consider size for chunk or not
long realSize = globalBodySize;
@ -739,20 +741,20 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
realSize -= 1; // last '&' removed
iterator = multipartHttpDatas.listIterator();
}
headers.set(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(realSize));
headers.set(HttpHeaderNames.CONTENT_LENGTH, String.valueOf(realSize));
if (realSize > HttpPostBodyUtil.chunkSize || isMultipart) {
isChunked = true;
if (transferEncoding != null) {
headers.remove(HttpHeaders.Names.TRANSFER_ENCODING);
headers.remove(HttpHeaderNames.TRANSFER_ENCODING);
for (CharSequence v : transferEncoding) {
if (AsciiString.equalsIgnoreCase(v, HttpHeaders.Values.CHUNKED)) {
if (HttpHeaderValues.CHUNKED.equalsIgnoreCase(v)) {
// ignore
} else {
headers.add(HttpHeaders.Names.TRANSFER_ENCODING, v);
headers.add(HttpHeaderNames.TRANSFER_ENCODING, v);
}
}
}
HttpHeaders.setTransferEncodingChunked(request);
HttpHeaderUtil.setTransferEncodingChunked(request, true);
// wrap to hide the possible content
return new WrappedHttpRequest(request);

View File

@ -17,7 +17,8 @@ package io.netty.handler.codec.http.multipart;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelException;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import java.io.IOException;
import java.nio.charset.Charset;
@ -119,12 +120,12 @@ public class MemoryFileUpload extends AbstractMemoryHttpData implements FileUplo
@Override
public String toString() {
return HttpPostBodyUtil.CONTENT_DISPOSITION + ": " +
HttpPostBodyUtil.FORM_DATA + "; " + HttpPostBodyUtil.NAME + "=\"" + getName() +
"\"; " + HttpPostBodyUtil.FILENAME + "=\"" + filename + "\"\r\n" +
HttpHeaders.Names.CONTENT_TYPE + ": " + contentType +
(getCharset() != null? "; " + HttpHeaders.Values.CHARSET + '=' + getCharset() + "\r\n" : "\r\n") +
HttpHeaders.Names.CONTENT_LENGTH + ": " + length() + "\r\n" +
return HttpHeaderNames.CONTENT_DISPOSITION + ": " +
HttpHeaderValues.FORM_DATA + "; " + HttpHeaderValues.NAME + "=\"" + getName() +
"\"; " + HttpHeaderValues.FILENAME + "=\"" + filename + "\"\r\n" +
HttpHeaderNames.CONTENT_TYPE + ": " + contentType +
(getCharset() != null? "; " + HttpHeaderValues.CHARSET + '=' + getCharset() + "\r\n" : "\r\n") +
HttpHeaderNames.CONTENT_LENGTH + ": " + length() + "\r\n" +
"Completed: " + isCompleted() +
"\r\nIsInMemory: " + isInMemory();
}

View File

@ -25,6 +25,7 @@ import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.http.HttpContentDecompressor;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpRequestEncoder;
import io.netty.handler.codec.http.HttpResponseDecoder;
@ -203,7 +204,7 @@ public abstract class WebSocketClientHandshaker {
// Verify the subprotocol that we received from the server.
// This must be one of our expected subprotocols - or null/empty if we didn't want to speak a subprotocol
String receivedProtocol = response.headers().get(HttpHeaders.Names.SEC_WEBSOCKET_PROTOCOL);
String receivedProtocol = response.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL);
receivedProtocol = receivedProtocol != null ? receivedProtocol.trim() : null;
String expectedProtocol = expectedSubprotocol != null ? expectedSubprotocol : "";
boolean protocolValid = false;

View File

@ -21,9 +21,9 @@ import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaders.Values;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
@ -43,6 +43,8 @@ import java.nio.ByteBuffer;
*/
public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
private static final AsciiString WEBSOCKET = new AsciiString("WebSocket");
private ByteBuf expectedChallengeResponseBytes;
/**
@ -136,9 +138,9 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
// Format request
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path);
HttpHeaders headers = request.headers();
headers.add(Names.UPGRADE, Values.WEBSOCKET)
.add(Names.CONNECTION, Values.UPGRADE)
.add(Names.HOST, wsURL.getHost());
headers.add(HttpHeaderNames.UPGRADE, WEBSOCKET)
.add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE)
.add(HttpHeaderNames.HOST, wsURL.getHost());
int wsPort = wsURL.getPort();
String originValue = "http://" + wsURL.getHost();
@ -148,13 +150,13 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
originValue = originValue + ':' + wsPort;
}
headers.add(Names.ORIGIN, originValue)
.add(Names.SEC_WEBSOCKET_KEY1, key1)
.add(Names.SEC_WEBSOCKET_KEY2, key2);
headers.add(HttpHeaderNames.ORIGIN, originValue)
.add(HttpHeaderNames.SEC_WEBSOCKET_KEY1, key1)
.add(HttpHeaderNames.SEC_WEBSOCKET_KEY2, key2);
String expectedSubprotocol = expectedSubprotocol();
if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
headers.add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
headers.add(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
}
if (customHeaders != null) {
@ -163,7 +165,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
// Set Content-Length to workaround some known defect.
// See also: http://www.ietf.org/mail-archive/web/hybi/current/msg02149.html
headers.set(Names.CONTENT_LENGTH, key3.length);
headers.set(HttpHeaderNames.CONTENT_LENGTH, key3.length);
request.content().writeBytes(key3);
return request;
}
@ -198,14 +200,14 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
HttpHeaders headers = response.headers();
CharSequence upgrade = headers.get(Names.UPGRADE);
if (!AsciiString.equalsIgnoreCase(Values.WEBSOCKET, upgrade)) {
CharSequence upgrade = headers.get(HttpHeaderNames.UPGRADE);
if (!WEBSOCKET.equalsIgnoreCase(upgrade)) {
throw new WebSocketHandshakeException("Invalid handshake response upgrade: "
+ upgrade);
}
CharSequence connection = headers.get(Names.CONNECTION);
if (!AsciiString.equalsIgnoreCase(Values.UPGRADE, connection)) {
CharSequence connection = headers.get(HttpHeaderNames.CONNECTION);
if (!HttpHeaderValues.UPGRADE.equalsIgnoreCase(connection)) {
throw new WebSocketHandshakeException("Invalid handshake response connection: "
+ connection);
}

View File

@ -15,13 +15,12 @@
*/
package io.netty.handler.codec.http.websocketx;
import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaders.Values;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
@ -41,7 +40,6 @@ import java.net.URI;
public class WebSocketClientHandshaker07 extends WebSocketClientHandshaker {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketClientHandshaker07.class);
private static final CharSequence WEBSOCKET = Values.WEBSOCKET.toLowerCase();
public static final String MAGIC_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
private String expectedChallengeResponseString;
@ -154,10 +152,10 @@ public class WebSocketClientHandshaker07 extends WebSocketClientHandshaker {
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path);
HttpHeaders headers = request.headers();
headers.add(Names.UPGRADE, WEBSOCKET)
.add(Names.CONNECTION, Values.UPGRADE)
.add(Names.SEC_WEBSOCKET_KEY, key)
.add(Names.HOST, wsURL.getHost());
headers.add(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET)
.add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE)
.add(HttpHeaderNames.SEC_WEBSOCKET_KEY, key)
.add(HttpHeaderNames.HOST, wsURL.getHost());
int wsPort = wsURL.getPort();
String originValue = "http://" + wsURL.getHost();
@ -166,14 +164,14 @@ public class WebSocketClientHandshaker07 extends WebSocketClientHandshaker {
// See http://tools.ietf.org/html/rfc6454#section-6.2
originValue = originValue + ':' + wsPort;
}
headers.add(Names.SEC_WEBSOCKET_ORIGIN, originValue);
headers.add(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, originValue);
String expectedSubprotocol = expectedSubprotocol();
if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
headers.add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
headers.add(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
}
headers.add(Names.SEC_WEBSOCKET_VERSION, "7");
headers.add(HttpHeaderNames.SEC_WEBSOCKET_VERSION, "7");
if (customHeaders != null) {
headers.add(customHeaders);
@ -207,17 +205,17 @@ public class WebSocketClientHandshaker07 extends WebSocketClientHandshaker {
throw new WebSocketHandshakeException("Invalid handshake response getStatus: " + response.status());
}
CharSequence upgrade = headers.get(Names.UPGRADE);
if (!AsciiString.equalsIgnoreCase(Values.WEBSOCKET, upgrade)) {
CharSequence upgrade = headers.get(HttpHeaderNames.UPGRADE);
if (!HttpHeaderValues.WEBSOCKET.equalsIgnoreCase(upgrade)) {
throw new WebSocketHandshakeException("Invalid handshake response upgrade: " + upgrade);
}
CharSequence connection = headers.get(Names.CONNECTION);
if (!AsciiString.equalsIgnoreCase(Values.UPGRADE, connection)) {
CharSequence connection = headers.get(HttpHeaderNames.CONNECTION);
if (!HttpHeaderValues.UPGRADE.equalsIgnoreCase(connection)) {
throw new WebSocketHandshakeException("Invalid handshake response connection: " + connection);
}
CharSequence accept = headers.get(Names.SEC_WEBSOCKET_ACCEPT);
CharSequence accept = headers.get(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT);
if (accept == null || !accept.equals(expectedChallengeResponseString)) {
throw new WebSocketHandshakeException(String.format(
"Invalid challenge. Actual: %s. Expected: %s", accept, expectedChallengeResponseString));

View File

@ -15,13 +15,12 @@
*/
package io.netty.handler.codec.http.websocketx;
import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaders.Values;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
@ -41,7 +40,6 @@ import java.net.URI;
public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketClientHandshaker08.class);
private static final CharSequence WEBSOCKET = Values.WEBSOCKET.toLowerCase();
public static final String MAGIC_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
@ -155,10 +153,10 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path);
HttpHeaders headers = request.headers();
headers.add(Names.UPGRADE, WEBSOCKET)
.add(Names.CONNECTION, Values.UPGRADE)
.add(Names.SEC_WEBSOCKET_KEY, key)
.add(Names.HOST, wsURL.getHost());
headers.add(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET)
.add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE)
.add(HttpHeaderNames.SEC_WEBSOCKET_KEY, key)
.add(HttpHeaderNames.HOST, wsURL.getHost());
int wsPort = wsURL.getPort();
String originValue = "http://" + wsURL.getHost();
@ -167,14 +165,14 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
// See http://tools.ietf.org/html/rfc6454#section-6.2
originValue = originValue + ':' + wsPort;
}
headers.add(Names.SEC_WEBSOCKET_ORIGIN, originValue);
headers.add(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, originValue);
String expectedSubprotocol = expectedSubprotocol();
if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
headers.add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
headers.add(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
}
headers.add(Names.SEC_WEBSOCKET_VERSION, "8");
headers.add(HttpHeaderNames.SEC_WEBSOCKET_VERSION, "8");
if (customHeaders != null) {
headers.add(customHeaders);
@ -208,17 +206,17 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
throw new WebSocketHandshakeException("Invalid handshake response getStatus: " + response.status());
}
CharSequence upgrade = headers.get(Names.UPGRADE);
if (!AsciiString.equalsIgnoreCase(Values.WEBSOCKET, upgrade)) {
CharSequence upgrade = headers.get(HttpHeaderNames.UPGRADE);
if (!HttpHeaderValues.WEBSOCKET.equalsIgnoreCase(upgrade)) {
throw new WebSocketHandshakeException("Invalid handshake response upgrade: " + upgrade);
}
CharSequence connection = headers.get(Names.CONNECTION);
if (!AsciiString.equalsIgnoreCase(Values.UPGRADE, connection)) {
CharSequence connection = headers.get(HttpHeaderNames.CONNECTION);
if (!HttpHeaderValues.UPGRADE.equalsIgnoreCase(connection)) {
throw new WebSocketHandshakeException("Invalid handshake response connection: " + connection);
}
CharSequence accept = headers.get(Names.SEC_WEBSOCKET_ACCEPT);
CharSequence accept = headers.get(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT);
if (accept == null || !accept.equals(expectedChallengeResponseString)) {
throw new WebSocketHandshakeException(String.format(
"Invalid challenge. Actual: %s. Expected: %s", accept, expectedChallengeResponseString));

View File

@ -15,13 +15,12 @@
*/
package io.netty.handler.codec.http.websocketx;
import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaders.Values;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
@ -41,7 +40,6 @@ import java.net.URI;
public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketClientHandshaker13.class);
private static final CharSequence WEBSOCKET = Values.WEBSOCKET.toLowerCase();
public static final String MAGIC_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
@ -166,10 +164,10 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path);
HttpHeaders headers = request.headers();
headers.add(Names.UPGRADE, WEBSOCKET)
.add(Names.CONNECTION, Values.UPGRADE)
.add(Names.SEC_WEBSOCKET_KEY, key)
.add(Names.HOST, wsURL.getHost() + ':' + wsPort);
headers.add(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET)
.add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE)
.add(HttpHeaderNames.SEC_WEBSOCKET_KEY, key)
.add(HttpHeaderNames.HOST, wsURL.getHost() + ':' + wsPort);
String originValue = "http://" + wsURL.getHost();
if (wsPort != 80 && wsPort != 443) {
@ -177,14 +175,14 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
// See http://tools.ietf.org/html/rfc6454#section-6.2
originValue = originValue + ':' + wsPort;
}
headers.add(Names.SEC_WEBSOCKET_ORIGIN, originValue);
headers.add(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, originValue);
String expectedSubprotocol = expectedSubprotocol();
if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
headers.add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
headers.add(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
}
headers.add(Names.SEC_WEBSOCKET_VERSION, "13");
headers.add(HttpHeaderNames.SEC_WEBSOCKET_VERSION, "13");
if (customHeaders != null) {
headers.add(customHeaders);
@ -218,17 +216,17 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
throw new WebSocketHandshakeException("Invalid handshake response getStatus: " + response.status());
}
CharSequence upgrade = headers.get(Names.UPGRADE);
if (!AsciiString.equalsIgnoreCase(Values.WEBSOCKET, upgrade)) {
CharSequence upgrade = headers.get(HttpHeaderNames.UPGRADE);
if (!HttpHeaderValues.WEBSOCKET.equalsIgnoreCase(upgrade)) {
throw new WebSocketHandshakeException("Invalid handshake response upgrade: " + upgrade);
}
CharSequence connection = headers.get(Names.CONNECTION);
if (!AsciiString.equalsIgnoreCase(Values.UPGRADE, connection)) {
CharSequence connection = headers.get(HttpHeaderNames.CONNECTION);
if (!HttpHeaderValues.UPGRADE.equalsIgnoreCase(connection)) {
throw new WebSocketHandshakeException("Invalid handshake response connection: " + connection);
}
CharSequence accept = headers.get(Names.SEC_WEBSOCKET_ACCEPT);
CharSequence accept = headers.get(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT);
if (accept == null || !accept.equals(expectedChallengeResponseString)) {
throw new WebSocketHandshakeException(String.format(
"Invalid challenge. Actual: %s. Expected: %s", accept, expectedChallengeResponseString));

View File

@ -20,19 +20,16 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaders.Values;
import io.netty.handler.codec.http.HttpResponseStatus;
import java.util.regex.Pattern;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpHeaders.Values.*;
import static io.netty.handler.codec.http.HttpVersion.*;
/**
@ -110,13 +107,14 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
protected FullHttpResponse newHandshakeResponse(FullHttpRequest req, HttpHeaders headers) {
// Serve the WebSocket handshake request.
if (!AsciiString.equalsIgnoreCase(Values.UPGRADE, req.headers().get(CONNECTION))
|| !AsciiString.equalsIgnoreCase(WEBSOCKET, req.headers().get(Names.UPGRADE))) {
if (!HttpHeaderValues.UPGRADE.equalsIgnoreCase(req.headers().get(HttpHeaderNames.CONNECTION))
|| !HttpHeaderValues.WEBSOCKET.equalsIgnoreCase(req.headers().get(HttpHeaderNames.UPGRADE))) {
throw new WebSocketHandshakeException("not a WebSocket handshake request: missing upgrade");
}
// Hixie 75 does not contain these headers while Hixie 76 does
boolean isHixie76 = req.headers().contains(SEC_WEBSOCKET_KEY1) && req.headers().contains(SEC_WEBSOCKET_KEY2);
boolean isHixie76 = req.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_KEY1) &&
req.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_KEY2);
// Create the WebSocket handshake response.
FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, new HttpResponseStatus(101,
@ -125,15 +123,15 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
res.headers().add(headers);
}
res.headers().add(Names.UPGRADE, WEBSOCKET);
res.headers().add(CONNECTION, Values.UPGRADE);
res.headers().add(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
res.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE);
// Fill in the headers and contents depending on handshake getMethod.
if (isHixie76) {
// New handshake getMethod with a challenge:
res.headers().add(SEC_WEBSOCKET_ORIGIN, req.headers().get(ORIGIN));
res.headers().add(SEC_WEBSOCKET_LOCATION, uri());
String subprotocols = req.headers().get(SEC_WEBSOCKET_PROTOCOL);
res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, req.headers().get(HttpHeaderNames.ORIGIN));
res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_LOCATION, uri());
String subprotocols = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL);
if (subprotocols != null) {
String selectedSubprotocol = selectSubprotocol(subprotocols);
if (selectedSubprotocol == null) {
@ -141,13 +139,13 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
logger.debug("Requested subprotocol(s) not supported: {}", subprotocols);
}
} else {
res.headers().add(SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
}
}
// Calculate the answer of the challenge.
String key1 = req.headers().get(SEC_WEBSOCKET_KEY1);
String key2 = req.headers().get(SEC_WEBSOCKET_KEY2);
String key1 = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_KEY1);
String key2 = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_KEY2);
int a = (int) (Long.parseLong(BEGINNING_DIGIT.matcher(key1).replaceAll("")) /
BEGINNING_SPACE.matcher(key1).replaceAll("").length());
int b = (int) (Long.parseLong(BEGINNING_DIGIT.matcher(key2).replaceAll("")) /
@ -160,11 +158,11 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
res.content().writeBytes(WebSocketUtil.md5(input.array()));
} else {
// Old Hixie 75 handshake getMethod with no challenge:
res.headers().add(WEBSOCKET_ORIGIN, req.headers().get(ORIGIN));
res.headers().add(WEBSOCKET_LOCATION, uri());
String protocol = req.headers().get(WEBSOCKET_PROTOCOL);
res.headers().add(HttpHeaderNames.WEBSOCKET_ORIGIN, req.headers().get(HttpHeaderNames.ORIGIN));
res.headers().add(HttpHeaderNames.WEBSOCKET_LOCATION, uri());
String protocol = req.headers().get(HttpHeaderNames.WEBSOCKET_PROTOCOL);
if (protocol != null) {
res.headers().add(WEBSOCKET_PROTOCOL, selectSubprotocol(protocol));
res.headers().add(HttpHeaderNames.WEBSOCKET_PROTOCOL, selectSubprotocol(protocol));
}
}
return res;

View File

@ -18,9 +18,9 @@ package io.netty.handler.codec.http.websocketx;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaders.Values;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.util.CharsetUtil;
@ -35,8 +35,6 @@ import static io.netty.handler.codec.http.HttpVersion.*;
*/
public class WebSocketServerHandshaker07 extends WebSocketServerHandshaker {
private static final CharSequence WEBSOCKET = Values.WEBSOCKET.toLowerCase();
public static final String WEBSOCKET_07_ACCEPT_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
private final boolean allowExtensions;
@ -129,7 +127,7 @@ public class WebSocketServerHandshaker07 extends WebSocketServerHandshaker {
res.headers().add(headers);
}
CharSequence key = req.headers().get(Names.SEC_WEBSOCKET_KEY);
CharSequence key = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_KEY);
if (key == null) {
throw new WebSocketHandshakeException("not a WebSocket request: missing key");
}
@ -141,10 +139,10 @@ public class WebSocketServerHandshaker07 extends WebSocketServerHandshaker {
logger.debug("WebSocket version 07 server handshake key: {}, response: {}.", key, accept);
}
res.headers().add(Names.UPGRADE, WEBSOCKET);
res.headers().add(Names.CONNECTION, Names.UPGRADE);
res.headers().add(Names.SEC_WEBSOCKET_ACCEPT, accept);
String subprotocols = req.headers().get(Names.SEC_WEBSOCKET_PROTOCOL);
res.headers().add(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
res.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE);
res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT, accept);
String subprotocols = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL);
if (subprotocols != null) {
String selectedSubprotocol = selectSubprotocol(subprotocols);
if (selectedSubprotocol == null) {
@ -152,7 +150,7 @@ public class WebSocketServerHandshaker07 extends WebSocketServerHandshaker {
logger.debug("Requested subprotocol(s) not supported: {}", subprotocols);
}
} else {
res.headers().add(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
}
}
return res;

View File

@ -18,9 +18,9 @@ package io.netty.handler.codec.http.websocketx;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaders.Values;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.util.CharsetUtil;
@ -35,8 +35,6 @@ import static io.netty.handler.codec.http.HttpVersion.*;
*/
public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
private static final CharSequence WEBSOCKET = Values.WEBSOCKET.toLowerCase();
public static final String WEBSOCKET_08_ACCEPT_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
private final boolean allowExtensions;
@ -128,7 +126,7 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
res.headers().add(headers);
}
CharSequence key = req.headers().get(Names.SEC_WEBSOCKET_KEY);
CharSequence key = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_KEY);
if (key == null) {
throw new WebSocketHandshakeException("not a WebSocket request: missing key");
}
@ -140,10 +138,10 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
logger.debug("WebSocket version 08 server handshake key: {}, response: {}", key, accept);
}
res.headers().add(Names.UPGRADE, WEBSOCKET);
res.headers().add(Names.CONNECTION, Names.UPGRADE);
res.headers().add(Names.SEC_WEBSOCKET_ACCEPT, accept);
String subprotocols = req.headers().get(Names.SEC_WEBSOCKET_PROTOCOL);
res.headers().add(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
res.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE);
res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT, accept);
String subprotocols = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL);
if (subprotocols != null) {
String selectedSubprotocol = selectSubprotocol(subprotocols);
if (selectedSubprotocol == null) {
@ -151,7 +149,7 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
logger.debug("Requested subprotocol(s) not supported: {}", subprotocols);
}
} else {
res.headers().add(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
}
}
return res;

View File

@ -18,9 +18,9 @@ package io.netty.handler.codec.http.websocketx;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaders.Values;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.util.CharsetUtil;
@ -34,8 +34,6 @@ import static io.netty.handler.codec.http.HttpVersion.*;
*/
public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
private static final CharSequence WEBSOCKET = Values.WEBSOCKET.toLowerCase();
public static final String WEBSOCKET_13_ACCEPT_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
private final boolean allowExtensions;
@ -126,7 +124,7 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
res.headers().add(headers);
}
CharSequence key = req.headers().get(Names.SEC_WEBSOCKET_KEY);
CharSequence key = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_KEY);
if (key == null) {
throw new WebSocketHandshakeException("not a WebSocket request: missing key");
}
@ -138,10 +136,10 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
logger.debug("WebSocket version 13 server handshake key: {}, response: {}", key, accept);
}
res.headers().add(Names.UPGRADE, WEBSOCKET);
res.headers().add(Names.CONNECTION, Names.UPGRADE);
res.headers().add(Names.SEC_WEBSOCKET_ACCEPT, accept);
String subprotocols = req.headers().get(Names.SEC_WEBSOCKET_PROTOCOL);
res.headers().add(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
res.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE);
res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT, accept);
String subprotocols = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL);
if (subprotocols != null) {
String selectedSubprotocol = selectSubprotocol(subprotocols);
if (selectedSubprotocol == null) {
@ -149,7 +147,7 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
logger.debug("Requested subprotocol(s) not supported: {}", subprotocols);
}
} else {
res.headers().add(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
}
}
return res;

View File

@ -19,7 +19,7 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.DefaultHttpResponse;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
@ -112,7 +112,7 @@ public class WebSocketServerHandshakerFactory {
*/
public WebSocketServerHandshaker newHandshaker(HttpRequest req) {
CharSequence version = req.headers().get(Names.SEC_WEBSOCKET_VERSION);
CharSequence version = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_VERSION);
if (version != null) {
if (version.equals(WebSocketVersion.V13.toHttpHeaderValue())) {
// Version 13 of the wire protocol - RFC 6455 (version 17 of the draft hybi specification).
@ -157,7 +157,7 @@ public class WebSocketServerHandshakerFactory {
HttpResponse res = new DefaultHttpResponse(
HttpVersion.HTTP_1_1,
HttpResponseStatus.UPGRADE_REQUIRED);
res.headers().set(Names.SEC_WEBSOCKET_VERSION, WebSocketVersion.V13.toHttpHeaderValue());
res.headers().set(HttpHeaderNames.SEC_WEBSOCKET_VERSION, WebSocketVersion.V13.toHttpHeaderValue());
return channel.write(res, promise);
}
}

View File

@ -22,11 +22,12 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.ssl.SslHandler;
import static io.netty.handler.codec.http.HttpHeaders.*;
import static io.netty.handler.codec.http.HttpHeaderUtil.*;
import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
@ -101,7 +102,6 @@ class WebSocketServerProtocolHandshakeHandler extends ChannelInboundHandlerAdapt
// SSL in use so use Secure WebSockets
protocol = "wss";
}
return protocol + "://" + req.headers().get(Names.HOST) + path;
return protocol + "://" + req.headers().get(HttpHeaderNames.HOST) + path;
}
}

View File

@ -0,0 +1,207 @@
/*
* 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.rtsp;
import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.http.HttpHeaderNames;
/**
* Standard RTSP header names.
* <p>
* These are all defined as lowercase to support HTTP/2 requirements while also not
* violating RTSP/1.x requirements. New header names should always be lowercase.
*/
public final class RtspHeaderNames {
/**
* {@code "accept"}
*/
public static final AsciiString ACCEPT = HttpHeaderNames.ACCEPT;
/**
* {@code "accept-encoding"}
*/
public static final AsciiString ACCEPT_ENCODING = HttpHeaderNames.ACCEPT_ENCODING;
/**
* {@code "accept-lanugage"}
*/
public static final AsciiString ACCEPT_LANGUAGE = HttpHeaderNames.ACCEPT_LANGUAGE;
/**
* {@code "allow"}
*/
public static final AsciiString ALLOW = new AsciiString("allow");
/**
* {@code "authorization"}
*/
public static final AsciiString AUTHORIZATION = HttpHeaderNames.AUTHORIZATION;
/**
* {@code "bandwidth"}
*/
public static final AsciiString BANDWIDTH = new AsciiString("bandwidth");
/**
* {@code "blocksize"}
*/
public static final AsciiString BLOCKSIZE = new AsciiString("blocksize");
/**
* {@code "cache-control"}
*/
public static final AsciiString CACHE_CONTROL = HttpHeaderNames.CACHE_CONTROL;
/**
* {@code "conference"}
*/
public static final AsciiString CONFERENCE = new AsciiString("conference");
/**
* {@code "connection"}
*/
public static final AsciiString CONNECTION = HttpHeaderNames.CONNECTION;
/**
* {@code "content-base"}
*/
public static final AsciiString CONTENT_BASE = HttpHeaderNames.CONTENT_BASE;
/**
* {@code "content-encoding"}
*/
public static final AsciiString CONTENT_ENCODING = HttpHeaderNames.CONTENT_ENCODING;
/**
* {@code "content-language"}
*/
public static final AsciiString CONTENT_LANGUAGE = HttpHeaderNames.CONTENT_LANGUAGE;
/**
* {@code "content-length"}
*/
public static final AsciiString CONTENT_LENGTH = HttpHeaderNames.CONTENT_LENGTH;
/**
* {@code "content-location"}
*/
public static final AsciiString CONTENT_LOCATION = HttpHeaderNames.CONTENT_LOCATION;
/**
* {@code "content-type"}
*/
public static final AsciiString CONTENT_TYPE = HttpHeaderNames.CONTENT_TYPE;
/**
* {@code "cseq"}
*/
public static final AsciiString CSEQ = new AsciiString("cseq");
/**
* {@code "cate"}
*/
public static final AsciiString DATE = HttpHeaderNames.DATE;
/**
* {@code "expires"}
*/
public static final AsciiString EXPIRES = HttpHeaderNames.EXPIRES;
/**
* {@code "from"}
*/
public static final AsciiString FROM = HttpHeaderNames.FROM;
/**
* {@code "host"}
*/
public static final AsciiString HOST = HttpHeaderNames.HOST;
/**
* {@code "if-match"}
*/
public static final AsciiString IF_MATCH = HttpHeaderNames.IF_MATCH;
/**
* {@code "if-modified-since"}
*/
public static final AsciiString IF_MODIFIED_SINCE = HttpHeaderNames.IF_MODIFIED_SINCE;
/**
* {@code "keymgmt"}
*/
public static final AsciiString KEYMGMT = new AsciiString("keymgmt");
/**
* {@code "last-modified"}
*/
public static final AsciiString LAST_MODIFIED = HttpHeaderNames.LAST_MODIFIED;
/**
* {@code "proxy-authenticate"}
*/
public static final AsciiString PROXY_AUTHENTICATE = HttpHeaderNames.PROXY_AUTHENTICATE;
/**
* {@code "proxy-require"}
*/
public static final AsciiString PROXY_REQUIRE = new AsciiString("proxy-require");
/**
* {@code "public"}
*/
public static final AsciiString PUBLIC = new AsciiString("public");
/**
* {@code "range"}
*/
public static final AsciiString RANGE = HttpHeaderNames.RANGE;
/**
* {@code "referer"}
*/
public static final AsciiString REFERER = HttpHeaderNames.REFERER;
/**
* {@code "require"}
*/
public static final AsciiString REQUIRE = new AsciiString("require");
/**
* {@code "retry-after"}
*/
public static final AsciiString RETRT_AFTER = HttpHeaderNames.RETRY_AFTER;
/**
* {@code "rtp-info"}
*/
public static final AsciiString RTP_INFO = new AsciiString("rtp-info");
/**
* {@code "scale"}
*/
public static final AsciiString SCALE = new AsciiString("scale");
/**
* {@code "session"}
*/
public static final AsciiString SESSION = new AsciiString("session");
/**
* {@code "server"}
*/
public static final AsciiString SERVER = HttpHeaderNames.SERVER;
/**
* {@code "speed"}
*/
public static final AsciiString SPEED = new AsciiString("speed");
/**
* {@code "timestamp"}
*/
public static final AsciiString TIMESTAMP = new AsciiString("timestamp");
/**
* {@code "transport"}
*/
public static final AsciiString TRANSPORT = new AsciiString("transport");
/**
* {@code "unsupported"}
*/
public static final AsciiString UNSUPPORTED = new AsciiString("unsupported");
/**
* {@code "user-agent"}
*/
public static final AsciiString USER_AGENT = HttpHeaderNames.USER_AGENT;
/**
* {@code "vary"}
*/
public static final AsciiString VARY = HttpHeaderNames.VARY;
/**
* {@code "via"}
*/
public static final AsciiString VIA = HttpHeaderNames.VIA;
/**
* {@code "www-authenticate"}
*/
public static final AsciiString WWW_AUTHENTICATE = HttpHeaderNames.WWW_AUTHENTICATE;
private RtspHeaderNames() { }
}

View File

@ -0,0 +1,196 @@
/*
* 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.rtsp;
import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.http.HttpHeaderValues;
/**
* Standard RTSP header names.
*/
public final class RtspHeaderValues {
/**
* {@code "append"}
*/
public static final AsciiString APPEND = new AsciiString("append");
/**
* {@code "AVP"}
*/
public static final AsciiString AVP = new AsciiString("AVP");
/**
* {@code "bytes"}
*/
public static final AsciiString BYTES = HttpHeaderValues.BYTES;
/**
* {@code "charset"}
*/
public static final AsciiString CHARSET = HttpHeaderValues.CHARSET;
/**
* {@code "client_port"}
*/
public static final AsciiString CLIENT_PORT = new AsciiString("client_port");
/**
* {@code "clock"}
*/
public static final AsciiString CLOCK = new AsciiString("clock");
/**
* {@code "close"}
*/
public static final AsciiString CLOSE = HttpHeaderValues.CLOSE;
/**
* {@code "compress"}
*/
public static final AsciiString COMPRESS = HttpHeaderValues.COMPRESS;
/**
* {@code "100-continue"}
*/
public static final AsciiString CONTINUE = HttpHeaderValues.CONTINUE;
/**
* {@code "deflate"}
*/
public static final AsciiString DEFLATE = HttpHeaderValues.DEFLATE;
/**
* {@code "destination"}
*/
public static final AsciiString DESTINATION = new AsciiString("destination");
/**
* {@code "gzip"}
*/
public static final AsciiString GZIP = HttpHeaderValues.GZIP;
/**
* {@code "identity"}
*/
public static final AsciiString IDENTITY = HttpHeaderValues.IDENTITY;
/**
* {@code "interleaved"}
*/
public static final AsciiString INTERLEAVED = new AsciiString("interleaved");
/**
* {@code "keep-alive"}
*/
public static final AsciiString KEEP_ALIVE = HttpHeaderValues.KEEP_ALIVE;
/**
* {@code "layers"}
*/
public static final AsciiString LAYERS = new AsciiString("layers");
/**
* {@code "max-age"}
*/
public static final AsciiString MAX_AGE = HttpHeaderValues.MAX_AGE;
/**
* {@code "max-stale"}
*/
public static final AsciiString MAX_STALE = HttpHeaderValues.MAX_STALE;
/**
* {@code "min-fresh"}
*/
public static final AsciiString MIN_FRESH = HttpHeaderValues.MIN_FRESH;
/**
* {@code "mode"}
*/
public static final AsciiString MODE = new AsciiString("mode");
/**
* {@code "multicast"}
*/
public static final AsciiString MULTICAST = new AsciiString("multicast");
/**
* {@code "must-revalidate"}
*/
public static final AsciiString MUST_REVALIDATE = HttpHeaderValues.MUST_REVALIDATE;
/**
* {@code "none"}
*/
public static final AsciiString NONE = HttpHeaderValues.NONE;
/**
* {@code "no-cache"}
*/
public static final AsciiString NO_CACHE = HttpHeaderValues.NO_CACHE;
/**
* {@code "no-transform"}
*/
public static final AsciiString NO_TRANSFORM = HttpHeaderValues.NO_TRANSFORM;
/**
* {@code "only-if-cached"}
*/
public static final AsciiString ONLY_IF_CACHED = HttpHeaderValues.ONLY_IF_CACHED;
/**
* {@code "port"}
*/
public static final AsciiString PORT = new AsciiString("port");
/**
* {@code "private"}
*/
public static final AsciiString PRIVATE = HttpHeaderValues.PRIVATE;
/**
* {@code "proxy-revalidate"}
*/
public static final AsciiString PROXY_REVALIDATE = HttpHeaderValues.PROXY_REVALIDATE;
/**
* {@code "public"}
*/
public static final AsciiString PUBLIC = HttpHeaderValues.PUBLIC;
/**
* {@code "RTP"}
*/
public static final AsciiString RTP = new AsciiString("RTP");
/**
* {@code "rtptime"}
*/
public static final AsciiString RTPTIME = new AsciiString("rtptime");
/**
* {@code "seq"}
*/
public static final AsciiString SEQ = new AsciiString("seq");
/**
* {@code "server_port"}
*/
public static final AsciiString SERVER_PORT = new AsciiString("server_port");
/**
* {@code "ssrc"}
*/
public static final AsciiString SSRC = new AsciiString("ssrc");
/**
* {@code "TCP"}
*/
public static final AsciiString TCP = new AsciiString("TCP");
/**
* {@code "time"}
*/
public static final AsciiString TIME = new AsciiString("time");
/**
* {@code "timeout"}
*/
public static final AsciiString TIMEOUT = new AsciiString("timeout");
/**
* {@code "ttl"}
*/
public static final AsciiString TTL = new AsciiString("ttl");
/**
* {@code "UDP"}
*/
public static final AsciiString UDP = new AsciiString("UDP");
/**
* {@code "unicast"}
*/
public static final AsciiString UNICAST = new AsciiString("unicast");
/**
* {@code "url"}
*/
public static final AsciiString URL = new AsciiString("url");
private RtspHeaderValues() { }
}

View File

@ -15,203 +15,211 @@
*/
package io.netty.handler.codec.rtsp;
import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.http.HttpHeaders;
/**
* @deprecated Use {@link RtspHeaderNames} or {@link RtspHeaderValues} instead.
* Standard RTSP header names and values.
*/
@Deprecated
public final class RtspHeaders {
/**
* @deprecated Use {@link RtspHeaderNames} instead.
*
* Standard RTSP header names.
*/
@Deprecated
public static final class Names {
/**
* {@code "Accept"}
*/
public static final AsciiString ACCEPT = HttpHeaders.Names.ACCEPT;
public static final String ACCEPT = HttpHeaders.Names.ACCEPT;
/**
* {@code "Accept-Encoding"}
*/
public static final AsciiString ACCEPT_ENCODING = HttpHeaders.Names.ACCEPT_ENCODING;
public static final String ACCEPT_ENCODING = HttpHeaders.Names.ACCEPT_ENCODING;
/**
* {@code "Accept-Lanugage"}
*/
public static final AsciiString ACCEPT_LANGUAGE = HttpHeaders.Names.ACCEPT_LANGUAGE;
public static final String ACCEPT_LANGUAGE = HttpHeaders.Names.ACCEPT_LANGUAGE;
/**
* {@code "Allow"}
*/
public static final AsciiString ALLOW = new AsciiString("Allow");
public static final String ALLOW = "Allow";
/**
* {@code "Authorization"}
*/
public static final AsciiString AUTHORIZATION = HttpHeaders.Names.AUTHORIZATION;
public static final String AUTHORIZATION = HttpHeaders.Names.AUTHORIZATION;
/**
* {@code "Bandwidth"}
*/
public static final AsciiString BANDWIDTH = new AsciiString("Bandwidth");
public static final String BANDWIDTH = "Bandwidth";
/**
* {@code "Blocksize"}
*/
public static final AsciiString BLOCKSIZE = new AsciiString("Blocksize");
public static final String BLOCKSIZE = "Blocksize";
/**
* {@code "Cache-Control"}
*/
public static final AsciiString CACHE_CONTROL = HttpHeaders.Names.CACHE_CONTROL;
public static final String CACHE_CONTROL = HttpHeaders.Names.CACHE_CONTROL;
/**
* {@code "Conference"}
*/
public static final AsciiString CONFERENCE = new AsciiString("Conference");
public static final String CONFERENCE = "Conference";
/**
* {@code "Connection"}
*/
public static final AsciiString CONNECTION = HttpHeaders.Names.CONNECTION;
public static final String CONNECTION = HttpHeaders.Names.CONNECTION;
/**
* {@code "Content-Base"}
*/
public static final AsciiString CONTENT_BASE = HttpHeaders.Names.CONTENT_BASE;
public static final String CONTENT_BASE = HttpHeaders.Names.CONTENT_BASE;
/**
* {@code "Content-Encoding"}
*/
public static final AsciiString CONTENT_ENCODING = HttpHeaders.Names.CONTENT_ENCODING;
public static final String CONTENT_ENCODING = HttpHeaders.Names.CONTENT_ENCODING;
/**
* {@code "Content-Language"}
*/
public static final AsciiString CONTENT_LANGUAGE = HttpHeaders.Names.CONTENT_LANGUAGE;
public static final String CONTENT_LANGUAGE = HttpHeaders.Names.CONTENT_LANGUAGE;
/**
* {@code "Content-Length"}
*/
public static final AsciiString CONTENT_LENGTH = HttpHeaders.Names.CONTENT_LENGTH;
public static final String CONTENT_LENGTH = HttpHeaders.Names.CONTENT_LENGTH;
/**
* {@code "Content-Location"}
*/
public static final AsciiString CONTENT_LOCATION = HttpHeaders.Names.CONTENT_LOCATION;
public static final String CONTENT_LOCATION = HttpHeaders.Names.CONTENT_LOCATION;
/**
* {@code "Content-Type"}
*/
public static final AsciiString CONTENT_TYPE = HttpHeaders.Names.CONTENT_TYPE;
public static final String CONTENT_TYPE = HttpHeaders.Names.CONTENT_TYPE;
/**
* {@code "CSeq"}
*/
public static final AsciiString CSEQ = new AsciiString("CSeq");
public static final String CSEQ = "CSeq";
/**
* {@code "Date"}
*/
public static final AsciiString DATE = HttpHeaders.Names.DATE;
public static final String DATE = HttpHeaders.Names.DATE;
/**
* {@code "Expires"}
*/
public static final AsciiString EXPIRES = HttpHeaders.Names.EXPIRES;
public static final String EXPIRES = HttpHeaders.Names.EXPIRES;
/**
* {@code "From"}
*/
public static final AsciiString FROM = HttpHeaders.Names.FROM;
public static final String FROM = HttpHeaders.Names.FROM;
/**
* {@code "Host"}
*/
public static final AsciiString HOST = HttpHeaders.Names.HOST;
public static final String HOST = HttpHeaders.Names.HOST;
/**
* {@code "If-Match"}
*/
public static final AsciiString IF_MATCH = HttpHeaders.Names.IF_MATCH;
public static final String IF_MATCH = HttpHeaders.Names.IF_MATCH;
/**
* {@code "If-Modified-Since"}
*/
public static final AsciiString IF_MODIFIED_SINCE = HttpHeaders.Names.IF_MODIFIED_SINCE;
public static final String IF_MODIFIED_SINCE = HttpHeaders.Names.IF_MODIFIED_SINCE;
/**
* {@code "KeyMgmt"}
*/
public static final AsciiString KEYMGMT = new AsciiString("KeyMgmt");
public static final String KEYMGMT = "KeyMgmt";
/**
* {@code "Last-Modified"}
*/
public static final AsciiString LAST_MODIFIED = HttpHeaders.Names.LAST_MODIFIED;
public static final String LAST_MODIFIED = HttpHeaders.Names.LAST_MODIFIED;
/**
* {@code "Proxy-Authenticate"}
*/
public static final AsciiString PROXY_AUTHENTICATE = HttpHeaders.Names.PROXY_AUTHENTICATE;
public static final String PROXY_AUTHENTICATE = HttpHeaders.Names.PROXY_AUTHENTICATE;
/**
* {@code "Proxy-Require"}
*/
public static final AsciiString PROXY_REQUIRE = new AsciiString("Proxy-Require");
public static final String PROXY_REQUIRE = "Proxy-Require";
/**
* {@code "Public"}
*/
public static final AsciiString PUBLIC = new AsciiString("Public");
public static final String PUBLIC = "Public";
/**
* {@code "Range"}
*/
public static final AsciiString RANGE = HttpHeaders.Names.RANGE;
public static final String RANGE = HttpHeaders.Names.RANGE;
/**
* {@code "Referer"}
*/
public static final AsciiString REFERER = HttpHeaders.Names.REFERER;
public static final String REFERER = HttpHeaders.Names.REFERER;
/**
* {@code "Require"}
*/
public static final AsciiString REQUIRE = new AsciiString("Require");
public static final String REQUIRE = "Require";
/**
* {@code "Retry-After"}
*/
public static final AsciiString RETRT_AFTER = HttpHeaders.Names.RETRY_AFTER;
public static final String RETRT_AFTER = HttpHeaders.Names.RETRY_AFTER;
/**
* {@code "RTP-Info"}
*/
public static final AsciiString RTP_INFO = new AsciiString("RTP-Info");
public static final String RTP_INFO = "RTP-Info";
/**
* {@code "Scale"}
*/
public static final AsciiString SCALE = new AsciiString("Scale");
public static final String SCALE = "Scale";
/**
* {@code "Session"}
*/
public static final AsciiString SESSION = new AsciiString("Session");
public static final String SESSION = "Session";
/**
* {@code "Server"}
*/
public static final AsciiString SERVER = HttpHeaders.Names.SERVER;
public static final String SERVER = HttpHeaders.Names.SERVER;
/**
* {@code "Speed"}
*/
public static final AsciiString SPEED = new AsciiString("Speed");
public static final String SPEED = "Speed";
/**
* {@code "Timestamp"}
*/
public static final AsciiString TIMESTAMP = new AsciiString("Timestamp");
public static final String TIMESTAMP = "Timestamp";
/**
* {@code "Transport"}
*/
public static final AsciiString TRANSPORT = new AsciiString("Transport");
public static final String TRANSPORT = "Transport";
/**
* {@code "Unsupported"}
*/
public static final AsciiString UNSUPPORTED = new AsciiString("Unsupported");
public static final String UNSUPPORTED = "Unsupported";
/**
* {@code "User-Agent"}
*/
public static final AsciiString USER_AGENT = HttpHeaders.Names.USER_AGENT;
public static final String USER_AGENT = HttpHeaders.Names.USER_AGENT;
/**
* {@code "Vary"}
*/
public static final AsciiString VARY = HttpHeaders.Names.VARY;
public static final String VARY = HttpHeaders.Names.VARY;
/**
* {@code "Via"}
*/
public static final AsciiString VIA = HttpHeaders.Names.VIA;
public static final String VIA = HttpHeaders.Names.VIA;
/**
* {@code "WWW-Authenticate"}
*/
public static final AsciiString WWW_AUTHENTICATE = HttpHeaders.Names.WWW_AUTHENTICATE;
public static final String WWW_AUTHENTICATE = HttpHeaders.Names.WWW_AUTHENTICATE;
private Names() {
}
}
/**
* @deprecated Use {@link RtspHeaderValues} instead.
*
* Standard RTSP header values.
*/
@Deprecated
public static final class Values {
/**
* {@code "append"}
@ -248,7 +256,7 @@ public final class RtspHeaders {
/**
* {@code "100-continue"}
*/
public static final String CONTINUE = HttpHeaders.Values.CONTINUE;
public static final String CONTINUE = HttpHeaders.Values.CONTINUE;
/**
* {@code "deflate"}
*/

View File

@ -79,7 +79,7 @@ public abstract class RtspObjectDecoder extends HttpObjectDecoder {
if (empty) {
return true;
}
if (!msg.headers().contains(RtspHeaders.Names.CONTENT_LENGTH)) {
if (!msg.headers().contains(RtspHeaderNames.CONTENT_LENGTH)) {
return true;
}
return empty;

View File

@ -24,7 +24,8 @@ import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpMessage;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderUtil;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
@ -170,14 +171,13 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
createHttpResponse(ctx, spdySynStreamFrame, validateHeaders);
// Set the Stream-ID, Associated-To-Stream-ID, Priority, and URL as headers
HttpHeaders.setIntHeader(httpResponseWithEntity, Names.STREAM_ID, streamId);
HttpHeaders.setIntHeader(
httpResponseWithEntity, Names.ASSOCIATED_TO_STREAM_ID, associatedToStreamId);
HttpHeaders.setIntHeader(httpResponseWithEntity, Names.PRIORITY, spdySynStreamFrame.priority());
httpResponseWithEntity.headers().setInt(Names.STREAM_ID, streamId);
httpResponseWithEntity.headers().setInt(Names.ASSOCIATED_TO_STREAM_ID, associatedToStreamId);
httpResponseWithEntity.headers().setInt(Names.PRIORITY, spdySynStreamFrame.priority());
httpResponseWithEntity.headers().set(Names.URL, URL);
if (spdySynStreamFrame.isLast()) {
HttpHeaders.setContentLength(httpResponseWithEntity, 0);
HttpHeaderUtil.setContentLength(httpResponseWithEntity, 0);
out.add(httpResponseWithEntity);
} else {
// Response body will follow in a series of Data Frames
@ -207,7 +207,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
FullHttpRequest httpRequestWithEntity = createHttpRequest(spdyVersion, spdySynStreamFrame);
// Set the Stream-ID as a header
HttpHeaders.setIntHeader(httpRequestWithEntity, Names.STREAM_ID, streamId);
httpRequestWithEntity.headers().setInt(Names.STREAM_ID, streamId);
if (spdySynStreamFrame.isLast()) {
out.add(httpRequestWithEntity);
@ -246,10 +246,10 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
FullHttpResponse httpResponseWithEntity = createHttpResponse(ctx, spdySynReplyFrame, validateHeaders);
// Set the Stream-ID as a header
HttpHeaders.setIntHeader(httpResponseWithEntity, Names.STREAM_ID, streamId);
httpResponseWithEntity.headers().setInt(Names.STREAM_ID, streamId);
if (spdySynReplyFrame.isLast()) {
HttpHeaders.setContentLength(httpResponseWithEntity, 0);
HttpHeaderUtil.setContentLength(httpResponseWithEntity, 0);
out.add(httpResponseWithEntity);
} else {
// Response body will follow in a series of Data Frames
@ -282,7 +282,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
}
if (spdyHeadersFrame.isLast()) {
HttpHeaders.setContentLength(fullHttpMessage, fullHttpMessage.content().readableBytes());
HttpHeaderUtil.setContentLength(fullHttpMessage, fullHttpMessage.content().readableBytes());
removeMessage(streamId);
out.add(fullHttpMessage);
}
@ -310,7 +310,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
content.writeBytes(spdyDataFrameData, spdyDataFrameData.readerIndex(), spdyDataFrameDataLen);
if (spdyDataFrame.isLast()) {
HttpHeaders.setContentLength(fullHttpMessage, content.readableBytes());
HttpHeaderUtil.setContentLength(fullHttpMessage, content.readableBytes());
removeMessage(streamId);
out.add(fullHttpMessage);
}
@ -342,17 +342,17 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
// Replace the SPDY host header with the HTTP host header
CharSequence host = headers.get(HOST);
headers.remove(HOST);
req.headers().set(HttpHeaders.Names.HOST, host);
req.headers().set(HttpHeaderNames.HOST, host);
for (Map.Entry<CharSequence, CharSequence> e: requestFrame.headers()) {
req.headers().add(e.getKey(), e.getValue());
}
// The Connection and Keep-Alive headers are no longer valid
HttpHeaders.setKeepAlive(req, true);
HttpHeaderUtil.setKeepAlive(req, true);
// Transfer-Encoding header is not valid
req.headers().remove(HttpHeaders.Names.TRANSFER_ENCODING);
req.headers().remove(HttpHeaderNames.TRANSFER_ENCODING);
return req;
}
@ -373,11 +373,11 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
}
// The Connection and Keep-Alive headers are no longer valid
HttpHeaders.setKeepAlive(res, true);
HttpHeaderUtil.setKeepAlive(res, true);
// Transfer-Encoding header is not valid
res.headers().remove(HttpHeaders.Names.TRANSFER_ENCODING);
res.headers().remove(HttpHeaders.Names.TRAILER);
res.headers().remove(HttpHeaderNames.TRANSFER_ENCODING);
res.headers().remove(HttpHeaderNames.TRAILER);
return res;
}

View File

@ -21,6 +21,7 @@ import io.netty.handler.codec.UnsupportedMessageTypeException;
import io.netty.handler.codec.http.FullHttpMessage;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMessage;
import io.netty.handler.codec.http.HttpObject;
@ -209,9 +210,9 @@ public class SpdyHttpEncoder extends MessageToMessageEncoder<HttpObject> {
throws Exception {
// Get the Stream-ID, Associated-To-Stream-ID, Priority, URL, and scheme from the headers
final HttpHeaders httpHeaders = httpMessage.headers();
int streamID = HttpHeaders.getIntHeader(httpMessage, Names.STREAM_ID);
int associatedToStreamId = HttpHeaders.getIntHeader(httpMessage, Names.ASSOCIATED_TO_STREAM_ID, 0);
byte priority = (byte) HttpHeaders.getIntHeader(httpMessage, Names.PRIORITY, 0);
int streamID = httpMessage.headers().getInt(Names.STREAM_ID);
int associatedToStreamId = httpMessage.headers().getInt(Names.ASSOCIATED_TO_STREAM_ID, 0);
byte priority = (byte) httpMessage.headers().getInt(Names.PRIORITY, 0);
String URL = httpHeaders.get(Names.URL);
String scheme = httpHeaders.get(Names.SCHEME);
httpHeaders.remove(Names.STREAM_ID);
@ -222,10 +223,10 @@ public class SpdyHttpEncoder extends MessageToMessageEncoder<HttpObject> {
// The Connection, Keep-Alive, Proxy-Connection, and Transfer-Encoding
// headers are not valid and MUST not be sent.
httpHeaders.remove(HttpHeaders.Names.CONNECTION);
httpHeaders.remove(HttpHeaderNames.CONNECTION);
httpHeaders.remove("Keep-Alive");
httpHeaders.remove("Proxy-Connection");
httpHeaders.remove(HttpHeaders.Names.TRANSFER_ENCODING);
httpHeaders.remove(HttpHeaderNames.TRANSFER_ENCODING);
SpdySynStreamFrame spdySynStreamFrame =
new DefaultSpdySynStreamFrame(streamID, associatedToStreamId, priority);
@ -248,8 +249,8 @@ public class SpdyHttpEncoder extends MessageToMessageEncoder<HttpObject> {
// Replace the HTTP host header with the SPDY host header
if (spdyVersion >= 3) {
String host = HttpHeaders.getHost(httpMessage);
httpHeaders.remove(HttpHeaders.Names.HOST);
String host = httpMessage.headers().get(HttpHeaderNames.HOST);
httpHeaders.remove(HttpHeaderNames.HOST);
frameHeaders.set(HOST, host);
}
@ -273,15 +274,15 @@ public class SpdyHttpEncoder extends MessageToMessageEncoder<HttpObject> {
throws Exception {
// Get the Stream-ID from the headers
final HttpHeaders httpHeaders = httpResponse.headers();
int streamID = HttpHeaders.getIntHeader(httpResponse, Names.STREAM_ID);
int streamID = httpResponse.headers().getInt(Names.STREAM_ID);
httpHeaders.remove(Names.STREAM_ID);
// The Connection, Keep-Alive, Proxy-Connection, and Transfer-Encoding
// headers are not valid and MUST not be sent.
httpHeaders.remove(HttpHeaders.Names.CONNECTION);
httpHeaders.remove(HttpHeaderNames.CONNECTION);
httpHeaders.remove("Keep-Alive");
httpHeaders.remove("Proxy-Connection");
httpHeaders.remove(HttpHeaders.Names.TRANSFER_ENCODING);
httpHeaders.remove(HttpHeaderNames.TRANSFER_ENCODING);
SpdySynReplyFrame spdySynReplyFrame = new DefaultSpdySynReplyFrame(streamID);
SpdyHeaders frameHeaders = spdySynReplyFrame.headers();

View File

@ -17,7 +17,6 @@ package io.netty.handler.codec.spdy;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMessage;
import io.netty.handler.codec.spdy.SpdyHttpHeaders.Names;
import io.netty.util.ReferenceCountUtil;
@ -45,7 +44,7 @@ public class SpdyHttpResponseStreamIdHandler extends
protected void encode(ChannelHandlerContext ctx, HttpMessage msg, List<Object> out) throws Exception {
Integer id = ids.poll();
if (id != null && id.intValue() != NO_ID && !msg.headers().contains(SpdyHttpHeaders.Names.STREAM_ID)) {
HttpHeaders.setIntHeader(msg, Names.STREAM_ID, id);
msg.headers().setInt(Names.STREAM_ID, id);
}
out.add(ReferenceCountUtil.retain(msg));
@ -58,7 +57,7 @@ public class SpdyHttpResponseStreamIdHandler extends
if (!contains) {
ids.add(NO_ID);
} else {
ids.add(HttpHeaders.getIntHeader((HttpMessage) msg, Names.STREAM_ID));
ids.add(((HttpMessage) msg).headers().getInt(Names.STREAM_ID));
}
} else if (msg instanceof SpdyRstStreamFrame) {
ids.remove(((SpdyRstStreamFrame) msg).streamId());

View File

@ -19,8 +19,6 @@ import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.compression.ZlibWrapper;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaders.Values;
import io.netty.util.CharsetUtil;
import org.junit.Test;
@ -110,7 +108,7 @@ public class HttpContentCompressorTest {
ch.writeInbound(newRequest());
HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
res.headers().set(Names.TRANSFER_ENCODING, Values.CHUNKED);
res.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
ch.writeOutbound(res);
assertEncodedResponse(ch);
@ -151,7 +149,7 @@ public class HttpContentCompressorTest {
ch.writeInbound(newRequest());
HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
res.headers().set(Names.TRANSFER_ENCODING, Values.CHUNKED);
res.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
ch.writeOutbound(res);
assertEncodedResponse(ch);
@ -197,7 +195,7 @@ public class HttpContentCompressorTest {
FullHttpResponse res = new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK,
Unpooled.copiedBuffer("Hello, World", CharsetUtil.US_ASCII));
res.headers().set(Names.CONTENT_LENGTH, res.content().readableBytes());
res.headers().set(HttpHeaderNames.CONTENT_LENGTH, res.content().readableBytes());
ch.writeOutbound(res);
assertEncodedResponse(ch);
@ -262,10 +260,10 @@ public class HttpContentCompressorTest {
assertThat(o, is(instanceOf(FullHttpResponse.class)));
res = (FullHttpResponse) o;
assertThat(res.headers().get(Names.TRANSFER_ENCODING), is(nullValue()));
assertThat(res.headers().get(HttpHeaderNames.TRANSFER_ENCODING), is(nullValue()));
// Content encoding shouldn't be modified.
assertThat(res.headers().get(Names.CONTENT_ENCODING), is(nullValue()));
assertThat(res.headers().get(HttpHeaderNames.CONTENT_ENCODING), is(nullValue()));
assertThat(res.content().readableBytes(), is(0));
assertThat(res.content().toString(CharsetUtil.US_ASCII), is(""));
res.release();
@ -287,10 +285,10 @@ public class HttpContentCompressorTest {
assertThat(o, is(instanceOf(FullHttpResponse.class)));
res = (FullHttpResponse) o;
assertThat(res.headers().get(Names.TRANSFER_ENCODING), is(nullValue()));
assertThat(res.headers().get(HttpHeaderNames.TRANSFER_ENCODING), is(nullValue()));
// Content encoding shouldn't be modified.
assertThat(res.headers().get(Names.CONTENT_ENCODING), is(nullValue()));
assertThat(res.headers().get(HttpHeaderNames.CONTENT_ENCODING), is(nullValue()));
assertThat(res.content().readableBytes(), is(0));
assertThat(res.content().toString(CharsetUtil.US_ASCII), is(""));
assertEquals("Netty", res.trailingHeaders().get("X-Test"));
@ -299,7 +297,7 @@ public class HttpContentCompressorTest {
private static FullHttpRequest newRequest() {
FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
req.headers().set(Names.ACCEPT_ENCODING, "gzip");
req.headers().set(HttpHeaderNames.ACCEPT_ENCODING, "gzip");
return req;
}
@ -309,8 +307,8 @@ public class HttpContentCompressorTest {
HttpResponse res = (HttpResponse) o;
assertThat(res, is(not(instanceOf(HttpContent.class))));
assertThat(res.headers().get(Names.TRANSFER_ENCODING), is("chunked"));
assertThat(res.headers().get(Names.CONTENT_LENGTH), is(nullValue()));
assertThat(res.headers().get(Names.CONTENT_ENCODING), is("gzip"));
assertThat(res.headers().get(HttpHeaderNames.TRANSFER_ENCODING), is("chunked"));
assertThat(res.headers().get(HttpHeaderNames.CONTENT_LENGTH), is(nullValue()));
assertThat(res.headers().get(HttpHeaderNames.CONTENT_ENCODING), is("gzip"));
}
}

View File

@ -21,8 +21,6 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaders.Values;
import io.netty.util.CharsetUtil;
import org.junit.Test;
@ -83,7 +81,7 @@ public class HttpContentEncoderTest {
ch.writeInbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));
HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
res.headers().set(Names.TRANSFER_ENCODING, Values.CHUNKED);
res.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
ch.writeOutbound(res);
assertEncodedResponse(ch);
@ -120,7 +118,7 @@ public class HttpContentEncoderTest {
ch.writeInbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));
HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
res.headers().set(Names.TRANSFER_ENCODING, Values.CHUNKED);
res.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
ch.writeOutbound(res);
assertEncodedResponse(ch);
@ -161,7 +159,7 @@ public class HttpContentEncoderTest {
FullHttpResponse res = new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(new byte[42]));
res.headers().set(Names.CONTENT_LENGTH, 42);
res.headers().set(HttpHeaderNames.CONTENT_LENGTH, 42);
ch.writeOutbound(res);
assertEncodedResponse(ch);
@ -219,10 +217,10 @@ public class HttpContentEncoderTest {
assertThat(o, is(instanceOf(FullHttpResponse.class)));
res = (FullHttpResponse) o;
assertThat(res.headers().get(Names.TRANSFER_ENCODING), is(nullValue()));
assertThat(res.headers().get(HttpHeaderNames.TRANSFER_ENCODING), is(nullValue()));
// Content encoding shouldn't be modified.
assertThat(res.headers().get(Names.CONTENT_ENCODING), is(nullValue()));
assertThat(res.headers().get(HttpHeaderNames.CONTENT_ENCODING), is(nullValue()));
assertThat(res.content().readableBytes(), is(0));
assertThat(res.content().toString(CharsetUtil.US_ASCII), is(""));
res.release();
@ -244,10 +242,10 @@ public class HttpContentEncoderTest {
assertThat(o, is(instanceOf(FullHttpResponse.class)));
res = (FullHttpResponse) o;
assertThat(res.headers().get(Names.TRANSFER_ENCODING), is(nullValue()));
assertThat(res.headers().get(HttpHeaderNames.TRANSFER_ENCODING), is(nullValue()));
// Content encoding shouldn't be modified.
assertThat(res.headers().get(Names.CONTENT_ENCODING), is(nullValue()));
assertThat(res.headers().get(HttpHeaderNames.CONTENT_ENCODING), is(nullValue()));
assertThat(res.content().readableBytes(), is(0));
assertThat(res.content().toString(CharsetUtil.US_ASCII), is(""));
assertEquals("Netty", res.trailingHeaders().get("X-Test"));
@ -260,8 +258,8 @@ public class HttpContentEncoderTest {
HttpResponse res = (HttpResponse) o;
assertThat(res, is(not(instanceOf(HttpContent.class))));
assertThat(res.headers().get(Names.TRANSFER_ENCODING), is("chunked"));
assertThat(res.headers().get(Names.CONTENT_LENGTH), is(nullValue()));
assertThat(res.headers().get(Names.CONTENT_ENCODING), is("test"));
assertThat(res.headers().get(HttpHeaderNames.TRANSFER_ENCODING), is("chunked"));
assertThat(res.headers().get(HttpHeaderNames.CONTENT_LENGTH), is(nullValue()));
assertThat(res.headers().get(HttpHeaderNames.CONTENT_ENCODING), is("test"));
}
}

View File

@ -28,9 +28,9 @@ public class HttpHeadersTest {
@Test
public void testRemoveTransferEncodingIgnoreCase() {
HttpMessage message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
message.headers().set(HttpHeaders.Names.TRANSFER_ENCODING, "Chunked");
message.headers().set(HttpHeaderNames.TRANSFER_ENCODING, "Chunked");
assertFalse(message.headers().isEmpty());
HttpHeaders.removeTransferEncodingChunked(message);
HttpHeaderUtil.setTransferEncodingChunked(message, false);
assertTrue(message.headers().isEmpty());
}

View File

@ -22,7 +22,6 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.DecoderResultProvider;
import io.netty.handler.codec.TooLongFrameException;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.util.CharsetUtil;
import org.easymock.EasyMock;
import org.junit.Test;
@ -42,7 +41,7 @@ public class HttpObjectAggregatorTest {
EmbeddedChannel embedder = new EmbeddedChannel(aggr);
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost");
HttpHeaders.setHeader(message, "X-Test", true);
message.headers().set("X-Test", true);
HttpContent chunk1 = new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII));
HttpContent chunk2 = new DefaultHttpContent(Unpooled.copiedBuffer("test2", CharsetUtil.US_ASCII));
HttpContent chunk3 = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER);
@ -57,7 +56,7 @@ public class HttpObjectAggregatorTest {
assertNotNull(aggratedMessage);
assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(),
HttpHeaders.getContentLength(aggratedMessage));
HttpHeaderUtil.getContentLength(aggratedMessage));
assertEquals(aggratedMessage.headers().get("X-Test"), Boolean.TRUE.toString());
checkContentBuffer(aggratedMessage);
assertNull(embedder.readInbound());
@ -80,8 +79,8 @@ public class HttpObjectAggregatorTest {
HttpObjectAggregator aggr = new HttpObjectAggregator(1024 * 1024);
EmbeddedChannel embedder = new EmbeddedChannel(aggr);
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost");
HttpHeaders.setHeader(message, "X-Test", true);
HttpHeaders.setTransferEncodingChunked(message);
message.headers().set("X-Test", true);
HttpHeaderUtil.setTransferEncodingChunked(message, true);
HttpContent chunk1 = new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII));
HttpContent chunk2 = new DefaultHttpContent(Unpooled.copiedBuffer("test2", CharsetUtil.US_ASCII));
LastHttpContent trailer = new DefaultLastHttpContent();
@ -98,7 +97,7 @@ public class HttpObjectAggregatorTest {
assertNotNull(aggratedMessage);
assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(),
HttpHeaders.getContentLength(aggratedMessage));
HttpHeaderUtil.getContentLength(aggratedMessage));
assertEquals(aggratedMessage.headers().get("X-Test"), Boolean.TRUE.toString());
assertEquals(aggratedMessage.trailingHeaders().get("X-Trailer"), Boolean.TRUE.toString());
checkContentBuffer(aggratedMessage);
@ -119,7 +118,7 @@ public class HttpObjectAggregatorTest {
FullHttpResponse response = embedder.readOutbound();
assertEquals(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE, response.status());
assertEquals("0", response.headers().get(Names.CONTENT_LENGTH));
assertEquals("0", response.headers().get(HttpHeaderNames.CONTENT_LENGTH));
assertFalse(embedder.isOpen());
try {
@ -136,14 +135,14 @@ public class HttpObjectAggregatorTest {
public void testOversizedRequestWithoutKeepAlive() {
// send a HTTP/1.0 request with no keep-alive header
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.PUT, "http://localhost");
HttpHeaders.setContentLength(message, 5);
HttpHeaderUtil.setContentLength(message, 5);
checkOversizedRequest(message);
}
@Test
public void testOversizedRequestWithContentLength() {
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "http://localhost");
HttpHeaders.setContentLength(message, 5);
HttpHeaderUtil.setContentLength(message, 5);
checkOversizedRequest(message);
}
@ -153,8 +152,8 @@ public class HttpObjectAggregatorTest {
// send an oversized request with 100 continue
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "http://localhost");
HttpHeaders.set100ContinueExpected(message);
HttpHeaders.setContentLength(message, 16);
HttpHeaderUtil.set100ContinueExpected(message, true);
HttpHeaderUtil.setContentLength(message, 16);
HttpContent chunk1 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("some", CharsetUtil.US_ASCII)));
HttpContent chunk2 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII)));
@ -166,7 +165,7 @@ public class HttpObjectAggregatorTest {
// The agregator should respond with '413 Request Entity Too Large.'
FullHttpResponse response = embedder.readOutbound();
assertEquals(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE, response.status());
assertEquals("0", response.headers().get(Names.CONTENT_LENGTH));
assertEquals("0", response.headers().get(HttpHeaderNames.CONTENT_LENGTH));
// An ill-behaving client could continue to send data without a respect, and such data should be discarded.
assertFalse(embedder.writeInbound(chunk1));
@ -186,9 +185,9 @@ public class HttpObjectAggregatorTest {
assertEquals(
chunk2.content().readableBytes() + chunk3.content().readableBytes(),
HttpHeaders.getContentLength(fullMsg));
HttpHeaderUtil.getContentLength(fullMsg));
assertEquals(HttpHeaders.getContentLength(fullMsg), fullMsg.content().readableBytes());
assertEquals(HttpHeaderUtil.getContentLength(fullMsg), fullMsg.content().readableBytes());
fullMsg.release();
assertFalse(embedder.finish());
@ -206,7 +205,7 @@ public class HttpObjectAggregatorTest {
FullHttpResponse response = embedder.readOutbound();
assertEquals(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE, response.status());
assertEquals("0", response.headers().get(Names.CONTENT_LENGTH));
assertEquals("0", response.headers().get(HttpHeaderNames.CONTENT_LENGTH));
// Keep-alive is on by default in HTTP/1.1, so the connection should be still alive.
assertTrue(embedder.isOpen());
@ -229,8 +228,8 @@ public class HttpObjectAggregatorTest {
// Write first request with Expect: 100-continue
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "http://localhost");
HttpHeaders.set100ContinueExpected(message);
HttpHeaders.setContentLength(message, 16);
HttpHeaderUtil.set100ContinueExpected(message, true);
HttpHeaderUtil.setContentLength(message, 16);
HttpContent chunk1 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("some", CharsetUtil.US_ASCII)));
HttpContent chunk2 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII)));
@ -242,7 +241,7 @@ public class HttpObjectAggregatorTest {
// The agregator should respond with '413 Request Entity Too Large.'
FullHttpResponse response = embedder.readOutbound();
assertEquals(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE, response.status());
assertEquals("0", response.headers().get(Names.CONTENT_LENGTH));
assertEquals("0", response.headers().get(HttpHeaderNames.CONTENT_LENGTH));
// An ill-behaving client could continue to send data without a respect, and such data should be discarded.
assertFalse(embedder.writeInbound(chunk1));
@ -262,9 +261,9 @@ public class HttpObjectAggregatorTest {
assertEquals(
chunk2.content().readableBytes() + chunk3.content().readableBytes(),
HttpHeaders.getContentLength(fullMsg));
HttpHeaderUtil.getContentLength(fullMsg));
assertEquals(HttpHeaders.getContentLength(fullMsg), fullMsg.content().readableBytes());
assertEquals(HttpHeaderUtil.getContentLength(fullMsg), fullMsg.content().readableBytes());
fullMsg.release();
assertFalse(embedder.finish());
@ -276,7 +275,7 @@ public class HttpObjectAggregatorTest {
assertFalse(embedder.writeInbound(message));
HttpResponse response = embedder.readOutbound();
assertEquals(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE, response.status());
assertEquals("0", response.headers().get(Names.CONTENT_LENGTH));
assertEquals("0", response.headers().get(HttpHeaderNames.CONTENT_LENGTH));
if (serverShouldCloseConnection(message)) {
assertFalse(embedder.isOpen());
@ -289,10 +288,10 @@ public class HttpObjectAggregatorTest {
private static boolean serverShouldCloseConnection(HttpRequest message) {
// The connection should only be kept open if Expect: 100-continue is set,
// or if keep-alive is on.
if (HttpHeaders.is100ContinueExpected(message)) {
if (HttpHeaderUtil.is100ContinueExpected(message)) {
return false;
}
if (HttpHeaders.isKeepAlive(message)) {
if (HttpHeaderUtil.isKeepAlive(message)) {
return false;
}
return true;
@ -345,8 +344,8 @@ public class HttpObjectAggregatorTest {
EmbeddedChannel embedder = new EmbeddedChannel(aggr);
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "http://localhost");
HttpHeaders.setHeader(message, "X-Test", true);
HttpHeaders.setHeader(message, "Transfer-Encoding", "Chunked");
message.headers().set("X-Test", true);
message.headers().set("Transfer-Encoding", "Chunked");
HttpContent chunk1 = new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII));
HttpContent chunk2 = new DefaultHttpContent(Unpooled.copiedBuffer("test2", CharsetUtil.US_ASCII));
HttpContent chunk3 = LastHttpContent.EMPTY_LAST_CONTENT;
@ -361,7 +360,7 @@ public class HttpObjectAggregatorTest {
assertNotNull(aggratedMessage);
assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(),
HttpHeaders.getContentLength(aggratedMessage));
HttpHeaderUtil.getContentLength(aggratedMessage));
assertEquals(aggratedMessage.headers().get("X-Test"), Boolean.TRUE.toString());
checkContentBuffer(aggratedMessage);
assertNull(embedder.readInbound());

View File

@ -17,7 +17,6 @@ package io.netty.handler.codec.http;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.util.CharsetUtil;
import org.junit.Test;
@ -184,7 +183,7 @@ public class HttpResponseDecoderTest {
HttpResponse res = ch.readInbound();
assertThat(res.protocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
assertThat(res.status(), is(HttpResponseStatus.OK));
assertThat(res.headers().get(Names.TRANSFER_ENCODING), is("chunked"));
assertThat(res.headers().get(HttpHeaderNames.TRANSFER_ENCODING), is("chunked"));
assertThat(ch.readInbound(), is(nullValue()));
// Close the connection without sending anything.
@ -205,7 +204,7 @@ public class HttpResponseDecoderTest {
HttpResponse res = ch.readInbound();
assertThat(res.protocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
assertThat(res.status(), is(HttpResponseStatus.OK));
assertThat(res.headers().get(Names.TRANSFER_ENCODING), is("chunked"));
assertThat(res.headers().get(HttpHeaderNames.TRANSFER_ENCODING), is("chunked"));
// Read the partial content.
HttpContent content = ch.readInbound();

View File

@ -36,13 +36,13 @@ public class HttpResponseEncoderTest {
public void testLargeFileRegionChunked() throws Exception {
EmbeddedChannel channel = new EmbeddedChannel(new HttpResponseEncoder());
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.headers().set(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
response.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
assertTrue(channel.writeOutbound(response));
ByteBuf buffer = channel.readOutbound();
assertEquals("HTTP/1.1 200 OK\r\n" + HttpHeaders.Names.TRANSFER_ENCODING + ": " +
HttpHeaders.Values.CHUNKED + "\r\n\r\n", buffer.toString(CharsetUtil.US_ASCII));
assertEquals("HTTP/1.1 200 OK\r\n" + HttpHeaderNames.TRANSFER_ENCODING + ": " +
HttpHeaderValues.CHUNKED + "\r\n\r\n", buffer.toString(CharsetUtil.US_ASCII));
buffer.release();
assertTrue(channel.writeOutbound(FILE_REGION));
buffer = channel.readOutbound();

View File

@ -21,7 +21,6 @@ import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.CharsetUtil;
import org.junit.Test;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
@ -92,7 +91,7 @@ public class HttpServerCodecTest {
// Ensure the aggregator generates a full request.
FullHttpRequest req = ch.readInbound();
assertThat(req.headers().get(CONTENT_LENGTH), is("1"));
assertThat(req.headers().get(HttpHeaderNames.CONTENT_LENGTH), is("1"));
assertThat(req.content().readableBytes(), is(1));
assertThat(req.content().readByte(), is((byte) 42));
req.release();
@ -103,13 +102,13 @@ public class HttpServerCodecTest {
// Send the actual response.
FullHttpResponse res = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CREATED);
res.content().writeBytes("OK".getBytes(CharsetUtil.UTF_8));
res.headers().set(CONTENT_LENGTH, 2);
res.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, 2);
ch.writeOutbound(res);
// Ensure the encoder handles the response after handling 100 Continue.
ByteBuf encodedRes = ch.readOutbound();
assertThat(encodedRes.toString(CharsetUtil.UTF_8), is("HTTP/1.1 201 Created\r\n" +
CONTENT_LENGTH + ": 2\r\n\r\nOK"));
assertThat(encodedRes.toString(CharsetUtil.UTF_8),
is("HTTP/1.1 201 Created\r\n" + HttpHeaderNames.CONTENT_LENGTH + ": 2\r\n\r\nOK"));
encodedRes.release();
ch.finish();

View File

@ -15,8 +15,8 @@
*/
package io.netty.handler.codec.http.cors;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpMethod;
import org.junit.Test;
@ -108,8 +108,8 @@ public class CorsConfigTest {
@Test
public void defaultPreflightResponseHeaders() {
final CorsConfig cors = withAnyOrigin().build();
assertThat(cors.preflightResponseHeaders().get(Names.DATE), is(notNullValue()));
assertThat(cors.preflightResponseHeaders().get(Names.CONTENT_LENGTH), is("0"));
assertThat(cors.preflightResponseHeaders().get(HttpHeaderNames.DATE), is(notNullValue()));
assertThat(cors.preflightResponseHeaders().get(HttpHeaderNames.CONTENT_LENGTH), is("0"));
}
@Test

View File

@ -28,10 +28,9 @@ import org.junit.Test;
import java.util.Arrays;
import java.util.concurrent.Callable;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpHeaderNames.*;
import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN;
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;

View File

@ -24,7 +24,8 @@ import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.DefaultHttpContent;
import io.netty.handler.codec.http.DefaultHttpRequest;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.LastHttpContent;
@ -62,8 +63,8 @@ public class HttpPostRequestDecoderTest {
"http://localhost");
req.setDecoderResult(DecoderResult.SUCCESS);
req.headers().add(HttpHeaders.Names.CONTENT_TYPE, contentTypeValue);
req.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
req.headers().add(HttpHeaderNames.CONTENT_TYPE, contentTypeValue);
req.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
// Force to use memory-based data.
final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
@ -106,8 +107,8 @@ public class HttpPostRequestDecoderTest {
"http://localhost");
req.setDecoderResult(DecoderResult.SUCCESS);
req.headers().add(HttpHeaders.Names.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
req.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
req.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
// Force to use memory-based data.
final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
@ -150,8 +151,8 @@ public class HttpPostRequestDecoderTest {
final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
"http://localhost");
req.setDecoderResult(DecoderResult.SUCCESS);
req.headers().add(HttpHeaders.Names.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
req.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
req.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
final String body =
"--" + boundary + "\r\n" +
"Content-Disposition: form-data; name=\"file" + i + "\"\r\n" +
@ -185,8 +186,8 @@ public class HttpPostRequestDecoderTest {
"http://localhost");
req.setDecoderResult(DecoderResult.SUCCESS);
req.headers().add(HttpHeaders.Names.CONTENT_TYPE, "multipart/form-data; boundary=\"" + boundary + '"');
req.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=\"" + boundary + '"');
req.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
// Force to use memory-based data.
final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
@ -218,10 +219,10 @@ public class HttpPostRequestDecoderTest {
DefaultHttpRequest aRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1,
HttpMethod.POST,
"http://localhost");
aRequest.headers().set(HttpHeaders.Names.CONTENT_TYPE,
aRequest.headers().set(HttpHeaderNames.CONTENT_TYPE,
"multipart/form-data; boundary=" + boundary);
aRequest.headers().set(HttpHeaders.Names.TRANSFER_ENCODING,
HttpHeaders.Values.CHUNKED);
aRequest.headers().set(HttpHeaderNames.TRANSFER_ENCODING,
HttpHeaderValues.CHUNKED);
HttpPostRequestDecoder aDecoder = new HttpPostRequestDecoder(aMemFactory, aRequest);

View File

@ -18,18 +18,17 @@ package io.netty.handler.codec.http.multipart;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder.EncoderMode;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.StringUtil;
import org.junit.Test;
import java.io.File;
import java.util.List;
import static io.netty.handler.codec.http.HttpHeaderNames.*;
import static org.junit.Assert.*;
/** {@link HttpPostRequestEncoder} test case. */

View File

@ -17,13 +17,13 @@ package io.netty.handler.codec.http.websocketx;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpVersion;
import static io.netty.handler.codec.http.HttpHeaders.Values.*;
import static io.netty.handler.codec.http.HttpVersion.*;
public class WebSocketRequestBuilder {
@ -48,33 +48,57 @@ public class WebSocketRequestBuilder {
return this;
}
public WebSocketRequestBuilder uri(String uri) {
this.uri = uri;
public WebSocketRequestBuilder uri(CharSequence uri) {
if (uri == null) {
this.uri = null;
} else {
this.uri = uri.toString();
}
return this;
}
public WebSocketRequestBuilder host(String host) {
this.host = host;
public WebSocketRequestBuilder host(CharSequence host) {
if (host == null) {
this.host = null;
} else {
this.host = host.toString();
}
return this;
}
public WebSocketRequestBuilder upgrade(String upgrade) {
this.upgrade = upgrade;
public WebSocketRequestBuilder upgrade(CharSequence upgrade) {
if (upgrade == null) {
this.upgrade = null;
} else {
this.upgrade = upgrade.toString();
}
return this;
}
public WebSocketRequestBuilder connection(String connection) {
this.connection = connection;
public WebSocketRequestBuilder connection(CharSequence connection) {
if (connection == null) {
this.connection = null;
} else {
this.connection = connection.toString();
}
return this;
}
public WebSocketRequestBuilder key(String key) {
this.key = key;
public WebSocketRequestBuilder key(CharSequence key) {
if (key == null) {
this.key = null;
} else {
this.key = key.toString();
}
return this;
}
public WebSocketRequestBuilder origin(String origin) {
this.origin = origin;
public WebSocketRequestBuilder origin(CharSequence origin) {
if (origin == null) {
this.origin = null;
} else {
this.origin = origin.toString();
}
return this;
}
@ -102,22 +126,22 @@ public class WebSocketRequestBuilder {
HttpHeaders headers = req.headers();
if (host != null) {
headers.set(Names.HOST, host);
headers.set(HttpHeaderNames.HOST, host);
}
if (upgrade != null) {
headers.set(Names.UPGRADE, upgrade);
headers.set(HttpHeaderNames.UPGRADE, upgrade);
}
if (connection != null) {
headers.set(Names.CONNECTION, connection);
headers.set(HttpHeaderNames.CONNECTION, connection);
}
if (key != null) {
headers.set(Names.SEC_WEBSOCKET_KEY, key);
headers.set(HttpHeaderNames.SEC_WEBSOCKET_KEY, key);
}
if (origin != null) {
headers.set(Names.SEC_WEBSOCKET_ORIGIN, origin);
headers.set(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, origin);
}
if (version != null) {
headers.set(Names.SEC_WEBSOCKET_VERSION, version.toHttpHeaderValue());
headers.set(HttpHeaderNames.SEC_WEBSOCKET_VERSION, version.toHttpHeaderValue());
}
return req;
}
@ -127,7 +151,7 @@ public class WebSocketRequestBuilder {
.method(HttpMethod.GET)
.uri("/test")
.host("server.example.com")
.upgrade(WEBSOCKET.toLowerCase().toString())
.upgrade(HttpHeaderValues.WEBSOCKET)
.key("dGhlIHNhbXBsZSBub25jZQ==")
.origin("http://example.com")
.version13()

View File

@ -19,7 +19,8 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
@ -32,7 +33,6 @@ import io.netty.util.ReferenceCountUtil;
import org.junit.Assert;
import org.junit.Test;
import static io.netty.handler.codec.http.HttpHeaders.Values.*;
import static io.netty.handler.codec.http.HttpVersion.*;
public class WebSocketServerHandshaker00Test {
@ -54,13 +54,13 @@ public class WebSocketServerHandshaker00Test {
FullHttpRequest req = ReferenceCountUtil.releaseLater(new DefaultFullHttpRequest(
HTTP_1_1, HttpMethod.GET, "/chat", Unpooled.copiedBuffer("^n:ds[4U", CharsetUtil.US_ASCII)));
req.headers().set(Names.HOST, "server.example.com");
req.headers().set(Names.UPGRADE, WEBSOCKET.toLowerCase());
req.headers().set(Names.CONNECTION, "Upgrade");
req.headers().set(Names.ORIGIN, "http://example.com");
req.headers().set(Names.SEC_WEBSOCKET_KEY1, "4 @1 46546xW%0l 1 5");
req.headers().set(Names.SEC_WEBSOCKET_KEY2, "12998 5 Y3 1 .P00");
req.headers().set(Names.SEC_WEBSOCKET_PROTOCOL, "chat, superchat");
req.headers().set(HttpHeaderNames.HOST, "server.example.com");
req.headers().set(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
req.headers().set(HttpHeaderNames.CONNECTION, "Upgrade");
req.headers().set(HttpHeaderNames.ORIGIN, "http://example.com");
req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_KEY1, "4 @1 46546xW%0l 1 5");
req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_KEY2, "12998 5 Y3 1 .P00");
req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, "chat, superchat");
if (subProtocol) {
new WebSocketServerHandshaker00(
@ -74,12 +74,12 @@ public class WebSocketServerHandshaker00Test {
ch2.writeInbound(ch.readOutbound());
HttpResponse res = ch2.readInbound();
Assert.assertEquals("ws://example.com/chat", res.headers().get(Names.SEC_WEBSOCKET_LOCATION));
Assert.assertEquals("ws://example.com/chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_LOCATION));
if (subProtocol) {
Assert.assertEquals("chat", res.headers().get(Names.SEC_WEBSOCKET_PROTOCOL));
Assert.assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
} else {
Assert.assertNull(res.headers().get(Names.SEC_WEBSOCKET_PROTOCOL));
Assert.assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
}
LastHttpContent content = ch2.readInbound();

View File

@ -19,7 +19,8 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
@ -30,7 +31,6 @@ import io.netty.util.ReferenceCountUtil;
import org.junit.Assert;
import org.junit.Test;
import static io.netty.handler.codec.http.HttpHeaders.Values.*;
import static io.netty.handler.codec.http.HttpVersion.*;
public class WebSocketServerHandshaker08Test {
@ -51,13 +51,13 @@ public class WebSocketServerHandshaker08Test {
FullHttpRequest req = ReferenceCountUtil.releaseLater(
new DefaultFullHttpRequest(HTTP_1_1, HttpMethod.GET, "/chat"));
req.headers().set(Names.HOST, "server.example.com");
req.headers().set(Names.UPGRADE, WEBSOCKET.toLowerCase());
req.headers().set(Names.CONNECTION, "Upgrade");
req.headers().set(Names.SEC_WEBSOCKET_KEY, "dGhlIHNhbXBsZSBub25jZQ==");
req.headers().set(Names.SEC_WEBSOCKET_ORIGIN, "http://example.com");
req.headers().set(Names.SEC_WEBSOCKET_PROTOCOL, "chat, superchat");
req.headers().set(Names.SEC_WEBSOCKET_VERSION, "8");
req.headers().set(HttpHeaderNames.HOST, "server.example.com");
req.headers().set(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
req.headers().set(HttpHeaderNames.CONNECTION, "Upgrade");
req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_KEY, "dGhlIHNhbXBsZSBub25jZQ==");
req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, "http://example.com");
req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, "chat, superchat");
req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_VERSION, "8");
if (subProtocol) {
new WebSocketServerHandshaker08(
@ -74,11 +74,11 @@ public class WebSocketServerHandshaker08Test {
HttpResponse res = ch2.readInbound();
Assert.assertEquals(
"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", res.headers().get(Names.SEC_WEBSOCKET_ACCEPT));
"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT));
if (subProtocol) {
Assert.assertEquals("chat", res.headers().get(Names.SEC_WEBSOCKET_PROTOCOL));
Assert.assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
} else {
Assert.assertNull(res.headers().get(Names.SEC_WEBSOCKET_PROTOCOL));
Assert.assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
}
ReferenceCountUtil.release(res);
}

View File

@ -19,7 +19,8 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
@ -30,7 +31,6 @@ import io.netty.util.ReferenceCountUtil;
import org.junit.Assert;
import org.junit.Test;
import static io.netty.handler.codec.http.HttpHeaders.Values.*;
import static io.netty.handler.codec.http.HttpVersion.*;
public class WebSocketServerHandshaker13Test {
@ -51,13 +51,13 @@ public class WebSocketServerHandshaker13Test {
FullHttpRequest req = ReferenceCountUtil.releaseLater(
new DefaultFullHttpRequest(HTTP_1_1, HttpMethod.GET, "/chat"));
req.headers().set(Names.HOST, "server.example.com");
req.headers().set(Names.UPGRADE, WEBSOCKET.toLowerCase());
req.headers().set(Names.CONNECTION, "Upgrade");
req.headers().set(Names.SEC_WEBSOCKET_KEY, "dGhlIHNhbXBsZSBub25jZQ==");
req.headers().set(Names.SEC_WEBSOCKET_ORIGIN, "http://example.com");
req.headers().set(Names.SEC_WEBSOCKET_PROTOCOL, "chat, superchat");
req.headers().set(Names.SEC_WEBSOCKET_VERSION, "13");
req.headers().set(HttpHeaderNames.HOST, "server.example.com");
req.headers().set(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
req.headers().set(HttpHeaderNames.CONNECTION, "Upgrade");
req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_KEY, "dGhlIHNhbXBsZSBub25jZQ==");
req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, "http://example.com");
req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, "chat, superchat");
req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_VERSION, "13");
if (subProtocol) {
new WebSocketServerHandshaker13(
@ -74,11 +74,11 @@ public class WebSocketServerHandshaker13Test {
HttpResponse res = ch2.readInbound();
Assert.assertEquals(
"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", res.headers().get(Names.SEC_WEBSOCKET_ACCEPT));
"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT));
if (subProtocol) {
Assert.assertEquals("chat", res.headers().get(Names.SEC_WEBSOCKET_PROTOCOL));
Assert.assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
} else {
Assert.assertNull(res.headers().get(Names.SEC_WEBSOCKET_PROTOCOL));
Assert.assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
}
ReferenceCountUtil.release(res);
}

View File

@ -24,6 +24,7 @@ import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpRequestDecoder;
@ -35,7 +36,6 @@ import org.junit.Test;
import java.util.ArrayDeque;
import java.util.Queue;
import static io.netty.handler.codec.http.HttpHeaders.Values.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
import static org.junit.Assert.*;
@ -95,7 +95,7 @@ public class WebSocketServerProtocolHandlerTest {
.uri("/test")
.key(null)
.connection("Upgrade")
.upgrade(WEBSOCKET.toLowerCase().toString())
.upgrade(HttpHeaderValues.WEBSOCKET)
.version13()
.build();

View File

@ -29,7 +29,9 @@ import io.netty.handler.codec.http.DefaultHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpChunkedInput;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderUtil;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.LastHttpContent;
@ -52,7 +54,6 @@ import java.util.Locale;
import java.util.TimeZone;
import java.util.regex.Pattern;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
@ -149,7 +150,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
}
// Cache Validation
String ifModifiedSince = request.headers().getAndConvert(IF_MODIFIED_SINCE);
String ifModifiedSince = request.headers().get(HttpHeaderNames.IF_MODIFIED_SINCE);
if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) {
SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
Date ifModifiedSinceDate = dateFormatter.parse(ifModifiedSince);
@ -174,11 +175,11 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
long fileLength = raf.length();
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
HttpHeaders.setContentLength(response, fileLength);
HttpHeaderUtil.setContentLength(response, fileLength);
setContentTypeHeader(response, file);
setDateAndCacheHeaders(response, file);
if (HttpHeaders.isKeepAlive(request)) {
response.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
if (HttpHeaderUtil.isKeepAlive(request)) {
response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
}
// Write the initial line and the header.
@ -215,7 +216,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
ChannelFuture lastContentFuture = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
// Decide whether to close the connection or not.
if (!HttpHeaders.isKeepAlive(request)) {
if (!HttpHeaderUtil.isKeepAlive(request)) {
// Close the connection when the whole content is written out.
lastContentFuture.addListener(ChannelFutureListener.CLOSE);
}
@ -263,7 +264,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
private static void sendListing(ChannelHandlerContext ctx, File dir) {
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK);
response.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8");
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=UTF-8");
StringBuilder buf = new StringBuilder();
String dirPath = dir.getPath();
@ -309,7 +310,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
private static void sendRedirect(ChannelHandlerContext ctx, String newUri) {
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, FOUND);
response.headers().set(LOCATION, newUri);
response.headers().set(HttpHeaderNames.LOCATION, newUri);
// Close the connection as soon as the error message is sent.
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
@ -318,7 +319,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
private static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
FullHttpResponse response = new DefaultFullHttpResponse(
HTTP_1_1, status, Unpooled.copiedBuffer("Failure: " + status + "\r\n", CharsetUtil.UTF_8));
response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8");
// Close the connection as soon as the error message is sent.
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
@ -349,7 +350,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE));
Calendar time = new GregorianCalendar();
response.headers().set(DATE, dateFormatter.format(time.getTime()));
response.headers().set(HttpHeaderNames.DATE, dateFormatter.format(time.getTime()));
}
/**
@ -366,14 +367,14 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
// Date header
Calendar time = new GregorianCalendar();
response.headers().set(DATE, dateFormatter.format(time.getTime()));
response.headers().set(HttpHeaderNames.DATE, dateFormatter.format(time.getTime()));
// Add cache headers
time.add(Calendar.SECOND, HTTP_CACHE_SECONDS);
response.headers().set(EXPIRES, dateFormatter.format(time.getTime()));
response.headers().set(CACHE_CONTROL, "private, max-age=" + HTTP_CACHE_SECONDS);
response.headers().set(HttpHeaderNames.EXPIRES, dateFormatter.format(time.getTime()));
response.headers().set(HttpHeaderNames.CACHE_CONTROL, "private, max-age=" + HTTP_CACHE_SECONDS);
response.headers().set(
LAST_MODIFIED, dateFormatter.format(new Date(fileToCache.lastModified())));
HttpHeaderNames.LAST_MODIFIED, dateFormatter.format(new Date(fileToCache.lastModified())));
}
/**
@ -386,6 +387,6 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
*/
private static void setContentTypeHeader(HttpResponse response, File file) {
MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
response.headers().set(CONTENT_TYPE, mimeTypesMap.getContentType(file.getPath()));
response.headers().set(HttpHeaderNames.CONTENT_TYPE, mimeTypesMap.getContentType(file.getPath()));
}
}

View File

@ -22,7 +22,7 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaderUtil;
import io.netty.handler.codec.http.HttpRequest;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
@ -46,10 +46,10 @@ public class HttpHelloWorldServerHandler extends ChannelInboundHandlerAdapter {
if (msg instanceof HttpRequest) {
HttpRequest req = (HttpRequest) msg;
if (HttpHeaders.is100ContinueExpected(req)) {
if (HttpHeaderUtil.is100ContinueExpected(req)) {
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
}
boolean keepAlive = HttpHeaders.isKeepAlive(req);
boolean keepAlive = HttpHeaderUtil.isKeepAlive(req);
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(CONTENT));
response.headers().set(CONTENT_TYPE, "text/plain");
response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());

View File

@ -23,7 +23,8 @@ import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.http.ClientCookieEncoder;
import io.netty.handler.codec.http.DefaultCookie;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpVersion;
@ -81,13 +82,13 @@ public final class HttpSnoopClient {
// Prepare the HTTP request.
HttpRequest request = new DefaultFullHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.GET, uri.getRawPath());
request.headers().set(HttpHeaders.Names.HOST, host);
request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);
request.headers().set(HttpHeaderNames.HOST, host);
request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
request.headers().set(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.GZIP);
// Set some example cookies.
request.headers().set(
HttpHeaders.Names.COOKIE,
HttpHeaderNames.COOKIE,
ClientCookieEncoder.encode(
new DefaultCookie("my-cookie", "foo"),
new DefaultCookie("another-cookie", "bar")));

View File

@ -18,7 +18,7 @@ package io.netty.example.http.snoop;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaderUtil;
import io.netty.handler.codec.http.HttpObject;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.LastHttpContent;
@ -44,7 +44,7 @@ public class HttpSnoopClientHandler extends SimpleChannelInboundHandler<HttpObje
System.err.println();
}
if (HttpHeaders.isTransferEncodingChunked(response)) {
if (HttpHeaderUtil.isTransferEncodingChunked(response)) {
System.err.println("CHUNKED CONTENT {");
} else {
System.err.println("CONTENT {");

View File

@ -26,6 +26,9 @@ import io.netty.handler.codec.http.CookieDecoder;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderUtil;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpObject;
import io.netty.handler.codec.http.HttpRequest;
@ -39,7 +42,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
@ -59,7 +61,7 @@ public class HttpSnoopServerHandler extends SimpleChannelInboundHandler<Object>
if (msg instanceof HttpRequest) {
HttpRequest request = this.request = (HttpRequest) msg;
if (HttpHeaders.is100ContinueExpected(request)) {
if (HttpHeaderUtil.is100ContinueExpected(request)) {
send100Continue(ctx);
}
@ -68,12 +70,12 @@ public class HttpSnoopServerHandler extends SimpleChannelInboundHandler<Object>
buf.append("===================================\r\n");
buf.append("VERSION: ").append(request.protocolVersion()).append("\r\n");
buf.append("HOSTNAME: ").append(HttpHeaders.getHost(request, "unknown")).append("\r\n");
buf.append("HOSTNAME: ").append(request.headers().get(HttpHeaderNames.HOST, "unknown")).append("\r\n");
buf.append("REQUEST_URI: ").append(request.uri()).append("\r\n\r\n");
HttpHeaders headers = request.headers();
if (!headers.isEmpty()) {
for (Map.Entry<CharSequence, CharSequence> h: headers) {
for (Map.Entry<String, String> h: headers) {
CharSequence key = h.getKey();
CharSequence value = h.getValue();
buf.append("HEADER: ").append(key).append(" = ").append(value).append("\r\n");
@ -144,36 +146,36 @@ public class HttpSnoopServerHandler extends SimpleChannelInboundHandler<Object>
private boolean writeResponse(HttpObject currentObj, ChannelHandlerContext ctx) {
// Decide whether to close the connection or not.
boolean keepAlive = HttpHeaders.isKeepAlive(request);
boolean keepAlive = HttpHeaderUtil.isKeepAlive(request);
// Build the response object.
FullHttpResponse response = new DefaultFullHttpResponse(
HTTP_1_1, currentObj.decoderResult().isSuccess()? OK : BAD_REQUEST,
Unpooled.copiedBuffer(buf.toString(), CharsetUtil.UTF_8));
response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8");
if (keepAlive) {
// Add 'Content-Length' header only for a keep-alive connection.
response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());
response.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
// Add keep alive header as per:
// - http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
response.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
}
// Encode the cookie.
String cookieString = request.headers().getAndConvert(COOKIE);
String cookieString = request.headers().get(HttpHeaderNames.COOKIE);
if (cookieString != null) {
Set<Cookie> cookies = CookieDecoder.decode(cookieString);
if (!cookies.isEmpty()) {
// Reset the cookies if necessary.
for (Cookie cookie: cookies) {
response.headers().add(SET_COOKIE, ServerCookieEncoder.encode(cookie));
response.headers().add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.encode(cookie));
}
}
} else {
// Browser sent no cookie. Add some.
response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("key1", "value1"));
response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("key2", "value2"));
response.headers().add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.encode("key1", "value1"));
response.headers().add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.encode("key2", "value2"));
}
// Write the response.

View File

@ -24,6 +24,8 @@ import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.http.ClientCookieEncoder;
import io.netty.handler.codec.http.DefaultCookie;
import io.netty.handler.codec.http.DefaultHttpRequest;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpRequest;
@ -162,28 +164,28 @@ public final class HttpUploadClient {
URI uriGet = new URI(encoder.toString());
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uriGet.toASCIIString());
HttpHeaders headers = request.headers();
headers.set(HttpHeaders.Names.HOST, host);
headers.set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
headers.set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP + ',' + HttpHeaders.Values.DEFLATE);
headers.set(HttpHeaderNames.HOST, host);
headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
headers.set(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.GZIP + "," + HttpHeaderValues.DEFLATE);
headers.set(HttpHeaders.Names.ACCEPT_CHARSET, "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
headers.set(HttpHeaders.Names.ACCEPT_LANGUAGE, "fr");
headers.set(HttpHeaders.Names.REFERER, uriSimple.toString());
headers.set(HttpHeaders.Names.USER_AGENT, "Netty Simple Http Client side");
headers.set(HttpHeaders.Names.ACCEPT, "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
headers.set(HttpHeaderNames.ACCEPT_CHARSET, "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
headers.set(HttpHeaderNames.ACCEPT_LANGUAGE, "fr");
headers.set(HttpHeaderNames.REFERER, uriSimple.toString());
headers.set(HttpHeaderNames.USER_AGENT, "Netty Simple Http Client side");
headers.set(HttpHeaderNames.ACCEPT, "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
//connection will not close but needed
// headers.set("Connection","keep-alive");
// headers.set("Keep-Alive","300");
headers.set(
HttpHeaders.Names.COOKIE, ClientCookieEncoder.encode(
HttpHeaderNames.COOKIE, ClientCookieEncoder.encode(
new DefaultCookie("my-cookie", "foo"),
new DefaultCookie("another-cookie", "bar"))
);
// send request
List<Entry<String, String>> entries = headers.entriesConverted();
List<Entry<String, String>> entries = headers.entries();
channel.writeAndFlush(request);
// Wait for the server to close the connection.

View File

@ -18,7 +18,7 @@ package io.netty.example.http.upload;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaderUtil;
import io.netty.handler.codec.http.HttpObject;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.LastHttpContent;
@ -47,7 +47,7 @@ public class HttpUploadClientHandler extends SimpleChannelInboundHandler<HttpObj
}
}
if (response.status().code() == 200 && HttpHeaders.isTransferEncodingChunked(response)) {
if (response.status().code() == 200 && HttpHeaderUtil.isTransferEncodingChunked(response)) {
readingChunks = true;
System.err.println("CHUNKED CONTENT {");
} else {

View File

@ -26,7 +26,9 @@ import io.netty.handler.codec.http.CookieDecoder;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderUtil;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpObject;
import io.netty.handler.codec.http.HttpRequest;
@ -59,7 +61,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import static io.netty.buffer.Unpooled.*;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObject> {
@ -113,14 +114,14 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
responseContent.append("\r\n\r\n");
// new getMethod
for (Entry<CharSequence, CharSequence> entry : request.headers()) {
for (Entry<String, String> entry : request.headers()) {
responseContent.append("HEADER: " + entry.getKey() + '=' + entry.getValue() + "\r\n");
}
responseContent.append("\r\n\r\n");
// new getMethod
Set<Cookie> cookies;
String value = request.headers().getAndConvert(COOKIE);
String value = request.headers().get(HttpHeaderNames.COOKIE);
if (value == null) {
cookies = Collections.emptySet();
} else {
@ -158,7 +159,7 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
return;
}
readingChunks = HttpHeaders.isTransferEncodingChunked(request);
readingChunks = HttpHeaderUtil.isTransferEncodingChunked(request);
responseContent.append("Is Chunked: " + readingChunks + "\r\n");
responseContent.append("IsMultipart: " + decoder.isMultipart() + "\r\n");
if (readingChunks) {
@ -287,23 +288,23 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
responseContent.setLength(0);
// Decide whether to close the connection or not.
boolean close = request.headers().contains(CONNECTION, HttpHeaders.Values.CLOSE, true)
boolean close = request.headers().contains(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE, true)
|| request.protocolVersion().equals(HttpVersion.HTTP_1_0)
&& !request.headers().contains(CONNECTION, HttpHeaders.Values.KEEP_ALIVE, true);
&& !request.headers().contains(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE, true);
// Build the response object.
FullHttpResponse response = new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buf);
response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8");
if (!close) {
// There's no need to add 'Content-Length' header
// if this is the last response.
response.headers().setInt(CONTENT_LENGTH, buf.readableBytes());
response.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, buf.readableBytes());
}
Set<Cookie> cookies;
String value = request.headers().getAndConvert(COOKIE);
String value = request.headers().get(HttpHeaderNames.COOKIE);
if (value == null) {
cookies = Collections.emptySet();
} else {
@ -312,7 +313,7 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
if (!cookies.isEmpty()) {
// Reset the cookies if necessary.
for (Cookie cookie : cookies) {
response.headers().add(SET_COOKIE, ServerCookieEncoder.encode(cookie));
response.headers().add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.encode(cookie));
}
}
// Write the response.
@ -400,8 +401,8 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
FullHttpResponse response = new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buf);
response.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8");
response.headers().setInt(CONTENT_LENGTH, buf.readableBytes());
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=UTF-8");
response.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, buf.readableBytes());
// Write the response.
ctx.channel().writeAndFlush(response);

View File

@ -24,7 +24,8 @@ import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderUtil;
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
import io.netty.handler.codec.http.websocketx.PingWebSocketFrame;
@ -35,7 +36,6 @@ import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
import io.netty.util.CharsetUtil;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
@ -81,8 +81,8 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
ByteBuf content = WebSocketServerBenchmarkPage.getContent(getWebSocketLocation(req));
FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
res.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8");
HttpHeaders.setContentLength(res, content.readableBytes());
res.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=UTF-8");
HttpHeaderUtil.setContentLength(res, content.readableBytes());
sendHttpResponse(ctx, req, res);
return;
@ -134,12 +134,12 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
ByteBuf buf = Unpooled.copiedBuffer(res.status().toString(), CharsetUtil.UTF_8);
res.content().writeBytes(buf);
buf.release();
HttpHeaders.setContentLength(res, res.content().readableBytes());
HttpHeaderUtil.setContentLength(res, res.content().readableBytes());
}
// Send the response and close the connection if necessary.
ChannelFuture f = ctx.channel().writeAndFlush(res);
if (!HttpHeaders.isKeepAlive(req) || res.status().code() != 200) {
if (!HttpHeaderUtil.isKeepAlive(req) || res.status().code() != 200) {
f.addListener(ChannelFutureListener.CLOSE);
}
}
@ -151,7 +151,7 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
}
private static String getWebSocketLocation(FullHttpRequest req) {
String location = req.headers().get(HOST) + WEBSOCKET_PATH;
String location = req.headers().get(HttpHeaderNames.HOST) + WEBSOCKET_PATH;
if (WebSocketServer.SSL) {
return "wss://" + location;
} else {

View File

@ -24,7 +24,8 @@ import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderUtil;
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
import io.netty.handler.codec.http.websocketx.PingWebSocketFrame;
import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
@ -34,7 +35,6 @@ import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
import io.netty.util.CharsetUtil;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
@ -80,8 +80,8 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
ByteBuf content = WebSocketServerIndexPage.getContent(getWebSocketLocation(req));
FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
res.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8");
HttpHeaders.setContentLength(res, content.readableBytes());
res.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=UTF-8");
HttpHeaderUtil.setContentLength(res, content.readableBytes());
sendHttpResponse(ctx, req, res);
return;
@ -132,12 +132,12 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
ByteBuf buf = Unpooled.copiedBuffer(res.status().toString(), CharsetUtil.UTF_8);
res.content().writeBytes(buf);
buf.release();
HttpHeaders.setContentLength(res, res.content().readableBytes());
HttpHeaderUtil.setContentLength(res, res.content().readableBytes());
}
// Send the response and close the connection if necessary.
ChannelFuture f = ctx.channel().writeAndFlush(res);
if (!HttpHeaders.isKeepAlive(req) || res.status().code() != 200) {
if (!HttpHeaderUtil.isKeepAlive(req) || res.status().code() != 200) {
f.addListener(ChannelFutureListener.CLOSE);
}
}
@ -149,7 +149,7 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
}
private static String getWebSocketLocation(FullHttpRequest req) {
String location = req.headers().get(HOST) + WEBSOCKET_PATH;
String location = req.headers().get(HttpHeaderNames.HOST) + WEBSOCKET_PATH;
if (WebSocketServer.SSL) {
return "wss://" + location;
} else {

View File

@ -20,7 +20,7 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.example.http.snoop.HttpSnoopClientHandler;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaderUtil;
import io.netty.handler.codec.http.HttpObject;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.LastHttpContent;
@ -55,7 +55,7 @@ public class HttpResponseClientHandler extends SimpleChannelInboundHandler<HttpO
System.out.println();
}
if (HttpHeaders.isTransferEncodingChunked(response)) {
if (HttpHeaderUtil.isTransferEncodingChunked(response)) {
System.out.println("CHUNKED CONTENT {");
} else {
System.out.println("CONTENT {");

View File

@ -22,7 +22,8 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpVersion;
@ -83,8 +84,8 @@ public final class SpdyClient {
// Create a GET request.
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "");
request.headers().set(HttpHeaders.Names.HOST, HOST);
request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);
request.headers().set(HttpHeaderNames.HOST, HOST);
request.headers().set(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.GZIP);
// Send the GET request.
channel.writeAndFlush(request).sync();

View File

@ -18,7 +18,6 @@ package io.netty.example.spdy.client;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMessage;
import io.netty.handler.codec.spdy.SpdyHttpHeaders;
import io.netty.handler.codec.spdy.SpdyHttpHeaders.Names;
@ -39,7 +38,7 @@ public class SpdyClientStreamIdHandler extends ChannelOutboundHandlerAdapter {
if (acceptOutboundMessage(msg)) {
HttpMessage httpMsg = (HttpMessage) msg;
if (!httpMsg.headers().contains(SpdyHttpHeaders.Names.STREAM_ID)) {
HttpHeaders.setIntHeader(httpMsg, Names.STREAM_ID, currentStreamId);
httpMsg.headers().setInt(Names.STREAM_ID, currentStreamId);
// Client stream IDs are always odd
currentStreamId += 2;
}

View File

@ -22,13 +22,14 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.util.CharsetUtil;
import java.util.Date;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpHeaders.*;
import static io.netty.handler.codec.http.HttpHeaderUtil.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
@ -50,13 +51,13 @@ public class SpdyServerHandler extends SimpleChannelInboundHandler<Object> {
ByteBuf content = Unpooled.copiedBuffer("Hello World " + new Date(), CharsetUtil.UTF_8);
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");
response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8");
response.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
if (!keepAlive) {
ctx.write(response).addListener(ChannelFutureListener.CLOSE);
} else {
response.headers().set(CONNECTION, Values.KEEP_ALIVE);
response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
ctx.write(response);
}
}

View File

@ -25,7 +25,7 @@ import io.netty.handler.codec.base64.Base64;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
@ -127,11 +127,11 @@ public final class HttpProxyHandler extends ProxyHandler {
SocketAddress proxyAddress = proxyAddress();
if (proxyAddress instanceof InetSocketAddress) {
InetSocketAddress hostAddr = (InetSocketAddress) proxyAddress;
req.headers().set(Names.HOST, hostAddr.getHostString() + ':' + hostAddr.getPort());
req.headers().set(HttpHeaderNames.HOST, hostAddr.getHostString() + ':' + hostAddr.getPort());
}
if (authorization != null) {
req.headers().set(Names.AUTHORIZATION, authorization);
req.headers().set(HttpHeaderNames.AUTHORIZATION, authorization);
}
return req;

View File

@ -26,7 +26,7 @@ import io.netty.handler.codec.base64.Base64;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
@ -86,7 +86,7 @@ final class HttpProxyServer extends ProxyServer {
boolean authzSuccess = false;
if (username != null) {
CharSequence authz = req.headers().get(Names.AUTHORIZATION);
CharSequence authz = req.headers().get(HttpHeaderNames.AUTHORIZATION);
if (authz != null) {
ByteBuf authzBuf64 = Unpooled.copiedBuffer(authz, CharsetUtil.US_ASCII);
ByteBuf authzBuf = Base64.decode(authzBuf64);
@ -113,7 +113,7 @@ final class HttpProxyServer extends ProxyServer {
FullHttpResponse res;
if (!authenticate(ctx, req)) {
res = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.UNAUTHORIZED);
res.headers().set(Names.CONTENT_LENGTH, 0);
res.headers().set(HttpHeaderNames.CONTENT_LENGTH, 0);
} else {
res = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
String uri = req.uri();
@ -144,10 +144,10 @@ final class HttpProxyServer extends ProxyServer {
if (!authenticate(ctx, req)) {
res = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.UNAUTHORIZED);
res.headers().set(Names.CONTENT_LENGTH, 0);
res.headers().set(HttpHeaderNames.CONTENT_LENGTH, 0);
} else if (!req.uri().equals(destination.getHostString() + ':' + destination.getPort())) {
res = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.FORBIDDEN);
res.headers().set(Names.CONTENT_LENGTH, 0);
res.headers().set(HttpHeaderNames.CONTENT_LENGTH, 0);
} else {
res = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
sendGreeting = true;

View File

@ -24,6 +24,7 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
import io.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame;
@ -39,7 +40,7 @@ import io.netty.util.internal.StringUtil;
import java.util.logging.Level;
import java.util.logging.Logger;
import static io.netty.handler.codec.http.HttpHeaders.*;
import static io.netty.handler.codec.http.HttpHeaderUtil.*;
import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
@ -142,6 +143,6 @@ public class AutobahnServerHandler extends ChannelInboundHandlerAdapter {
}
private static String getWebSocketLocation(FullHttpRequest req) {
return "ws://" + req.headers().get(Names.HOST);
return "ws://" + req.headers().get(HttpHeaderNames.HOST);
}
}