8282import org .apache .hc .core5 .http2 .impl .BasicH2TransportMetrics ;
8383import org .apache .hc .core5 .http2 .nio .AsyncPingHandler ;
8484import org .apache .hc .core5 .http2 .nio .command .PingCommand ;
85+ import org .apache .hc .core5 .http2 .nio .command .PushResponseCommand ;
8586import org .apache .hc .core5 .io .CloseMode ;
8687import org .apache .hc .core5 .reactor .Command ;
8788import org .apache .hc .core5 .reactor .ProtocolIOSession ;
@@ -499,7 +500,7 @@ public final void onOutput() throws HttpException, IOException {
499500 }
500501
501502 if (connState .compareTo (ConnectionHandshake .ACTIVE ) <= 0 && remoteSettingState == SettingsHandshake .ACKED ) {
502- while (streams .size () < remoteConfig .getMaxConcurrentStreams ()) {
503+ while (streams .getLocalCount () < remoteConfig .getMaxConcurrentStreams ()) {
503504 final Command command = ioSession .poll ();
504505 if (command == null ) {
505506 break ;
@@ -510,6 +511,8 @@ public final void onOutput() throws HttpException, IOException {
510511 executePing ((PingCommand ) command );
511512 } else if (command instanceof RequestExecutionCommand ) {
512513 executeRequest ((RequestExecutionCommand ) command );
514+ } else if (command instanceof PushResponseCommand ) {
515+ executePush ((PushResponseCommand ) command );
513516 }
514517 if (!outputQueue .isEmpty ()) {
515518 return ;
@@ -638,6 +641,23 @@ private void executeRequest(final RequestExecutionCommand requestExecutionComman
638641 }
639642 }
640643
644+ private void executePush (final PushResponseCommand pushResponseCommand ) throws IOException , HttpException {
645+ if (pushResponseCommand .isCancelled ()) {
646+ return ;
647+ }
648+ final H2Stream stream = streams .lookupSeen (pushResponseCommand .getStreamId ());
649+ if (stream != null && stream .isReserved ()) {
650+ if (!stream .isLocalClosed ()) {
651+ stream .activate ();
652+ if (stream .isOutputReady ()) {
653+ stream .produceOutput ();
654+ }
655+ } else {
656+ stream .abort ();
657+ }
658+ }
659+ }
660+
641661 public final void onException (final Exception cause ) {
642662 try {
643663 for (;;) {
@@ -812,7 +832,7 @@ private void consumeFrame(final RawFrame frame) throws HttpException, IOExceptio
812832 if (streamId == 0 ) {
813833 throw new H2ConnectionException (H2Error .PROTOCOL_ERROR , "Illegal stream id: " + streamId );
814834 }
815- final H2Stream stream = streams .lookupValidOrNull (streamId );
835+ final H2Stream stream = streams .lookupSeen (streamId );
816836 if (stream != null ) {
817837 final ByteBuffer payload = frame .getPayload ();
818838 if (payload == null || payload .remaining () != 4 ) {
@@ -1247,7 +1267,8 @@ void appendState(final StringBuilder buf) {
12471267 .append (", connInputWindow=" ).append (connInputWindow )
12481268 .append (", connOutputWindow=" ).append (connOutputWindow )
12491269 .append (", outputQueue=" ).append (outputQueue .size ())
1250- .append (", streams.size=" ).append (streams .size ())
1270+ .append (", streams.localCoubt=" ).append (streams .getLocalCount ())
1271+ .append (", streams.remoteCount=" ).append (streams .getRemoteCount ())
12511272 .append (", streams.lastLocal=" ).append (streams .getLastLocalId ())
12521273 .append (", streams.lastRemote=" ).append (streams .getLastRemoteId ());
12531274 }
@@ -1362,9 +1383,11 @@ public void push(final List<Header> headers, final AsyncPushProducer pushProduce
13621383 ensureNotClosed ();
13631384 final int promisedStreamId = streams .generateStreamId ();
13641385 final H2StreamChannel channel = createChannel (promisedStreamId );
1365- streams .createReserved (channel , outgoingPushPromise (channel , pushProducer ));
1386+ final H2Stream stream = streams .createReserved (channel , outgoingPushPromise (channel , pushProducer ));
13661387
13671388 commitPushPromise (id , promisedStreamId , headers );
1389+ stream .markRemoteClosed ();
1390+ submitCommand (new PushResponseCommand (promisedStreamId ));
13681391 } finally {
13691392 ioSession .getLock ().unlock ();
13701393 }
0 commit comments