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 2022/01/30 18:01:56 UTC

[httpcomponents-core] branch master updated (fc1d4da -> 1186aa2)

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.


    omit fc1d4da  Protocol negotiators now keep track the negotiated HTTP protocol version and can report it to the application layer
     new 1186aa2  Protocol negotiators now keep track the negotiated HTTP protocol version and can report it to the application layer

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   (fc1d4da)
            \
             N -- N -- N   refs/heads/master (1186aa2)

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 1 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/http2/impl/nio/ClientHttpProtocolNegotiator.java |  4 ++--
 .../core5/http2/impl/nio/H2OnlyClientProtocolNegotiator.java  |  5 ++---
 .../http2/impl/nio/H2OnlyServerHttpProtocolNegotiator.java    |  2 +-
 .../hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java | 11 ++++-------
 4 files changed, 9 insertions(+), 13 deletions(-)

[httpcomponents-core] 01/01: Protocol negotiators now keep track the negotiated HTTP protocol version and can report it to the application layer

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 1186aa237072a452de5ecccd479d85c5133baf07
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Thu Jan 27 18:37:51 2022 +0100

    Protocol negotiators now keep track the negotiated HTTP protocol version and can report it to the application layer
---
 .../hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java    | 3 +++
 .../hc/core5/http2/impl/nio/H2OnlyClientProtocolNegotiator.java  | 5 +++--
 .../core5/http2/impl/nio/H2OnlyServerHttpProtocolNegotiator.java | 2 ++
 .../apache/hc/core5/http2/impl/nio/ProtocolNegotiatorBase.java   | 8 +++++++-
 .../hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java    | 9 +++++----
 5 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
index 9c2152f..19934c8 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
@@ -34,6 +34,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.hc.core5.annotation.Internal;
 import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.impl.nio.BufferedData;
 import org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler;
 import org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory;
