You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2025/02/12 15:36:28 UTC

(httpcomponents-core) branch master updated (b0b040b27 -> e2e311009)

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git


 discard b0b040b27 Bug fix: Corrected state tracking of pipelined message exchanges by   HTTP/1.1 async client protocol handler
     new 1d65a168f Bug fix: Corrected state tracking of pipelined message exchanges by HTTP/1.1 async client protocol handler
     new e2e311009 Bug fix: Corrected handling of invalid HTTP protocol version by HTTP/1.1 async client protocol handler

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (b0b040b27)
            \
             N -- N -- N   refs/heads/master (e2e311009)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../hc/core5/testing/nio/Http1IntegrationTest.java | 46 ++++++++++++++++++++++
 .../http/impl/nio/ServerHttp1StreamHandler.java    | 15 ++++---
 2 files changed, 53 insertions(+), 8 deletions(-)


(httpcomponents-core) 02/02: Bug fix: Corrected handling of invalid HTTP protocol version by HTTP/1.1 async client protocol handler

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit e2e3110091fdb6dbedfd3aab0a9a1269bf16ecda
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Feb 12 16:23:21 2025 +0100

    Bug fix: Corrected handling of invalid HTTP protocol version by HTTP/1.1 async client protocol handler
---
 .../hc/core5/testing/nio/Http1IntegrationTest.java | 46 ++++++++++++++++++++++
 .../http/impl/nio/ServerHttp1StreamHandler.java    | 15 ++++---
 2 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
index 6c7472a82..ce62f597c 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
@@ -83,11 +83,15 @@
 import org.apache.hc.core5.http.impl.Http1StreamListener;
 import org.apache.hc.core5.http.impl.HttpProcessors;
 import org.apache.hc.core5.http.impl.nio.AbstractContentEncoder;
+import org.apache.hc.core5.http.impl.nio.AbstractMessageWriter;
 import org.apache.hc.core5.http.impl.nio.DefaultHttpRequestFactory;
 import org.apache.hc.core5.http.impl.nio.DefaultHttpRequestParser;
 import org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexer;
 import org.apache.hc.core5.http.message.BasicHttpRequest;
 import org.apache.hc.core5.http.message.BasicHttpResponse;
+import org.apache.hc.core5.http.message.BasicLineFormatter;
+import org.apache.hc.core5.http.message.LineFormatter;
+import org.apache.hc.core5.http.message.RequestLine;
 import org.apache.hc.core5.http.nio.AsyncEntityProducer;
 import org.apache.hc.core5.http.nio.AsyncRequestConsumer;
 import org.apache.hc.core5.http.nio.AsyncRequestProducer;
@@ -2154,4 +2158,46 @@ protected HttpRequest createMessage(final CharArrayBuffer buffer) throws HttpExc
         Assertions.assertInstanceOf(ConnectionClosedException.class, executionException.getCause());
     }
 
+    @Test
+    void testInvalidProtocolVersion() throws Exception {
+        final Http1TestServer server = resources.server();
+        final Http1TestClient client = resources.client();
+
+        server.register("/hello", () -> new SingleLineResponseHandler("Hi there"));
+        final InetSocketAddress serverEndpoint = server.start();
+        final HttpHost target = target(serverEndpoint);
+
+        final LineFormatter lineFormatter = BasicLineFormatter.INSTANCE;
+        client.configure(() -> new AbstractMessageWriter<HttpRequest>(lineFormatter) {
+
+            @Override
+            protected void writeHeadLine(final HttpRequest message, final CharArrayBuffer lineBuf) throws IOException {
+                lineBuf.clear();
+                lineFormatter.formatRequestLine(lineBuf, new RequestLine(
+                    message.getMethod(),
+                    message.getRequestUri(),
+                    new HttpVersion(2, 1)));
+            }
+
+        });
+        client.start();
+        final Future<ClientSessionEndpoint> connectFuture = client.connect(
+            "localhost", serverEndpoint.getPort(), TIMEOUT);
+        final ClientSessionEndpoint streamEndpoint = connectFuture.get();
+
+        final BasicHttpRequest request = BasicRequestBuilder.get()
+                .setHttpHost(target)
+                .setPath("/hello")
+                .build();
+
+        final Future<Message<HttpResponse, String>> future = streamEndpoint.execute(
+            new BasicRequestProducer(request, null),
+            new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
+        final Message<HttpResponse, String> result = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+        Assertions.assertNotNull(result);
+        final HttpResponse response = result.getHead();
+        Assertions.assertNotNull(response);
+        Assertions.assertEquals(505, response.getCode());
+    }
+
 }
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
index da71b9d07..28f108e31 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
@@ -253,15 +253,14 @@ void consumeHeader(final HttpRequest request, final EntityDetails requestEntityD
         }
         receivedRequest = request;
         requestState = requestEntityDetails == null ? MessageState.COMPLETE : MessageState.BODY;
