From d4348ab4d75c2db7befbe59b050a98f8a70a27fd Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Sun, 30 Nov 2008 16:22:03 +0000 Subject: [PATCH] Fixed NETTY-86 (HttpResponseDecoder decodes the initial line incorrectly.) --- .../codec/http/HttpMessageDecoder.java | 54 ++++++++++++------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/jboss/netty/handler/codec/http/HttpMessageDecoder.java b/src/main/java/org/jboss/netty/handler/codec/http/HttpMessageDecoder.java index 7dafc827da..5ccf9042ed 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/HttpMessageDecoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/HttpMessageDecoder.java @@ -22,6 +22,8 @@ package org.jboss.netty.handler.codec.http; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; @@ -37,10 +39,14 @@ import org.jboss.netty.handler.codec.replay.ReplayingDecoder; * @author Trustin Lee (tlee@redhat.com) */ public abstract class HttpMessageDecoder extends ReplayingDecoder { + + private static final Pattern INITIAL_PATTERN = Pattern.compile( + "^\\s*(\\S+)\\s+(\\S+)\\s+(.*)\\s*$"); + private static final Pattern HEADER_PATTERN = Pattern.compile( + "^\\s*(\\S+)\\s*:\\s*(.*)\\s*$"); + protected HttpMessage message; - private ChannelBuffer content; - private int chunkSize; public enum ResponseState { @@ -79,8 +85,10 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder current = message.getHeaders(lastHeader); int lastPos = current.size() - 1; @@ -164,8 +173,14 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder 0) { + if (message.getContentLength() >= 0) { nextState = ResponseState.READ_FIXED_LENGTH_CONTENT; } else if (message.isChunked()) { @@ -188,8 +203,10 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder