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:05 UTC
[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
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);
}
}