@@ -93,6 +94,7 @@ public class ClientHttpProtocolNegotiator extends ProtocolNegotiatorBase {
     }
 
     private void startHttp1() throws IOException {
+        setNegotiatedProtocol(HttpVersion.HTTP_1_1);
         final ByteBuffer data = inBuf != null ? inBuf.data() : null;
         startProtocol(new ClientHttp1IOEventHandler(http1StreamHandlerFactory.create(ioSession)), data);
         ioSession.registerProtocol(ApplicationProtocol.HTTP_2.id, new ClientH2UpgradeHandler(http2StreamHandlerFactory));
@@ -102,6 +104,7 @@ public class ClientHttpProtocolNegotiator extends ProtocolNegotiatorBase {
     }
 
     private void startHttp2() throws IOException {
+        setNegotiatedProtocol(HttpVersion.HTTP_2);
         final ByteBuffer data = inBuf != null ? inBuf.data() : null;
         startProtocol(new ClientH2IOEventHandler(http2StreamHandlerFactory.create(ioSession)), data);
         if (inBuf != null) {
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/H2OnlyClientProtocolNegotiator.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/H2OnlyClientProtocolNegotiator.java
index 388e034..cf1901e 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/H2OnlyClientProtocolNegotiator.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/H2OnlyClientProtocolNegotiator.java
@@ -34,6 +34,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.hc.core5.annotation.Internal;
 import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.impl.nio.BufferedData;
 import org.apache.hc.core5.http2.ssl.ApplicationProtocol;
 import org.apache.hc.core5.reactor.IOSession;
@@ -104,9 +105,9 @@ public class H2OnlyClientProtocolNegotiator extends ProtocolNegotiatorBase {
         }
         if (!preface.hasRemaining()) {
             session.clearEvent(SelectionKey.OP_WRITE);
-            final ClientH2StreamMultiplexer streamMultiplexer = http2StreamHandlerFactory.create(ioSession);
+            setNegotiatedProtocol(HttpVersion.HTTP_2);
             final ByteBuffer data = inBuf != null ? inBuf.data() : null;
-            startProtocol(new ClientH2IOEventHandler(streamMultiplexer), data);
+            startProtocol(new ClientH2IOEventHandler(http2StreamHandlerFactory.create(ioSession)), data);
             if (inBuf != null) {
                 inBuf.clear();
             }
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/H2OnlyServerHttpProtocolNegotiator.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/H2OnlyServerHttpProtocolNegotiator.java
index a770f01..78f3b0a 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/H2OnlyServerHttpProtocolNegotiator.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/H2OnlyServerHttpProtocolNegotiator.java
@@ -33,6 +33,7 @@ import java.nio.ByteBuffer;
 import org.apache.hc.core5.annotation.Internal;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.http.ConnectionClosedException;
+import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.impl.nio.BufferedData;
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.ProtocolIOSession;
@@ -90,6 +91,7 @@ public class H2OnlyServerHttpProtocolNegotiator extends ProtocolNegotiatorBase {
                     throw new ProtocolNegotiationException("Unexpected HTTP/2 preface");
                 }
             }
+            setNegotiatedProtocol(HttpVersion.HTTP_2);
             startProtocol(new ServerH2IOEventHandler(http2StreamHandlerFactory.create(ioSession)), data.hasRemaining() ? data : null);
         } else {
             if (endOfStream) {
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ProtocolNegotiatorBase.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ProtocolNegotiatorBase.java
index 89e787c..c56f952 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ProtocolNegotiatorBase.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ProtocolNegotiatorBase.java
@@ -55,6 +55,7 @@ abstract class ProtocolNegotiatorBase implements HttpConnectionEventHandler {
     private final AtomicReference<HttpConnectionEventHandler> protocolHandlerRef;
     private final FutureCallback<ProtocolIOSession> resultCallback;
     private final AtomicBoolean completed;
+    private final AtomicReference<ProtocolVersion> negotiatedProtocolRef;
 
     ProtocolNegotiatorBase(
             final ProtocolIOSession ioSession,
@@ -63,6 +64,7 @@ abstract class ProtocolNegotiatorBase implements HttpConnectionEventHandler {
         this.protocolHandlerRef = new AtomicReference<>();
         this.resultCallback = resultCallback;
         this.completed = new AtomicBoolean();
+        this.negotiatedProtocolRef = new AtomicReference<>();
     }
 
     void startProtocol(final HttpConnectionEventHandler protocolHandler, final ByteBuffer data) throws IOException {
@@ -77,6 +79,10 @@ abstract class ProtocolNegotiatorBase implements HttpConnectionEventHandler {
         }
     }
 
+    void setNegotiatedProtocol(final ProtocolVersion protocolVersion) {
+        negotiatedProtocolRef.set(protocolVersion);
+    }
+
     @Override
     public void timeout(final IOSession session, final Timeout timeout) {
         exception(session, SocketTimeoutExceptionFactory.create(timeout));
@@ -138,7 +144,7 @@ abstract class ProtocolNegotiatorBase implements HttpConnectionEventHandler {
 
     @Override
     public ProtocolVersion getProtocolVersion() {
-        return null;
+        return negotiatedProtocolRef.get();
     }
 
     @Override
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
index f6febff..6ab3a02 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
@@ -34,10 +34,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.hc.core5.annotation.Internal;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.http.ConnectionClosedException;
+import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.URIScheme;
 import org.apache.hc.core5.http.impl.nio.BufferedData;
 import org.apache.hc.core5.http.impl.nio.ServerHttp1IOEventHandler;
-import org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexer;
 import org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexerFactory;
 import org.apache.hc.core5.http2.HttpVersionPolicy;
 import org.apache.hc.core5.http2.ssl.ApplicationProtocol;
@@ -92,14 +92,15 @@ public class ServerHttpProtocolNegotiator extends ProtocolNegotiatorBase {
     }
 
     private void startHttp1(final TlsDetails tlsDetails, final ByteBuffer data) throws IOException {
-        final ServerHttp1StreamDuplexer http1StreamHandler = http1StreamHandlerFactory.create(
+        setNegotiatedProtocol(HttpVersion.HTTP_1_1);
+        startProtocol(new ServerHttp1IOEventHandler(http1StreamHandlerFactory.create(
                 tlsDetails != null ? URIScheme.HTTPS.id : URIScheme.HTTP.id,
-                ioSession);
-        startProtocol(new ServerHttp1IOEventHandler(http1StreamHandler), data);
+                ioSession)), data);
         ioSession.registerProtocol(ApplicationProtocol.HTTP_2.id, new ServerH2UpgradeHandler(http2StreamHandlerFactory));
     }
 
     private void startHttp2(final ByteBuffer data) throws IOException {
+        setNegotiatedProtocol(HttpVersion.HTTP_2);
         startProtocol(new ServerH2IOEventHandler(http2StreamHandlerFactory.create(ioSession)), data);
     }