From 6246825fda9332a421272ec649bd6ec0b3dd405a Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Wed, 27 Feb 2013 14:23:36 -0800 Subject: [PATCH] [#1100 ] Fix SPDY codec to work again in 4.x --- .../netty/handler/codec/spdy/SpdyHeaders.java | 28 +++++++++---------- .../handler/codec/spdy/SpdyHttpEncoder.java | 21 +++++++++----- .../codec/spdy/SpdySessionHandler.java | 2 +- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaders.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaders.java index 7afa155590..6ab424cf22 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaders.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaders.java @@ -108,9 +108,9 @@ public abstract class SpdyHeaders implements Iterable> */ public static final String HOST = ":host"; /** - * {@code ":getMethod"} + * {@code ":method"} */ - public static final String METHOD = ":getMethod"; + public static final String METHOD = ":method"; /** * {@code ":path"} */ @@ -120,9 +120,9 @@ public abstract class SpdyHeaders implements Iterable> */ public static final String SCHEME = ":scheme"; /** - * {@code ":getStatus"} + * {@code ":status"} */ - public static final String STATUS = ":getStatus"; + public static final String STATUS = ":status"; /** * {@code ":version"} */ @@ -136,17 +136,17 @@ public abstract class SpdyHeaders implements Iterable> */ public static final class Spdy2HttpNames { /** - * {@code "getMethod"} + * {@code "method"} */ - public static final String METHOD = "getMethod"; + public static final String METHOD = "method"; /** * {@code "scheme"} */ public static final String SCHEME = "scheme"; /** - * {@code "getStatus"} + * {@code "status"} */ - public static final String STATUS = "getStatus"; + public static final String STATUS = "status"; /** * {@code "url"} */ @@ -231,7 +231,7 @@ public abstract class SpdyHeaders implements Iterable> } /** - * Removes the HTTP getMethod header. + * Removes the HTTP method header. */ public static void removeMethod(int spdyVersion, SpdyHeaderBlock block) { if (spdyVersion < 3) { @@ -242,7 +242,7 @@ public abstract class SpdyHeaders implements Iterable> } /** - * Returns the {@link HttpMethod} represented by the HTTP getMethod header. + * Returns the {@link HttpMethod} represented by the HTTP method header. */ public static HttpMethod getMethod(int spdyVersion, SpdyHeaderBlock block) { try { @@ -257,7 +257,7 @@ public abstract class SpdyHeaders implements Iterable> } /** - * Sets the HTTP getMethod header. + * Sets the HTTP method header. */ public static void setMethod(int spdyVersion, SpdyHeaderBlock block, HttpMethod method) { if (spdyVersion < 3) { @@ -301,7 +301,7 @@ public abstract class SpdyHeaders implements Iterable> } /** - * Removes the HTTP response getStatus header. + * Removes the HTTP response status header. */ public static void removeStatus(int spdyVersion, SpdyHeaderBlock block) { if (spdyVersion < 3) { @@ -312,7 +312,7 @@ public abstract class SpdyHeaders implements Iterable> } /** - * Returns the {@link HttpResponseStatus} represented by the HTTP response getStatus header. + * Returns the {@link HttpResponseStatus} represented by the HTTP response status header. */ public static HttpResponseStatus getStatus(int spdyVersion, SpdyHeaderBlock block) { try { @@ -341,7 +341,7 @@ public abstract class SpdyHeaders implements Iterable> } /** - * Sets the HTTP response getStatus header. + * Sets the HTTP response status header. */ public static void setStatus(int spdyVersion, SpdyHeaderBlock block, HttpResponseStatus status) { if (spdyVersion < 3) { diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpEncoder.java index 28d7acfecd..6a00be5b82 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpEncoder.java @@ -142,11 +142,16 @@ public class SpdyHttpEncoder extends MessageToMessageEncoder { protected Object encode(ChannelHandlerContext ctx, HttpObject msg) throws Exception { List out = new ArrayList(); + + boolean valid = false; + if (msg instanceof HttpRequest) { HttpRequest httpRequest = (HttpRequest) msg; SpdySynStreamFrame spdySynStreamFrame = createSynStreamFrame(httpRequest); out.add(spdySynStreamFrame); + + valid = true; } if (msg instanceof HttpResponse) { @@ -158,6 +163,8 @@ public class SpdyHttpEncoder extends MessageToMessageEncoder { SpdySynReplyFrame spdySynReplyFrame = createSynReplyFrame(httpResponse); out.add(spdySynReplyFrame); } + + valid = true; } if (msg instanceof HttpContent) { @@ -185,7 +192,11 @@ public class SpdyHttpEncoder extends MessageToMessageEncoder { } else { out.add(spdyDataFrame); } - } else { + + valid = true; + } + + if (!valid) { throw new UnsupportedMessageTypeException(msg); } @@ -255,8 +266,6 @@ public class SpdyHttpEncoder extends MessageToMessageEncoder { private SpdySynReplyFrame createSynReplyFrame(HttpResponse httpResponse) throws Exception { - boolean chunked = HttpHeaders.isTransferEncodingChunked(httpResponse); - // Get the Stream-ID from the headers int streamID = SpdyHttpHeaders.getStreamId(httpResponse); SpdyHttpHeaders.removeStreamId(httpResponse); @@ -279,10 +288,8 @@ public class SpdyHttpEncoder extends MessageToMessageEncoder { spdySynReplyFrame.headers().add(entry.getKey(), entry.getValue()); } - if (chunked) { - currentStreamId = streamID; - spdySynReplyFrame.setLast(false); - } + currentStreamId = streamID; + spdySynReplyFrame.setLast(false); return spdySynReplyFrame; } diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySessionHandler.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySessionHandler.java index 52e59a57c1..b3aefc160b 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySessionHandler.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySessionHandler.java @@ -92,7 +92,7 @@ public class SpdySessionHandler @Override public void freeInboundBuffer(ChannelHandlerContext ctx) throws Exception { - ctx.inboundByteBuffer().release(); + ctx.inboundMessageBuffer().release(); } @Override