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/06/23 12:07:31 UTC
[httpcomponents-core] branch 5.1.x updated: HTTPCLIENT-2222: fixed ProtocolNegotiationException
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch 5.1.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git
The following commit(s) were added to refs/heads/5.1.x by this push:
new 45afde3f9 HTTPCLIENT-2222: fixed ProtocolNegotiationException
45afde3f9 is described below
commit 45afde3f9a51fd9dc5ade04bf0e9649bd6eec267
Author: Gaojie Liu <go...@linkedin.com>
AuthorDate: Wed Jun 22 11:26:54 2022 -0700
HTTPCLIENT-2222: fixed ProtocolNegotiationException
Aligned with the implementation of the latest release to get rid of
ProtocolNegotiationException:
https://github.com/apache/httpcomponents-core/blob/rel/v5.2-beta2/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientH2PrefaceHandler.java#L142
---
.../core5/http2/impl/nio/H2OnlyClientProtocolNegotiator.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
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 9808bfbb8..367e24001 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
@@ -36,6 +36,7 @@ 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.ProtocolVersion;
+import org.apache.hc.core5.http.impl.nio.BufferedData;
import org.apache.hc.core5.http2.ssl.ApplicationProtocol;
import org.apache.hc.core5.reactor.IOSession;
import org.apache.hc.core5.reactor.ProtocolIOSession;
@@ -58,6 +59,7 @@ public class H2OnlyClientProtocolNegotiator extends ProtocolNegotiatorBase {
private final AtomicBoolean initialized;
private volatile ByteBuffer preface;
+ private volatile BufferedData inBuf;
public H2OnlyClientProtocolNegotiator(
final ProtocolIOSession ioSession,
@@ -104,7 +106,8 @@ public class H2OnlyClientProtocolNegotiator extends ProtocolNegotiatorBase {
}
if (!preface.hasRemaining()) {
session.clearEvent(SelectionKey.OP_WRITE);
- startProtocol(HttpVersion.HTTP_2, new ClientH2IOEventHandler(http2StreamHandlerFactory.create(ioSession)), null);
+ final ByteBuffer data = inBuf != null ? inBuf.data() : null;
+ startProtocol(HttpVersion.HTTP_2, new ClientH2IOEventHandler(http2StreamHandlerFactory.create(ioSession)), data);
preface = null;
}
}
@@ -131,7 +134,10 @@ public class H2OnlyClientProtocolNegotiator extends ProtocolNegotiatorBase {
@Override
public void inputReady(final IOSession session, final ByteBuffer src) throws IOException {
if (src != null) {
- throw new ProtocolNegotiationException("Unexpected input");
+ if (inBuf == null) {
+ inBuf = BufferedData.allocate(src.remaining());
+ }
+ inBuf.put(src);
}
if (preface != null) {
writeOutPreface(session);