hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1709766 - in /httpcomponents/httpcore/trunk/httpcore-nio/src: main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java test/java/org/apache/http/nio/integration/TestHttpAsyncHandlersPipelining.java
Date Wed, 21 Oct 2015 08:51:01 GMT
Author: olegk
Date: Wed Oct 21 08:51:01 2015
New Revision: 1709766

URL: http://svn.apache.org/viewvc?rev=1709766&view=rev
Log:
Fixed handling of pipelined HEAD requests

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlersPipelining.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java?rev=1709766&r1=1709765&r2=1709766&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
Wed Oct 21 08:51:01 2015
@@ -29,6 +29,8 @@ package org.apache.http.nio.protocol;
 
 import java.io.IOException;
 import java.net.SocketTimeoutException;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
 
 import org.apache.http.ConnectionClosedException;
 import org.apache.http.ExceptionLogger;
@@ -185,6 +187,9 @@ public class HttpAsyncRequestExecutor im
             throw new ProtocolException(version + " cannot be used with request pipelining");
         }
         state.setRequest(request);
+        if (pipelined) {
+            state.getRequestQueue().add(request);
+        }
 
         final HttpEntity entity = request.getEntity();
         if (entity != null) {
@@ -241,12 +246,21 @@ public class HttpAsyncRequestExecutor im
         Asserts.check(state.getResponseState() == MessageState.READY,
                 "Unexpected request state %s", state.getResponseState());
 
-        final HttpRequest request = state.getRequest();
-        if (request == null) {
-            throw new HttpException("Out of sequence response");
-        }
         final HttpAsyncClientExchangeHandler handler = getHandler(conn);
         Asserts.notNull(handler, "Client exchange handler");
+
+        final boolean pipelined = handler.getClass().getAnnotation(Pipelined.class) != null;
+        final HttpRequest request;
+        if (pipelined) {
+            request = state.getRequestQueue().poll();
+            Asserts.notNull(request, "HTTP request");
+        } else {
+            request = state.getRequest();
+            if (request == null) {
+                throw new HttpException("Out of sequence response");
+            }
+        }
+
         final HttpResponse response = conn.getHttpResponse();
 
         final int statusCode = response.getStatusLine().getStatusCode();
@@ -442,6 +456,7 @@ public class HttpAsyncRequestExecutor im
 
     static class State {
 
+        private final Queue<HttpRequest> requestQueue;
         private volatile MessageState requestState;
         private volatile MessageState responseState;
         private volatile HttpRequest request;
@@ -451,6 +466,7 @@ public class HttpAsyncRequestExecutor im
 
         State() {
             super();
+            this.requestQueue = new ConcurrentLinkedQueue<>();
             this.valid = true;
             this.requestState = MessageState.READY;
             this.responseState = MessageState.READY;
@@ -488,6 +504,10 @@ public class HttpAsyncRequestExecutor im
             this.response = response;
         }
 
+        public Queue<HttpRequest> getRequestQueue() {
+            return this.requestQueue;
+        }
+
         public int getTimeout() {
             return this.timeout;
         }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlersPipelining.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlersPipelining.java?rev=1709766&r1=1709765&r2=1709766&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlersPipelining.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlersPipelining.java
Wed Oct 21 08:51:01 2015
@@ -188,10 +188,11 @@ public class TestHttpAsyncHandlersPipeli
         final Queue<Future<List<HttpResponse>>> queue = new ConcurrentLinkedQueue<>();
         for (int i = 0; i < 10; i++) {
             final String requestUri = createRequestUri(pattern, count);
-            final Future<List<HttpResponse>> future = this.client.executePipelined(target,
-                    new BasicHttpRequest("GET", requestUri),
-                    new BasicHttpRequest("GET", requestUri),
-                    new BasicHttpRequest("GET", requestUri));
+            final HttpRequest head1 = new BasicHttpRequest("HEAD", requestUri);
+            final HttpRequest head2 = new BasicHttpRequest("HEAD", requestUri);
+            final HttpRequest post1 = new BasicHttpRequest("POST", requestUri);
+            post1.setEntity(new NStringEntity("stuff", ContentType.TEXT_PLAIN));
+            final Future<List<HttpResponse>> future = this.client.executePipelined(target,
head1, head2, post1);
             queue.add(future);
         }
 



Mime
View raw message