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 2018/03/12 18:15:04 UTC

[1/2] httpcomponents-core git commit: Bugfix: fixed NPE caused by null timeout attribute of IOSessionRequest

Repository: httpcomponents-core
Updated Branches:
  refs/heads/master 3b782accc -> 161f92baf


Bugfix: fixed NPE caused by null timeout attribute of IOSessionRequest


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/161f92ba
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/161f92ba
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/161f92ba

Branch: refs/heads/master
Commit: 161f92bafcfbcd6179983426436e615b36446d79
Parents: 45f4ec7
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Mon Mar 12 18:56:03 2018 +0100
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Mon Mar 12 19:05:55 2018 +0100

----------------------------------------------------------------------
 .../java/org/apache/hc/core5/reactor/InternalConnectChannel.java  | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/161f92ba/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalConnectChannel.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalConnectChannel.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalConnectChannel.java
index 2b82c8d..acf929d 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalConnectChannel.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalConnectChannel.java
@@ -33,6 +33,7 @@ import java.nio.channels.SelectionKey;
 import java.nio.channels.SocketChannel;
 
 import org.apache.hc.core5.io.ShutdownType;
+import org.apache.hc.core5.util.TimeValue;
 
 final class InternalConnectChannel extends InternalChannel {
 
@@ -78,7 +79,7 @@ final class InternalConnectChannel extends InternalChannel {
 
     @Override
     int getTimeout() {
-        return sessionRequest.timeout.toMillisIntBound();
+        return TimeValue.defaultsToZeroMillis(sessionRequest.timeout).toMillisIntBound();
     }
 
     @Override


[2/2] httpcomponents-core git commit: Bugfix: fixed incorrect propagation of exception cause in case of an HTTP protocol violation during HTTP protocol version negotiation

Posted by ol...@apache.org.
Bugfix: fixed incorrect propagation of exception cause in case of an HTTP protocol violation during HTTP protocol version negotiation


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/45f4ec7d
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/45f4ec7d
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/45f4ec7d

Branch: refs/heads/master
Commit: 45f4ec7d5aff9e8c64cdd3c68603cb4f248852bb
Parents: 3b782ac
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Mon Mar 12 18:46:18 2018 +0100
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Mon Mar 12 19:05:55 2018 +0100

----------------------------------------------------------------------
 .../impl/nio/ClientHttpProtocolNegotiator.java  | 95 +++++++++++---------
 1 file changed, 53 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/45f4ec7d/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
----------------------------------------------------------------------
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 180e26a..61ca1f4 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
@@ -86,65 +86,76 @@ public class ClientHttpProtocolNegotiator implements HttpConnectionEventHandler
         this.versionPolicy = versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE;
     }
 
-    @Override
-    public void connected(final IOSession session) {
+    private void startHttp1(final IOSession session) {
+        final ClientHttp1StreamDuplexer http1StreamHandler = http1StreamHandlerFactory.create(ioSession);
+        final ClientHttp1IOEventHandler newHandler = new ClientHttp1IOEventHandler(http1StreamHandler);
         try {
-            switch (versionPolicy) {
-                case NEGOTIATE:
-                    final TlsDetails tlsDetails = ioSession.getTlsDetails();
-                    if (tlsDetails != null) {
-                        if (ApplicationProtocols.HTTP_2.id.equals(tlsDetails.getApplicationProtocol())) {
-                            // Proceed with the H2 preface
-                            preface = ByteBuffer.wrap(PREFACE);
-                        }
-                    }
-                    break;
-                case FORCE_HTTP_2:
-                    preface = ByteBuffer.wrap(PREFACE);
-                    break;
-            }
-            if (preface == null) {
-                final ClientHttp1StreamDuplexer http1StreamHandler = http1StreamHandlerFactory.create(ioSession);
-                ioSession.upgrade(new ClientHttp1IOEventHandler(http1StreamHandler));
-                http1StreamHandler.onConnect(null);
-            } else {
-                writePreface(session);
-            }
+            ioSession.upgrade(newHandler);
+            newHandler.connected(session);
         } catch (final Exception ex) {
+            newHandler.exception(session, ex);
             session.shutdown(ShutdownType.IMMEDIATE);
-            exception(session, ex);
         }
     }
 
-    private void writePreface(final IOSession session) throws IOException  {
-        if (preface.hasRemaining()) {
-            final ByteChannel channel = session.channel();
-            channel.write(preface);
-        }
-        if (!preface.hasRemaining()) {
-            final ClientHttp2StreamMultiplexer streamMultiplexer = http2StreamHandlerFactory.create(ioSession);
-            final IOEventHandler newHandler = new ClientHttp2IOEventHandler(streamMultiplexer);
-            newHandler.connected(session);
+    private void startHttp2(final IOSession session) {
+        final ClientHttp2StreamMultiplexer streamMultiplexer = http2StreamHandlerFactory.create(ioSession);
+        final IOEventHandler newHandler = new ClientHttp2IOEventHandler(streamMultiplexer);
+        try {
             ioSession.upgrade(newHandler);
+            newHandler.connected(session);
+        } catch (final Exception ex) {
+            newHandler.exception(session, ex);
+            session.shutdown(ShutdownType.IMMEDIATE);
         }
     }
 
     @Override
-    public void inputReady(final IOSession session) {
+    public void connected(final IOSession session) throws IOException {
+        switch (versionPolicy) {
+            case NEGOTIATE:
+                final TlsDetails tlsDetails = ioSession.getTlsDetails();
+                if (tlsDetails != null) {
+                    if (ApplicationProtocols.HTTP_2.id.equals(tlsDetails.getApplicationProtocol())) {
+                        // Proceed with the H2 preface
+                        preface = ByteBuffer.wrap(PREFACE);
+                    }
+                }
+                break;
+            case FORCE_HTTP_2:
+                preface = ByteBuffer.wrap(PREFACE);
+                break;
+        }
+        if (preface == null) {
+            startHttp1(session);
+        } else {
+            if (preface.hasRemaining()) {
+                final ByteChannel channel = session.channel();
+                channel.write(preface);
+            }
+            if (!preface.hasRemaining()) {
+                startHttp2(session);
+            }
+        }
+    }
+
+    @Override
+    public void inputReady(final IOSession session)throws IOException  {
         outputReady(session);
     }
 
     @Override
-    public void outputReady(final IOSession session) {
-        try {
-            if (preface != null) {
-                writePreface(session);
-            } else {
-                session.shutdown(ShutdownType.IMMEDIATE);
+    public void outputReady(final IOSession session) throws IOException {
+        if (preface != null) {
+            if (preface.hasRemaining()) {
+                final ByteChannel channel = session.channel();
+                channel.write(preface);
+            }
+            if (!preface.hasRemaining()) {
+                startHttp2(session);
             }
-        } catch (final IOException ex) {
+        } else {
             session.shutdown(ShutdownType.IMMEDIATE);
-            exception(session, ex);
         }
     }