From eaf65a2902acc7bb0794f09323ddace8cbe2e9a8 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 8 Nov 2012 14:36:48 +1100 Subject: [PATCH] 393075 1xx 204 and 304 ignore all headers suggesting content --- .../java/org/eclipse/jetty/http/HttpParser.java | 13 +++++++++---- .../jetty/websocket/TomcatServerQuirksTest.java | 11 +++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java index 40f8d156157..4fab1e0c26b 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java @@ -525,7 +525,7 @@ public class HttpParser implements Parser switch (ho) { case HttpHeaders.CONTENT_LENGTH_ORDINAL: - if (_contentLength != HttpTokens.CHUNKED_CONTENT && _responseStatus!=304 && _responseStatus!=204 && (_responseStatus<100 || _responseStatus>=200)) + if (_contentLength != HttpTokens.CHUNKED_CONTENT ) { try { @@ -596,12 +596,17 @@ public class HttpParser implements Parser } _buffer.setMarkIndex(-1); - // now handle ch if (ch == HttpTokens.CARRIAGE_RETURN || ch == HttpTokens.LINE_FEED) { - // work out the _content demarcation - if (_contentLength == HttpTokens.UNKNOWN_CONTENT) + // is it a response that cannot have a body? + if (_responseStatus > 0 && // response + (_responseStatus == 304 || // not-modified response + _responseStatus == 204 || // no-content response + _responseStatus < 200)) // 1xx response + _contentLength=HttpTokens.NO_CONTENT; // ignore any other headers set + // else if we don't know framing + else if (_contentLength == HttpTokens.UNKNOWN_CONTENT) { if (_responseStatus == 0 // request || _responseStatus == 304 // not-modified response diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/TomcatServerQuirksTest.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/TomcatServerQuirksTest.java index 754a4199db4..8fdd3a1b67e 100644 --- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/TomcatServerQuirksTest.java +++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/TomcatServerQuirksTest.java @@ -44,14 +44,15 @@ public class TomcatServerQuirksTest * @throws IOException */ @Test - @Ignore("Bug with Transfer-Encoding") - public void testTomcat7_0_32_WithTransferEncoding() throws Exception { + public void testTomcat7_0_32_WithTransferEncoding() throws Exception + { DummyServer server = new DummyServer(); int bufferSize = 512; QueuedThreadPool threadPool = new QueuedThreadPool(); WebSocketClientFactory factory = new WebSocketClientFactory(threadPool, new ZeroMaskGen(), bufferSize); - try { + try + { server.start(); // Setup Client Factory @@ -113,7 +114,9 @@ public class TomcatServerQuirksTest socket.flush(); Assert.assertTrue(dataLatch.await(1000, TimeUnit.SECONDS)); - } finally { + } + finally + { factory.stop(); threadPool.stop(); server.stop();