From b19a12b952398dba12e46db452f0b8220d1e0267 Mon Sep 17 00:00:00 2001 From: Nitesh Kant Date: Thu, 29 Jan 2015 23:08:15 -0800 Subject: [PATCH] Fixes #3362 (Possible wrong behavior in `HttpResponseDecoder`/`HttpRequestDecoder` for large header/initline/content) Motivation: `HttpResponseDecoder` and `HttpRequestDecoder` in the event when the max configured sizes for HTTP initial line, headers or content is breached, sends a `DefaultHttpResponse` and `DefaultHttpRequest` respectively. After this `HttpObjectDecoder` gets into `BAD_MESSAGE` state and ignores any other data received on this connection. The combination of the above two behaviors, means that the decoded response/request are not complete (absence of sending `LastHTTPContent`). So, any code, waiting for a complete message will have to additionally check for decoder result to follow the correct semantics of HTTP. If `HttpResponseDecoder` and `HttpRequestDecoder` creates a Full* invalid message then the request/response is a complete HTTP message and hence obeys the HTTP contract. Modification: Modified `HttpRequestDecoder`, `HttpResponseDecoder`, `RtspRequestDecoder` and `RtspResponseDecoder` to return Full* messages from `createInvalidMessage()` Result: Fixes the wrong behavior of sending incomplete messages from these codecs --- .../java/io/netty/handler/codec/http/HttpRequestDecoder.java | 2 +- .../java/io/netty/handler/codec/http/HttpResponseDecoder.java | 2 +- .../java/io/netty/handler/codec/rtsp/RtspRequestDecoder.java | 3 ++- .../java/io/netty/handler/codec/rtsp/RtspResponseDecoder.java | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestDecoder.java index bae740864f..0fb0339e8f 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestDecoder.java @@ -84,7 +84,7 @@ public class HttpRequestDecoder extends HttpObjectDecoder { @Override protected HttpMessage createInvalidMessage() { - return new DefaultHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "/bad-request", validateHeaders); + return new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "/bad-request", validateHeaders); } @Override diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseDecoder.java index 982f98286b..bbb747057b 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseDecoder.java @@ -115,7 +115,7 @@ public class HttpResponseDecoder extends HttpObjectDecoder { @Override protected HttpMessage createInvalidMessage() { - return new DefaultHttpResponse(HttpVersion.HTTP_1_0, UNKNOWN_STATUS, validateHeaders); + return new DefaultFullHttpResponse(HttpVersion.HTTP_1_0, UNKNOWN_STATUS, validateHeaders); } @Override diff --git a/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspRequestDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspRequestDecoder.java index 2222ee91c5..6be4d403a6 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspRequestDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspRequestDecoder.java @@ -17,6 +17,7 @@ package io.netty.handler.codec.rtsp; import io.netty.buffer.ByteBuf; import io.netty.handler.codec.TooLongFrameException; +import io.netty.handler.codec.http.DefaultFullHttpRequest; import io.netty.handler.codec.http.DefaultHttpRequest; import io.netty.handler.codec.http.HttpMessage; import io.netty.handler.codec.http.HttpRequest; @@ -78,7 +79,7 @@ public class RtspRequestDecoder extends RtspObjectDecoder { @Override protected HttpMessage createInvalidMessage() { - return new DefaultHttpRequest(RtspVersions.RTSP_1_0, RtspMethods.OPTIONS, "/bad-request", validateHeaders); + return new DefaultFullHttpRequest(RtspVersions.RTSP_1_0, RtspMethods.OPTIONS, "/bad-request", validateHeaders); } @Override diff --git a/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspResponseDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspResponseDecoder.java index cdf49902a4..0234c6773b 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspResponseDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspResponseDecoder.java @@ -17,6 +17,7 @@ package io.netty.handler.codec.rtsp; import io.netty.buffer.ByteBuf; import io.netty.handler.codec.TooLongFrameException; +import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.DefaultHttpResponse; import io.netty.handler.codec.http.HttpMessage; import io.netty.handler.codec.http.HttpResponse; @@ -83,7 +84,7 @@ public class RtspResponseDecoder extends RtspObjectDecoder { @Override protected HttpMessage createInvalidMessage() { - return new DefaultHttpResponse(RtspVersions.RTSP_1_0, UNKNOWN_STATUS, validateHeaders); + return new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, UNKNOWN_STATUS, validateHeaders); } @Override