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
parent afbbc11c8f
commit 7e818352e2
2 changed files with 17 additions and 8 deletions

View File

@ -232,6 +232,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).
@ -430,14 +437,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) {