-
-        final ProtocolVersion transportVersion = request.getVersion();
-        if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
-            throw new UnsupportedHttpVersionException(transportVersion);
-        }
-        context.setProtocolVersion(transportVersion != null ? transportVersion : http1Config.getVersion());
-        context.setRequest(request);
-
         try {
+            final ProtocolVersion transportVersion = request.getVersion();
+            if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
+                throw new UnsupportedHttpVersionException(transportVersion);
+            }
+            context.setProtocolVersion(transportVersion != null ? transportVersion : http1Config.getVersion());
+            context.setRequest(request);
+
             httpProcessor.process(request, requestEntityDetails, context);
 
             AsyncServerExchangeHandler handler;


(httpcomponents-core) 01/02: Bug fix: Corrected state tracking of pipelined message exchanges by HTTP/1.1 async client protocol handler

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit 1d65a168f7955dfc4b09f0cfe22e0c8528cefe2b
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Feb 12 15:14:30 2025 +0100

    Bug fix: Corrected state tracking of pipelined message exchanges by HTTP/1.1 async client protocol handler
---
 .../hc/core5/testing/nio/Http1IntegrationTest.java | 42 ++++++++++++++++++++++
 .../http/impl/nio/ClientHttp1StreamDuplexer.java   |  4 +--
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
index c2899fd4a..6c7472a82 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
@@ -57,6 +57,7 @@
 import java.util.concurrent.locks.ReentrantLock;
 
 import org.apache.hc.core5.function.Callback;
+import org.apache.hc.core5.http.ConnectionClosedException;
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.ContentLengthStrategy;
 import org.apache.hc.core5.http.ContentType;
@@ -82,6 +83,8 @@
 import org.apache.hc.core5.http.impl.Http1StreamListener;
 import org.apache.hc.core5.http.impl.HttpProcessors;
 import org.apache.hc.core5.http.impl.nio.AbstractContentEncoder;
+import org.apache.hc.core5.http.impl.nio.DefaultHttpRequestFactory;
+import org.apache.hc.core5.http.impl.nio.DefaultHttpRequestParser;
 import org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexer;
 import org.apache.hc.core5.http.message.BasicHttpRequest;
 import org.apache.hc.core5.http.message.BasicHttpResponse;
@@ -2112,4 +2115,43 @@ void testHeaderTooLargePost() throws Exception {
         Assertions.assertEquals("Maximum line length limit exceeded", result1.getBody());
     }
 
+    @Test
+    void testInvalidRequestMessage() throws Exception {
+        final Http1Config http1Config = Http1Config.DEFAULT;
+        final Http1TestServer server = resources.server();
+        server.configure(http1Config);
+        server.configure(() -> new DefaultHttpRequestParser<HttpRequest>(http1Config, DefaultHttpRequestFactory.INSTANCE) {
+
+            @Override
+            protected HttpRequest createMessage(final CharArrayBuffer buffer) throws HttpException {
+                throw new RuntimeException("Ka-boom");
+            }
+
+        });
+
+        server.register("/hello", () -> new SingleLineResponseHandler("Hi there"));
+
+        final InetSocketAddress serverEndpoint = server.start();
+        final HttpHost target = target(serverEndpoint);
+
+        final Http1TestClient client = resources.client();
+
+        client.start();
+        final Future<ClientSessionEndpoint> connectFuture = client.connect(
+                "localhost", serverEndpoint.getPort(), TIMEOUT);
+        final ClientSessionEndpoint streamEndpoint = connectFuture.get();
+
+        final BasicHttpRequest request = BasicRequestBuilder.get()
+                .setHttpHost(target)
+                .setPath("/hello")
+                .build();
+
+        final Future<Message<HttpResponse, String>> future = streamEndpoint.execute(
+                new BasicRequestProducer(request, null),
+                new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
+        final ExecutionException executionException = Assertions.assertThrows(ExecutionException.class, () ->
+                future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()));
+        Assertions.assertInstanceOf(ConnectionClosedException.class, executionException.getCause());
+    }
+
 }
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
index 7299d7251..a67b9926e 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
@@ -288,12 +288,12 @@ protected ContentEncoder createContentEncoder(
 
     @Override
     boolean inputIdle() {
-        return incoming == null;
+        return incoming == null && pipeline.isEmpty();
     }
 
     @Override
     boolean outputIdle() {
-        return outgoing == null && pipeline.isEmpty();
+        return outgoing == null;
     }
 
     @Override