Skip to content

Commit

Permalink
Synchronized between 4.1 and master
Browse files Browse the repository at this point in the history
Motivation:

4 and 5 were diverged long time ago and we recently reverted some of the
early commits in master.  We must make sure 4.1 and master are not very
different now.

Modification:

Fix found differences

Result:

4.1 and master got closer.
  • Loading branch information
trustin committed Apr 24, 2014
1 parent 65ee10f commit db3709e
Show file tree
Hide file tree
Showing 54 changed files with 242 additions and 186 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ Note that this is build-time requirement. JDK 5 (for 3.x) or 6 (for 4.0+) is en

## Branches to look

[The 'master' branch](https://github.com/netty/netty/tree/master) is where the development of the latest major version lives on. The development of all other major versions takes place in each branch whose name is identical to its major version number. For example, the development of 3.x and 4.x resides in [the branch '3'](https://github.com/netty/netty/tree/3) and [the branch '4'](https://github.com/netty/netty/tree/4) respectively.
[The 'master' branch](https://github.com/netty/netty/tree/master) is where the development of the latest major version lives on. The development of all other versions takes place in each branch whose name is identical to `<majorVersion>.<minorVersion>`. For example, the development of 3.9 and 4.0 resides in [the branch '3.9'](https://github.com/netty/netty/tree/3.9) and [the branch '4.0'](https://github.com/netty/netty/tree/4.0) respectively.

Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ public ByteBuf touch(Object hint) {

@Override
public boolean release() {
boolean deallocated = super.release();
boolean deallocated = super.release();
if (deallocated) {
leak.close();
} else {
Expand Down
2 changes: 1 addition & 1 deletion buffer/src/main/java/io/netty/buffer/WrappedByteBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.nio.channels.ScatteringByteChannel;
import java.nio.charset.Charset;

class WrappedByteBuf extends ByteBuf {
public class WrappedByteBuf extends ByteBuf {

protected final ByteBuf buf;

Expand Down
8 changes: 4 additions & 4 deletions buffer/src/main/java/io/netty/buffer/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@
* type.
* <pre>
* // The composite type is compatible with the component type.
* {@link ByteBuf} message = {@link Unpooled}.wrappedBuffer(header, body);
* {@link io.netty.buffer.ByteBuf} message = {@link io.netty.buffer.Unpooled}.wrappedBuffer(header, body);
*
* // Therefore, you can even create a composite by mixing a composite and an
* // ordinary buffer.
* {@link ByteBuf} messageWithFooter = {@link Unpooled}.wrappedBuffer(message, footer);
* {@link io.netty.buffer.ByteBuf} messageWithFooter = {@link io.netty.buffer.Unpooled}.wrappedBuffer(message, footer);
*
* // Because the composite is still a {@link ByteBuf}, you can access its content
* // Because the composite is still a {@link io.netty.buffer.ByteBuf}, you can access its content
* // easily, and the accessor method will behave just like it's a single buffer
* // even if the region you want to access spans over multiple components. The
* // unsigned integer being read here is located across body and footer.
Expand All @@ -100,7 +100,7 @@
* <pre>
* // A new dynamic buffer is created. Internally, the actual buffer is created
* // lazily to avoid potentially wasted memory space.
* {@link ByteBuf} b = {@link Unpooled}.buffer(4);
* {@link io.netty.buffer.ByteBuf} b = {@link io.netty.buffer.Unpooled}.buffer(4);
*
* // When the first write attempt is made, the internal buffer is created with
* // the specified initial capacity (4).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,14 @@ public Set<String> names() {
return names;
}

void encode(ByteBuf buf) {
HeaderEntry e = head.after;
while (e != head) {
e.encode(buf);
e = e.after;
}
}

private static CharSequence toCharSequence(Object value) {
if (value == null) {
return null;
Expand All @@ -400,14 +408,6 @@ private static CharSequence toCharSequence(Object value) {
return value.toString();
}

void encode(ByteBuf buf) {
HeaderEntry e = head.after;
while (e != head) {
e.encode(buf);
e = e.after;
}
}

private final class HeaderIterator implements Iterator<Map.Entry<String, String>> {

private HeaderEntry current = head;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ protected DefaultHttpMessage(final HttpVersion version) {
this(version, true);
}

protected DefaultHttpMessage(final HttpVersion version, boolean validate) {
/**
* Creates a new instance.
*/
protected DefaultHttpMessage(final HttpVersion version, boolean validateHeaders) {
if (version == null) {
throw new NullPointerException("version");
}
this.version = version;
headers = new DefaultHttpHeaders(validate);
headers = new DefaultHttpHeaders(validateHeaders);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri
* @param httpVersion the HTTP version of the request
* @param method the HTTP getMethod of the request
* @param uri the URI or path of the request
* @param validateHeaders validate the headers when adding them
* @param validateHeaders validate the header names and values when adding them to the {@link HttpHeaders}
*/
public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri, boolean validateHeaders) {
super(httpVersion, validateHeaders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status) {
*
* @param version the HTTP version of this response
* @param status the getStatus of this response
* @param validateHeaders validate the headers when adding them
* @param validateHeaders validate the header names and values when adding them to the {@link HttpHeaders}
*/
public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, boolean validateHeaders) {
super(version, validateHeaders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ private static final class TrailingHeaders extends DefaultHttpHeaders {
@Override
void validateHeaderName0(CharSequence name) {
super.validateHeaderName0(name);
if (HttpHeaders.equalsIgnoreCase(HttpHeaders.Names.CONTENT_LENGTH, name) ||
HttpHeaders.equalsIgnoreCase(HttpHeaders.Names.TRANSFER_ENCODING, name) ||
HttpHeaders.equalsIgnoreCase(HttpHeaders.Names.TRAILER, name)) {
if (equalsIgnoreCase(HttpHeaders.Names.CONTENT_LENGTH, name) ||
equalsIgnoreCase(HttpHeaders.Names.TRANSFER_ENCODING, name) ||
equalsIgnoreCase(HttpHeaders.Names.TRAILER, name)) {
throw new IllegalArgumentException(
"prohibited trailing header: " + name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ private HttpMethod(String name, boolean bytes) {
}

for (int i = 0; i < name.length(); i ++) {
if (Character.isISOControl(name.charAt(i)) ||
Character.isWhitespace(name.charAt(i))) {
char c = name.charAt(i);
if (Character.isISOControl(c) || Character.isWhitespace(c)) {
throw new IllegalArgumentException("invalid character in name");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
/**
* 417 Expectation Failed
*/
public static final HttpResponseStatus EXPECTATION_FAILED =
new HttpResponseStatus(417, "Expectation Failed", true);
public static final HttpResponseStatus EXPECTATION_FAILED = new HttpResponseStatus(417, "Expectation Failed", true);

/**
* 422 Unprocessable Entity (WebDAV, RFC4918)
Expand All @@ -225,8 +224,7 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
/**
* 423 Locked (WebDAV, RFC4918)
*/
public static final HttpResponseStatus LOCKED =
new HttpResponseStatus(423, "Locked", true);
public static final HttpResponseStatus LOCKED = new HttpResponseStatus(423, "Locked", true);

/**
* 424 Failed Dependency (WebDAV, RFC4918)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ protected void verify(FullHttpResponse response) {
HttpHeaders headers = response.headers();

String upgrade = headers.get(Names.UPGRADE);
if (!Values.WEBSOCKET.equalsIgnoreCase(upgrade)) {
if (!HttpHeaders.equalsIgnoreCase(Values.WEBSOCKET, upgrade)) {
throw new WebSocketHandshakeException("Invalid handshake response upgrade: "
+ upgrade);
}

String connection = headers.get(Names.CONNECTION);
if (!Values.UPGRADE.equalsIgnoreCase(connection)) {
if (!HttpHeaders.equalsIgnoreCase(Values.UPGRADE, connection)) {
throw new WebSocketHandshakeException("Invalid handshake response connection: "
+ connection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
public class WebSocketClientHandshaker07 extends WebSocketClientHandshaker {

private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketClientHandshaker07.class);

private static final CharSequence WEBSOCKET = HttpHeaders.newEntity(Values.WEBSOCKET.toLowerCase());
public static final String MAGIC_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";

private String expectedChallengeResponseString;
Expand Down Expand Up @@ -119,7 +119,7 @@ protected FullHttpRequest newHandshakeRequest() {
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path);
HttpHeaders headers = request.headers();

headers.add(Names.UPGRADE, Values.WEBSOCKET.toLowerCase())
headers.add(Names.UPGRADE, WEBSOCKET)
.add(Names.CONNECTION, Values.UPGRADE)
.add(Names.SEC_WEBSOCKET_KEY, key)
.add(Names.HOST, wsURL.getHost());
Expand Down Expand Up @@ -173,12 +173,12 @@ protected void verify(FullHttpResponse response) {
}

String upgrade = headers.get(Names.UPGRADE);
if (!Values.WEBSOCKET.equalsIgnoreCase(upgrade)) {
if (!HttpHeaders.equalsIgnoreCase(Values.WEBSOCKET, upgrade)) {
throw new WebSocketHandshakeException("Invalid handshake response upgrade: " + upgrade);
}

String connection = headers.get(Names.CONNECTION);
if (!Values.UPGRADE.equalsIgnoreCase(connection)) {
if (!HttpHeaders.equalsIgnoreCase(Values.UPGRADE, connection)) {
throw new WebSocketHandshakeException("Invalid handshake response connection: " + connection);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {

private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketClientHandshaker08.class);
private static final CharSequence WEBSOCKET = HttpHeaders.newEntity(Values.WEBSOCKET.toLowerCase());

public static final String MAGIC_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";

Expand Down Expand Up @@ -119,7 +120,7 @@ protected FullHttpRequest newHandshakeRequest() {
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path);
HttpHeaders headers = request.headers();

headers.add(Names.UPGRADE, Values.WEBSOCKET.toLowerCase())
headers.add(Names.UPGRADE, WEBSOCKET)
.add(Names.CONNECTION, Values.UPGRADE)
.add(Names.SEC_WEBSOCKET_KEY, key)
.add(Names.HOST, wsURL.getHost());
Expand Down Expand Up @@ -173,12 +174,12 @@ protected void verify(FullHttpResponse response) {
}

String upgrade = headers.get(Names.UPGRADE);
if (!Values.WEBSOCKET.equalsIgnoreCase(upgrade)) {
if (!HttpHeaders.equalsIgnoreCase(Values.WEBSOCKET, upgrade)) {
throw new WebSocketHandshakeException("Invalid handshake response upgrade: " + upgrade);
}

String connection = headers.get(Names.CONNECTION);
if (!Values.UPGRADE.equalsIgnoreCase(connection)) {
if (!HttpHeaders.equalsIgnoreCase(Values.UPGRADE, connection)) {
throw new WebSocketHandshakeException("Invalid handshake response connection: " + connection);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {

private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketClientHandshaker13.class);
private static final CharSequence WEBSOCKET = HttpHeaders.newEntity(Values.WEBSOCKET.toLowerCase());

public static final String MAGIC_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";

Expand Down Expand Up @@ -130,7 +131,7 @@ protected FullHttpRequest newHandshakeRequest() {
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path);
HttpHeaders headers = request.headers();

headers.add(Names.UPGRADE, Values.WEBSOCKET.toLowerCase())
headers.add(Names.UPGRADE, WEBSOCKET)
.add(Names.CONNECTION, Values.UPGRADE)
.add(Names.SEC_WEBSOCKET_KEY, key)
.add(Names.HOST, wsURL.getHost() + ':' + wsPort);
Expand Down Expand Up @@ -183,12 +184,12 @@ protected void verify(FullHttpResponse response) {
}

String upgrade = headers.get(Names.UPGRADE);
if (!Values.WEBSOCKET.equalsIgnoreCase(upgrade)) {
if (!HttpHeaders.equalsIgnoreCase(Values.WEBSOCKET, upgrade)) {
throw new WebSocketHandshakeException("Invalid handshake response upgrade: " + upgrade);
}

String connection = headers.get(Names.CONNECTION);
if (!Values.UPGRADE.equalsIgnoreCase(connection)) {
if (!HttpHeaders.equalsIgnoreCase(Values.UPGRADE, connection)) {
throw new WebSocketHandshakeException("Invalid handshake response connection: " + connection);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public WebSocketServerHandshaker00(String webSocketURL, String subprotocols, int
protected FullHttpResponse newHandshakeResponse(FullHttpRequest req, HttpHeaders headers) {

// Serve the WebSocket handshake request.
if (!Values.UPGRADE.equalsIgnoreCase(req.headers().get(CONNECTION))
|| !WEBSOCKET.equalsIgnoreCase(req.headers().get(Names.UPGRADE))) {
if (!HttpHeaders.equalsIgnoreCase(Values.UPGRADE, req.headers().get(CONNECTION))
|| !HttpHeaders.equalsIgnoreCase(WEBSOCKET, req.headers().get(Names.UPGRADE))) {
throw new WebSocketHandshakeException("not a WebSocket handshake request: missing upgrade");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import io.netty.handler.codec.http.FullHttpResponse;
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;

import static io.netty.handler.codec.http.HttpHeaders.Values.*;
import static io.netty.handler.codec.http.HttpVersion.*;

/**
Expand All @@ -35,6 +35,8 @@
*/
public class WebSocketServerHandshaker07 extends WebSocketServerHandshaker {

private static final CharSequence WEBSOCKET = HttpHeaders.newEntity(Values.WEBSOCKET.toLowerCase());

public static final String WEBSOCKET_07_ACCEPT_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";

private final boolean allowExtensions;
Expand Down Expand Up @@ -114,7 +116,7 @@ protected FullHttpResponse newHandshakeResponse(FullHttpRequest req, HttpHeaders
logger.debug("WebSocket version 07 server handshake key: {}, response: {}.", key, accept);
}

res.headers().add(Names.UPGRADE, WEBSOCKET.toLowerCase());
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import io.netty.handler.codec.http.FullHttpResponse;
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;

import static io.netty.handler.codec.http.HttpHeaders.Values.*;
import static io.netty.handler.codec.http.HttpVersion.*;

/**
Expand All @@ -35,6 +35,8 @@
*/
public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {

private static final CharSequence WEBSOCKET = HttpHeaders.newEntity(Values.WEBSOCKET.toLowerCase());

public static final String WEBSOCKET_08_ACCEPT_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";

private final boolean allowExtensions;
Expand Down Expand Up @@ -113,7 +115,7 @@ protected FullHttpResponse newHandshakeResponse(FullHttpRequest req, HttpHeaders
logger.debug("WebSocket version 08 server handshake key: {}, response: {}", key, accept);
}

res.headers().add(Names.UPGRADE, WEBSOCKET.toLowerCase());
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import io.netty.handler.codec.http.FullHttpResponse;
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;

import static io.netty.handler.codec.http.HttpHeaders.Values.*;
import static io.netty.handler.codec.http.HttpVersion.*;

/**
Expand All @@ -34,6 +34,8 @@
*/
public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {

private static final CharSequence WEBSOCKET = HttpHeaders.newEntity(Values.WEBSOCKET.toLowerCase());

public static final String WEBSOCKET_13_ACCEPT_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";

private final boolean allowExtensions;
Expand Down Expand Up @@ -111,7 +113,7 @@ protected FullHttpResponse newHandshakeResponse(FullHttpRequest req, HttpHeaders
logger.debug("WebSocket version 13 server handshake key: {}, response: {}", key, accept);
}

res.headers().add(Names.UPGRADE, WEBSOCKET.toLowerCase());
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.util.CharsetUtil;

Expand All @@ -38,11 +39,11 @@ public boolean acceptOutboundMessage(Object msg) throws Exception {
@Override
protected void encodeInitialLine(ByteBuf buf, HttpRequest request)
throws Exception {
encodeAscii(request.getMethod().toString(), buf);
HttpHeaders.encodeAscii(request.getMethod().toString(), buf);
buf.writeByte(SP);
buf.writeBytes(request.getUri().getBytes(CharsetUtil.UTF_8));
buf.writeByte(SP);
encodeAscii(request.getProtocolVersion().toString(), buf);
HttpHeaders.encodeAscii(request.getProtocolVersion().toString(), buf);
buf.writeBytes(CRLF);
}
}
Loading

0 comments on commit db3709e

Please sign in to comment.