@Override protected ChannelFuture doWriteData(int id, int streamId, HttpData data, boolean endStream) { if (isStreamPresentAndWritable(streamId)) { // Write to an existing stream. return encoder.writeData(ctx, streamId, toByteBuf(data), 0, endStream, ctx.newPromise()); } if (encoder.connection().local().mayHaveCreatedStream(streamId)) { // Can't write to an outdated (closed) stream. ReferenceCountUtil.safeRelease(data); return data.isEmpty() ? ctx.writeAndFlush(Unpooled.EMPTY_BUFFER) : newFailedFuture(ClosedPublisherException.get()); } // Cannot start a new stream with a DATA frame. It must start with a HEADERS frame. ReferenceCountUtil.safeRelease(data); return newFailedFuture(new IllegalStateException( "cannot start a new stream " + streamId + " with a DATA frame")); }
stream = connection.local().createStream(streamId, endOfStream); } catch (Http2Exception cause) { if (connection.remote().mayHaveCreatedStream(streamId)) { promise.tryFailure(new IllegalStateException("Stream no longer exists: " + streamId, cause)); return promise;
stream = connection.local().createStream(streamId, endOfStream); } catch (Http2Exception cause) { if (connection.remote().mayHaveCreatedStream(streamId)) { promise.tryFailure(new IllegalStateException("Stream no longer exists: " + streamId, cause)); return promise;
if (connection.remote().mayHaveCreatedStream(streamId)) { promise.tryFailure(new IllegalStateException("Stream no longer exists: " + streamId, cause)); return promise;
if (!outbound || connection().local().mayHaveCreatedStream(streamId)) { resetUnknownStream(ctx, streamId, http2Ex.error().code(), ctx.newPromise());
if (!outbound || connection().local().mayHaveCreatedStream(streamId)) { resetUnknownStream(ctx, streamId, http2Ex.error().code(), ctx.newPromise());
@Override protected ChannelFuture doWriteHeaders(int id, int streamId, HttpHeaders headers, boolean endStream) { final Http2Connection conn = encoder.connection(); final boolean server = conn.isServer(); if (isStreamPresentAndWritable(streamId)) { // Writing to an existing stream. return encoder.writeHeaders(ctx, streamId, ArmeriaHttpUtil.toNettyHttp2(headers, server), 0, endStream, ctx.newPromise()); } if (server) { // One of the following cases: // - Stream has been closed already. // - (bug) Server tried to send a response HEADERS frame before receiving a request HEADERS frame. return newFailedFuture(ClosedPublisherException.get()); } if (conn.local().mayHaveCreatedStream(streamId)) { // Stream has been closed. return newFailedFuture(ClosedPublisherException.get()); } // Client starts a new stream. return encoder.writeHeaders( ctx, streamId, ArmeriaHttpUtil.toNettyHttp2(headers, server), 0, endStream, ctx.newPromise()); }