hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1681814 - in /httpcomponents/httpcore/trunk: httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/ httpcore/src/main/java/org/apache/http/impl/io/ httpcore/src/test/java/org...
Date Tue, 26 May 2015 18:56:31 GMT
Author: olegk
Date: Tue May 26 18:56:31 2015
New Revision: 1681814

URL: http://svn.apache.org/r1681814
Log:
RFC 7230: reject messages with incompatible major protocol version

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestParser.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseParser.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestHttpMessageParser.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParser.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParser.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestRequestParser.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestResponseParser.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestParser.java?rev=1681814&r1=1681813&r2=1681814&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestParser.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestParser.java
Tue May 26 18:56:31 2015
@@ -30,8 +30,11 @@ package org.apache.http.impl.nio.codecs;
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestFactory;
+import org.apache.http.HttpVersion;
 import org.apache.http.ParseException;
+import org.apache.http.ProtocolVersion;
 import org.apache.http.RequestLine;
+import org.apache.http.UnsupportedHttpVersionException;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.config.MessageConstraints;
 import org.apache.http.impl.DefaultHttpRequestFactory;
@@ -87,6 +90,10 @@ public class DefaultHttpRequestParser ex
     protected HttpRequest createMessage(final CharArrayBuffer buffer)
             throws HttpException, ParseException {
         final RequestLine requestLine = getLineParser().parseRequestLine(buffer);
+        final ProtocolVersion version = requestLine.getProtocolVersion();
+        if (version.greaterEquals(HttpVersion.HTTP_2)) {
+            throw new UnsupportedHttpVersionException("Unsupported version: " + version);
+        }
         return this.requestFactory.newHttpRequest(requestLine);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseParser.java?rev=1681814&r1=1681813&r2=1681814&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseParser.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseParser.java
Tue May 26 18:56:31 2015
@@ -30,8 +30,11 @@ package org.apache.http.impl.nio.codecs;
 import org.apache.http.HttpException;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpResponseFactory;
+import org.apache.http.HttpVersion;
 import org.apache.http.ParseException;
+import org.apache.http.ProtocolVersion;
 import org.apache.http.StatusLine;
+import org.apache.http.UnsupportedHttpVersionException;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.config.MessageConstraints;
 import org.apache.http.impl.DefaultHttpResponseFactory;
@@ -87,8 +90,12 @@ public class DefaultHttpResponseParser e
     @Override
     protected HttpResponse createMessage(final CharArrayBuffer buffer)
             throws HttpException, ParseException {
-        final StatusLine statusline = getLineParser().parseStatusLine(buffer);
-        return this.responseFactory.newHttpResponse(statusline, null);
+        final StatusLine statusLine = getLineParser().parseStatusLine(buffer);
+        final ProtocolVersion version = statusLine.getProtocolVersion();
+        if (version.greaterEquals(HttpVersion.HTTP_2)) {
+            throw new UnsupportedHttpVersionException("Unsupported version: " + version);
+        }
+        return this.responseFactory.newHttpResponse(statusLine, null);
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestHttpMessageParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestHttpMessageParser.java?rev=1681814&r1=1681813&r2=1681814&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestHttpMessageParser.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestHttpMessageParser.java
Tue May 26 18:56:31 2015
@@ -39,6 +39,7 @@ import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
+import org.apache.http.UnsupportedHttpVersionException;
 import org.apache.http.config.MessageConstraints;
 import org.apache.http.impl.nio.reactor.SessionInputBufferImpl;
 import org.apache.http.nio.NHttpMessageParser;
@@ -201,49 +202,14 @@ public class TestHttpMessageParser {
         Assert.assertEquals("whatever", request.getFirstHeader("Header").getValue());
     }
 
-    @Test
+    @Test(expected = HttpException.class)
     public void testParsingInvalidRequestLine() throws Exception {
         final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
         final NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser();
 
         final ReadableByteChannel channel = newChannel("GET garbage\r\n");
         inbuf.fill(channel);
-        try {
-            requestParser.parse(inbuf, false);
-            Assert.fail("HttpException should have been thrown");
-        } catch (final HttpException ex) {
-            // expected
-        }
-    }
-
-    @Test
-    public void testParsingInvalidStatusLine() throws Exception {
-        final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
-        final NHttpMessageParser<HttpResponse> responseParser = new DefaultHttpResponseParser();
-
-        final ReadableByteChannel channel = newChannel("HTTP 200 OK\r\n");
-        inbuf.fill(channel);
-        try {
-            responseParser.parse(inbuf, false);
-            Assert.fail("HttpException should have been thrown");
-        } catch (final HttpException ex) {
-            // expected
-        }
-    }
-
-    @Test
-    public void testParsingInvalidHeader() throws Exception {
-        final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
-        final NHttpMessageParser<HttpResponse> responseParser = new DefaultHttpResponseParser();
-
-        final ReadableByteChannel channel = newChannel("HTTP/1.0 200 OK\r\nstuff\r\n\r\n");
-        inbuf.fill(channel);
-        try {
-            responseParser.parse(inbuf, false);
-            Assert.fail("HttpException should have been thrown");
-        } catch (final HttpException ex) {
-            // expected
-        }
+        requestParser.parse(inbuf, false);
     }
 
     @Test
@@ -268,7 +234,7 @@ public class TestHttpMessageParser {
         Assert.assertEquals("two", request.getFirstHeader("Header").getValue());
     }
 
-    @Test
+    @Test(expected = IOException.class)
     public void testLineLimitForStatus() throws Exception {
         final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
         NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(
@@ -278,15 +244,11 @@ public class TestHttpMessageParser {
         requestParser.reset();
 
         requestParser = new DefaultHttpRequestParser(MessageConstraints.lineLen(15));
-        try {
-            inbuf.fill(newChannel("GET /loooooooooooooooong HTTP/1.0\r\nHeader: one\r\n\r\n"));
-            requestParser.parse(inbuf, false);
-            Assert.fail("IOException should have been thrown");
-        } catch (final IOException expected) {
-        }
+        inbuf.fill(newChannel("GET /loooooooooooooooong HTTP/1.0\r\nHeader: one\r\n\r\n"));
+        requestParser.parse(inbuf, false);
     }
 
-    @Test
+    @Test(expected = IOException.class)
     public void testLineLimitForHeader() throws Exception {
         final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
 
@@ -300,31 +262,23 @@ public class TestHttpMessageParser {
         inbuf.fill(newChannel("GET / HTTP/1.0\r\nHeader: 9012345\r\n\r\n"));
         requestParser.parse(inbuf, false);
         requestParser.reset();
-        try {
-            inbuf.fill(newChannel("GET / HTTP/1.0\r\nHeader: 90123456\r\n\r\n"));
-            requestParser.parse(inbuf, false);
-            Assert.fail("IOException should have been thrown");
-        } catch (final IOException expected) {
-        }
+        inbuf.fill(newChannel("GET / HTTP/1.0\r\nHeader: 90123456\r\n\r\n"));
+        requestParser.parse(inbuf, false);
     }
 
-    @Test
+    @Test(expected = IOException.class)
     public void testLineLimitForFoldedHeader() throws Exception {
         final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
 
         final MessageConstraints constraints = MessageConstraints.custom()
                 .setMaxHeaderCount(2).setMaxLineLength(15).build();
         final NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(constraints);
-        try {
-            inbuf.fill(newChannel("GET / HTTP/1.0\r\nHeader: 9012345\r\n" +
-                    " 23456789012345\r\n 23456789012345\r\n 23456789012345\r\n\r\n"));
-            requestParser.parse(inbuf, false);
-            Assert.fail("IOException should have been thrown");
-        } catch (final IOException expected) {
-        }
+        inbuf.fill(newChannel("GET / HTTP/1.0\r\nHeader: 9012345\r\n" +
+                " 23456789012345\r\n 23456789012345\r\n 23456789012345\r\n\r\n"));
+        requestParser.parse(inbuf, false);
     }
 
-    @Test
+    @Test(expected = IOException.class)
     public void testMaxHeaderCount() throws Exception {
         final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
 
@@ -335,16 +289,12 @@ public class TestHttpMessageParser {
         requestParser.parse(inbuf, false);
         requestParser.reset();
 
-        try {
-            inbuf.fill(newChannel("GET /whatever HTTP/1.0\r\nHeader: one\r\n" +
-                    "Header: two\r\nHeader: three\r\n\r\n"));
-            requestParser.parse(inbuf, false);
-            Assert.fail("IOException should have been thrown");
-        } catch (final IOException expected) {
-        }
+        inbuf.fill(newChannel("GET /whatever HTTP/1.0\r\nHeader: one\r\n" +
+                "Header: two\r\nHeader: three\r\n\r\n"));
+        requestParser.parse(inbuf, false);
     }
 
-    @Test
+    @Test(expected = IOException.class)
     public void testDetectLineLimitEarly() throws Exception {
         final SessionInputBuffer inbuf = new SessionInputBufferImpl(2, 128, Consts.ASCII);
 
@@ -354,11 +304,43 @@ public class TestHttpMessageParser {
         Assert.assertEquals(2, inbuf.fill(channel));
         Assert.assertNull(requestParser.parse(inbuf, false));
         Assert.assertEquals(4, inbuf.fill(channel));
-        try {
-            requestParser.parse(inbuf, false);
-            Assert.fail("IOException should have been thrown");
-        } catch (final IOException expected) {
-        }
+        requestParser.parse(inbuf, false);
+    }
+
+    @Test(expected = UnsupportedHttpVersionException.class)
+    public void testParsingUnsupportedRequestVersion() throws Exception {
+        final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
+        final NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser();
+        inbuf.fill(newChannel("GET /whatever HTTP/2.0\r\nSome header: stuff\r\n\r\n"));
+        requestParser.parse(inbuf, false);
+    }
+
+    @Test(expected = UnsupportedHttpVersionException.class)
+    public void testParsingUnsupportedVersion() throws Exception {
+        final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
+        final NHttpMessageParser<HttpResponse> requestParser = new DefaultHttpResponseParser();
+        inbuf.fill(newChannel("HTTP/2.0 200 OK\r\nSome header: stuff\r\n\r\n"));
+        requestParser.parse(inbuf, false);
+    }
+
+    @Test(expected = HttpException.class)
+    public void testParsingInvalidStatusLine() throws Exception {
+        final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
+        final NHttpMessageParser<HttpResponse> responseParser = new DefaultHttpResponseParser();
+
+        final ReadableByteChannel channel = newChannel("HTTP 200 OK\r\n");
+        inbuf.fill(channel);
+        responseParser.parse(inbuf, false);
+    }
+
+    @Test(expected = HttpException.class)
+    public void testParsingInvalidHeader() throws Exception {
+        final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
+        final NHttpMessageParser<HttpResponse> responseParser = new DefaultHttpResponseParser();
+
+        final ReadableByteChannel channel = newChannel("HTTP/1.0 200 OK\r\nstuff\r\n\r\n");
+        inbuf.fill(channel);
+        responseParser.parse(inbuf, false);
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParser.java?rev=1681814&r1=1681813&r2=1681814&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParser.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParser.java
Tue May 26 18:56:31 2015
@@ -33,8 +33,11 @@ import org.apache.http.ConnectionClosedE
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestFactory;
+import org.apache.http.HttpVersion;
 import org.apache.http.ParseException;
+import org.apache.http.ProtocolVersion;
 import org.apache.http.RequestLine;
+import org.apache.http.UnsupportedHttpVersionException;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.config.MessageConstraints;
 import org.apache.http.impl.DefaultHttpRequestFactory;
@@ -99,8 +102,12 @@ public class DefaultHttpRequestParser ex
         if (i == -1) {
             throw new ConnectionClosedException("Client closed connection");
         }
-        final RequestLine requestline = getLineParser().parseRequestLine(this.lineBuf);
-        return this.requestFactory.newHttpRequest(requestline);
+        final RequestLine requestLine = getLineParser().parseRequestLine(this.lineBuf);
+        final ProtocolVersion version = requestLine.getProtocolVersion();
+        if (version.greaterEquals(HttpVersion.HTTP_2)) {
+            throw new UnsupportedHttpVersionException("Unsupported version: " + version);
+        }
+        return this.requestFactory.newHttpRequest(requestLine);
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParser.java?rev=1681814&r1=1681813&r2=1681814&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParser.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParser.java
Tue May 26 18:56:31 2015
@@ -32,9 +32,12 @@ import java.io.IOException;
 import org.apache.http.HttpException;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpResponseFactory;
+import org.apache.http.HttpVersion;
 import org.apache.http.NoHttpResponseException;
 import org.apache.http.ParseException;
+import org.apache.http.ProtocolVersion;
 import org.apache.http.StatusLine;
+import org.apache.http.UnsupportedHttpVersionException;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.config.MessageConstraints;
 import org.apache.http.impl.DefaultHttpResponseFactory;
@@ -71,8 +74,7 @@ public class DefaultHttpResponseParser e
             final HttpResponseFactory responseFactory,
             final MessageConstraints constraints) {
         super(lineParser, constraints);
-        this.responseFactory = responseFactory != null ? responseFactory :
-            DefaultHttpResponseFactory.INSTANCE;
+        this.responseFactory = responseFactory != null ? responseFactory : DefaultHttpResponseFactory.INSTANCE;
         this.lineBuf = new CharArrayBuffer(128);
     }
 
@@ -91,8 +93,8 @@ public class DefaultHttpResponseParser e
     }
 
     @Override
-    protected HttpResponse parseHead(final SessionInputBuffer sessionBuffer)
-        throws IOException, HttpException, ParseException {
+    protected HttpResponse parseHead(
+            final SessionInputBuffer sessionBuffer) throws IOException, HttpException, ParseException
{
 
         this.lineBuf.clear();
         final int i = sessionBuffer.readLine(this.lineBuf);
@@ -101,6 +103,10 @@ public class DefaultHttpResponseParser e
         }
         //create the status line from the status string
         final StatusLine statusline = getLineParser().parseStatusLine(this.lineBuf);
+        final ProtocolVersion version = statusline.getProtocolVersion();
+        if (version.greaterEquals(HttpVersion.HTTP_2)) {
+            throw new UnsupportedHttpVersionException("Unsupported version: " + version);
+        }
         return this.responseFactory.newHttpResponse(statusline, null);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestRequestParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestRequestParser.java?rev=1681814&r1=1681813&r2=1681814&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestRequestParser.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestRequestParser.java
Tue May 26 18:56:31 2015
@@ -34,6 +34,7 @@ import org.apache.http.Header;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpVersion;
 import org.apache.http.RequestLine;
+import org.apache.http.UnsupportedHttpVersionException;
 import org.apache.http.impl.SessionInputBufferMock;
 import org.apache.http.io.SessionInputBuffer;
 import org.junit.Assert;
@@ -66,16 +67,12 @@ public class TestRequestParser {
         Assert.assertEquals(3, headers.length);
     }
 
-    @Test
+    @Test(expected = ConnectionClosedException.class)
     public void testConnectionClosedException() throws Exception {
         final SessionInputBuffer inbuffer = new SessionInputBufferMock(new byte[] {});
 
         final DefaultHttpRequestParser parser = new DefaultHttpRequestParser();
-        try {
-            parser.parse(inbuffer);
-            Assert.fail("ConnectionClosedException should have been thrown");
-        } catch (final ConnectionClosedException expected) {
-        }
+        parser.parse(inbuffer);
     }
 
     @Test
@@ -107,8 +104,7 @@ public class TestRequestParser {
         Assert.assertEquals(5, timeoutCount);
 
         @SuppressWarnings("null") // httprequest cannot be null here
-        final
-        RequestLine reqline = httprequest.getRequestLine();
+        final RequestLine reqline = httprequest.getRequestLine();
         Assert.assertNotNull(reqline);
         Assert.assertEquals("GET", reqline.getMethod());
         Assert.assertEquals("/", reqline.getUri());
@@ -117,5 +113,13 @@ public class TestRequestParser {
         Assert.assertEquals(3, headers.length);
     }
 
+    @Test(expected = UnsupportedHttpVersionException.class)
+    public void testParsingUnsupportedVersion() throws Exception {
+        final String s = "GET / HTTP/2.0\r\n\r\n";
+        final SessionInputBuffer inbuffer = new SessionInputBufferMock(s, Consts.ASCII);
+        final DefaultHttpRequestParser parser = new DefaultHttpRequestParser();
+        parser.parse(inbuffer);
+    }
+
 }
 

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestResponseParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestResponseParser.java?rev=1681814&r1=1681813&r2=1681814&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestResponseParser.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestResponseParser.java
Tue May 26 18:56:31 2015
@@ -35,6 +35,7 @@ import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
 import org.apache.http.NoHttpResponseException;
 import org.apache.http.StatusLine;
+import org.apache.http.UnsupportedHttpVersionException;
 import org.apache.http.impl.SessionInputBufferMock;
 import org.apache.http.io.SessionInputBuffer;
 import org.junit.Assert;
@@ -67,16 +68,12 @@ public class TestResponseParser {
         Assert.assertEquals(3, headers.length);
     }
 
-    @Test
+    @Test(expected = NoHttpResponseException.class)
     public void testConnectionClosedException() throws Exception {
         final SessionInputBuffer inbuffer = new SessionInputBufferMock(new byte[] {});
 
         final DefaultHttpResponseParser parser = new DefaultHttpResponseParser();
-        try {
-            parser.parse(inbuffer);
-            Assert.fail("NoHttpResponseException should have been thrown");
-        } catch (final NoHttpResponseException expected) {
-        }
+        parser.parse(inbuffer);
     }
 
     @Test
@@ -102,14 +99,12 @@ public class TestResponseParser {
             } catch (final InterruptedIOException ex) {
                 timeoutCount++;
             }
-
         }
         Assert.assertNotNull(httpresponse);
         Assert.assertEquals(5, timeoutCount);
 
         @SuppressWarnings("null") // httpresponse cannot be null here
-        final
-        StatusLine statusline = httpresponse.getStatusLine();
+        final StatusLine statusline = httpresponse.getStatusLine();
         Assert.assertNotNull(statusline);
         Assert.assertEquals(200, statusline.getStatusCode());
         Assert.assertEquals("OK", statusline.getReasonPhrase());
@@ -118,5 +113,13 @@ public class TestResponseParser {
         Assert.assertEquals(3, headers.length);
     }
 
+    @Test(expected = UnsupportedHttpVersionException.class)
+    public void testParsingUnsupportedVersion() throws Exception {
+        final String s = "HTTP/2.0 200 OK\r\n\r\n";
+        final SessionInputBuffer inbuffer = new SessionInputBufferMock(s, Consts.ASCII);
+        final DefaultHttpResponseParser parser = new DefaultHttpResponseParser();
+        parser.parse(inbuffer);
+    }
+
 }
 



Mime
View raw message