Skip to content

Commit 5228923

Browse files
authored
Ensure the HTTP/2 upgrade stream inherits the proper state from the original HTTP/1.1 connection when successful upgrade from HTTP/1.1 to HTTP/2 (#3838)
Signed-off-by: Violeta Georgieva <696661+violetagg@users.noreply.github.com>
1 parent a60f640 commit 5228923

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

reactor-netty-http/src/main/java/reactor/netty/http/client/Http2ConnectionProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ public void operationComplete(Future<Http2StreamChannel> future) {
437437
setChannelContext(ch, currentContext());
438438
}
439439
HttpClientConfig.addStreamHandlers(ch, obs.then(new HttpClientConfig.StreamConnectionObserver(currentContext())),
440-
opsFactory, acceptGzip, metricsRecorder, proxyAddress, remoteAddress, -1, uriTagValue);
440+
opsFactory, acceptGzip, false, metricsRecorder, proxyAddress, remoteAddress, -1, uriTagValue);
441441

442442
if (log.isDebugEnabled()) {
443443
logStreamsState(ch, http2PooledRef.slot, "Stream opened");

reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientConfig.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ static void addStreamHandlers(
600600
ConnectionObserver obs,
601601
ChannelOperations.OnSetup opsFactory,
602602
boolean acceptGzip,
603+
boolean copyState,
603604
@Nullable ChannelMetricsRecorder metricsRecorder,
604605
@Nullable SocketAddress proxyAddress,
605606
SocketAddress remoteAddress,
@@ -677,6 +678,9 @@ else if (metricsRecorder instanceof ContextAwareHttpClientMetricsRecorder) {
677678
ChannelOperations<?, ?> ops = opsFactory.create(Connection.from(ch), obs, null);
678679
if (ops != null) {
679680
ops.bind();
681+
if (copyState && ops instanceof HttpClientOperations) {
682+
HttpClientOperations.copyState(((HttpClientOperations) ops));
683+
}
680684
}
681685
}
682686

@@ -979,7 +983,7 @@ protected void initChannel(Channel ch) {
979983
setChannelContext(ch, owner.currentContext());
980984
}
981985
addStreamHandlers(ch, observer.then(new StreamConnectionObserver(owner.currentContext())), opsFactory,
982-
acceptGzip, metricsRecorder, proxyAddress, remoteAddress, responseTimeoutMillis, uriTagValue);
986+
acceptGzip, true, metricsRecorder, proxyAddress, remoteAddress, responseTimeoutMillis, uriTagValue);
983987
if (log.isDebugEnabled()) {
984988
logStreamsState(ch, http2PooledRef(owner.pooledRef).slot, "Stream opened");
985989
}

reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientOperations.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,19 @@ final void withWebsocketSupport(WebsocketClientSpec websocketClientSpec) {
951951
}
952952
}
953953

954+
static void copyState(HttpClientOperations streamOps) {
955+
ChannelOperations<?, ?> ops = ChannelOperations.get(streamOps.channel().parent());
956+
if (ops instanceof HttpClientOperations) {
957+
HttpClientOperations parentOps = (HttpClientOperations) ops;
958+
if (parentOps.hasSentBody()) {
959+
streamOps.markSentHeaderAndBody();
960+
}
961+
else if (parentOps.hasSentHeaders()) {
962+
streamOps.markSentHeaders();
963+
}
964+
}
965+
}
966+
954967
static Throwable addOutboundErrorCause(Throwable exception, @Nullable Throwable cause) {
955968
if (cause != null) {
956969
cause.setStackTrace(new StackTraceElement[0]);

0 commit comments

Comments
 (0)