Move responsibility for creating upgrade stream to Http2FrameCodec (#9360)

Motivation:

The Http2FrameCodec should be responsible to create the upgrade stream.

Modifications:

Move code to create stream to Http2FrameCodec

Result:

More correct responsibility
This commit is contained in:
Norman Maurer 2019-07-16 13:24:45 +02:00 committed by GitHub
parent 1748352d98
commit 306299323c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 9 deletions

View File

@ -161,7 +161,7 @@ public class Http2FrameCodec extends Http2ConnectionHandler {
new IntObjectHashMap<DefaultHttp2FrameStream>(8);
private final ChannelFutureListener bufferedStreamsListener = new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
public void operationComplete(ChannelFuture future) {
numBufferedStreams--;
}
};
@ -240,6 +240,13 @@ public class Http2FrameCodec extends Http2ConnectionHandler {
// sub-class can override this for extra steps that needs to be done when the handler is added.
}
@Override
public void onHttpClientUpgrade() throws Http2Exception {
super.onHttpClientUpgrade();
// Now make a new Http2FrameStream, set it's underlying Http2Stream, and initialize it.
newStream().setStreamAndProperty(streamKey, connection().stream(HTTP_UPGRADE_STREAM_ID));
}
/**
* Handles the cleartext HTTP upgrade event. If an upgrade occurred, sends a simple response via
* HTTP/2 on stream 1 (the stream specifically reserved for cleartext HTTP upgrade).
@ -438,14 +445,15 @@ public class Http2FrameCodec extends Http2ConnectionHandler {
@Override
public void onStreamClosed(Http2Stream stream) {
Http2FrameStream stream2 = stream.getProperty(streamKey);
if (stream2 != null) {
onHttp2StreamStateChanged(ctx, stream2);
}
onHttp2StreamStateChanged0(stream);
}
@Override
public void onStreamHalfClosed(Http2Stream stream) {
onHttp2StreamStateChanged0(stream);
}
private void onHttp2StreamStateChanged0(Http2Stream stream) {
Http2FrameStream stream2 = stream.getProperty(streamKey);
if (stream2 != null) {
onHttp2StreamStateChanged(ctx, stream2);

View File

@ -116,10 +116,6 @@ public class Http2MultiplexCodec extends Http2FrameCodec {
}
// Creates the Http2Stream in the Connection.
super.onHttpClientUpgrade();
// Now make a new FrameStream, set it's underlying Http2Stream, and initialize it.
DefaultHttp2FrameStream codecStream = newStream();
codecStream.setStreamAndProperty(streamKey, connection().stream(HTTP_UPGRADE_STREAM_ID));
onHttp2UpgradeStreamInitialized(ctx, codecStream);
}
@Override
@ -174,6 +170,11 @@ public class Http2MultiplexCodec extends Http2FrameCodec {
DefaultHttp2FrameStream s = (DefaultHttp2FrameStream) stream;
switch (stream.state()) {
case HALF_CLOSED_LOCAL:
if (stream.id() == HTTP_UPGRADE_STREAM_ID) {
onHttp2UpgradeStreamInitialized(ctx, s);
}
break;
case HALF_CLOSED_REMOTE:
case OPEN:
if (s.attachment != null) {