hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1791523 - in /httpcomponents/httpcore/trunk: httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2StreamHandler.java httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
Date Sat, 15 Apr 2017 17:02:35 GMT
Author: olegk
Date: Sat Apr 15 17:02:35 2017
New Revision: 1791523

URL: http://svn.apache.org/viewvc?rev=1791523&view=rev
Log:
Fixed HTTP/2 server side response message delineation when replying to HEAD requests

Modified:
    httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2StreamHandler.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java

Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2StreamHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2StreamHandler.java?rev=1791523&r1=1791522&r2=1791523&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2StreamHandler.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2StreamHandler.java
Sat Apr 15 17:02:35 2017
@@ -69,6 +69,7 @@ public class ServerHttp2StreamHandler im
     private final AtomicBoolean done;
 
     private volatile AsyncServerExchangeHandler exchangeHandler;
+    private volatile HttpRequest receivedRequest;
     private volatile MessageState requestState;
     private volatile MessageState responseState;
 
@@ -140,7 +141,10 @@ public class ServerHttp2StreamHandler im
 
             final List<Header> responseHeaders = DefaultH2ResponseConverter.INSTANCE.convert(response);
 
-            outputChannel.submit(responseHeaders, responseEntityDetails == null);
+            Asserts.notNull(receivedRequest, "Received request");
+            final String method = receivedRequest.getMethod();
+            final boolean endStream = responseEntityDetails == null || method.equalsIgnoreCase("HEAD");
+            outputChannel.submit(responseHeaders, endStream);
             connMetrics.incrementResponseCount();
             if (responseEntityDetails == null) {
                 responseState = MessageState.COMPLETE;
@@ -201,6 +205,7 @@ public class ServerHttp2StreamHandler im
 
                 httpProcessor.process(request, requestEntityDetails, context);
                 connMetrics.incrementRequestCount();
+                receivedRequest = request;
 
                 exchangeHandler.handleRequest(request, requestEntityDetails, new ResponseChannel()
{
 

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java?rev=1791523&r1=1791522&r2=1791523&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
Sat Apr 15 17:02:35 2017
@@ -199,6 +199,36 @@ public class Http2IntegrationTest extend
     }
 
     @Test
+    public void testSimpleHead() throws Exception {
+        server.register("/hello", new Supplier<AsyncServerExchangeHandler>() {
+
+            @Override
+            public AsyncServerExchangeHandler get() {
+                return new SingleLineResponseHandler("Hi there");
+            }
+
+        });
+        final InetSocketAddress serverEndpoint = server.start();
+
+        client.start();
+        final Future<ClientSessionEndpoint> connectFuture = client.connect(
+                "localhost", serverEndpoint.getPort(), TIMEOUT);
+        final ClientSessionEndpoint streamEndpoint = connectFuture.get();
+
+        for (int i = 0; i < 5; i++) {
+            final Future<Message<HttpResponse, String>> future = streamEndpoint.execute(
+                    new BasicRequestProducer("HEAD", createRequestURI(serverEndpoint, "/hello")),
+                    new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
+            final Message<HttpResponse, String> result = future.get(TIMEOUT.getDuration(),
TIMEOUT.getTimeUnit());
+            Assert.assertNotNull(result);
+            final HttpResponse response1 = result.getHead();
+            Assert.assertNotNull(response1);
+            Assert.assertEquals(200, response1.getCode());
+            Assert.assertNull(result.getBody());
+        }
+    }
+
+    @Test
     public void testLargeGet() throws Exception {
         server.register("/", new Supplier<AsyncServerExchangeHandler>() {
 



Mime
View raw message