@Override public void createStream(Handler<AsyncResult<HttpClientStream>> completionHandler) { Future<HttpClientStream> fut; synchronized (this) { Http2Connection conn = handler.connection(); try { int id = conn.local().lastStreamCreated() == 0 ? 1 : conn.local().lastStreamCreated() + 2; Http2ClientStream stream = createStream(conn.local().createStream(id, false)); fut = Future.succeededFuture(stream); } catch (Exception e) { fut = Future.failedFuture(e); } } completionHandler.handle(fut); }
if (stream == null) { try { stream = connection.local().createStream(streamId, endOfStream); } catch (Http2Exception cause) { if (connection.remote().mayHaveCreatedStream(streamId)) {
static void handle(ChannelHandlerContext ctx, Http2Connection connection, Http2FrameListener listener, FullHttpMessage message) throws Http2Exception { try { int streamId = getStreamId(connection, message.headers()); Http2Stream stream = connection.stream(streamId); if (stream == null) { stream = connection.remote().createStream(streamId, false); } message.headers().set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), HttpScheme.HTTP.name()); Http2Headers messageHeaders = HttpConversionUtil.toHttp2Headers(message, true); boolean hasContent = message.content().isReadable(); boolean hasTrailers = !message.trailingHeaders().isEmpty(); listener.onHeadersRead( ctx, streamId, messageHeaders, 0, !(hasContent || hasTrailers)); if (hasContent) { listener.onDataRead(ctx, streamId, message.content(), 0, !hasTrailers); } if (hasTrailers) { Http2Headers headers = HttpConversionUtil.toHttp2Headers(message.trailingHeaders(), true); listener.onHeadersRead(ctx, streamId, headers, 0, true); } stream.closeRemoteSide(); } finally { message.release(); } } }
boolean allowHalfClosedRemote = false; if (stream == null && !connection.streamMayHaveExisted(streamId)) { stream = connection.remote().createStream(streamId, endOfStream);
stream = encoder.connection().remote().createStream(streamId, true); } catch (Http2Exception e) { resetUnknownStream(ctx, streamId, http2Ex.error().code(), ctx.newPromise());
stream = encoder.connection().remote().createStream(streamId, true); } catch (Http2Exception e) { resetUnknownStream(ctx, streamId, http2Ex.error().code(), ctx.newPromise());
boolean allowHalfClosedRemote = false; if (stream == null && !connection.streamMayHaveExisted(streamId)) { stream = connection.remote().createStream(streamId, endOfStream);
static void handle(ChannelHandlerContext ctx, Http2Connection connection, Http2FrameListener listener, FullHttpMessage message) throws Http2Exception { try { int streamId = getStreamId(connection, message.headers()); Http2Stream stream = connection.stream(streamId); if (stream == null) { stream = connection.remote().createStream(streamId, false); } message.headers().set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), HttpScheme.HTTP.name()); Http2Headers messageHeaders = HttpConversionUtil.toHttp2Headers(message, true); boolean hasContent = message.content().isReadable(); boolean hasTrailers = !message.trailingHeaders().isEmpty(); listener.onHeadersRead( ctx, streamId, messageHeaders, 0, !(hasContent || hasTrailers)); if (hasContent) { listener.onDataRead(ctx, streamId, message.content(), 0, !hasTrailers); } if (hasTrailers) { Http2Headers headers = HttpConversionUtil.toHttp2Headers(message.trailingHeaders(), true); listener.onHeadersRead(ctx, streamId, headers, 0, true); } stream.closeRemoteSide(); } finally { message.release(); } } }
static void handle(ChannelHandlerContext ctx, Http2Connection connection, Http2FrameListener listener, FullHttpMessage message) throws Http2Exception { try { int streamId = getStreamId(connection, message.headers()); Http2Stream stream = connection.stream(streamId); if (stream == null) { stream = connection.remote().createStream(streamId, false); } message.headers().set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), HttpScheme.HTTP.name()); Http2Headers messageHeaders = HttpConversionUtil.toHttp2Headers(message, true); boolean hasContent = message.content().isReadable(); boolean hasTrailers = !message.trailingHeaders().isEmpty(); listener.onHeadersRead( ctx, streamId, messageHeaders, 0, !(hasContent || hasTrailers)); if (hasContent) { listener.onDataRead(ctx, streamId, message.content(), 0, !hasTrailers); } if (hasTrailers) { Http2Headers headers = HttpConversionUtil.toHttp2Headers(message.trailingHeaders(), true); listener.onHeadersRead(ctx, streamId, headers, 0, true); } stream.closeRemoteSide(); } finally { message.release(); } } }
/** * Handles the server-side (cleartext) upgrade from HTTP to HTTP/2. * @param settings the settings for the remote endpoint. */ public void onHttpServerUpgrade(Http2Settings settings) throws Http2Exception { if (!connection().isServer()) { throw connectionError(PROTOCOL_ERROR, "Server-side HTTP upgrade requested for a client"); } if (!prefaceSent()) { // If the preface was not sent yet it most likely means the handler was not added to the pipeline before // calling this method. throw connectionError(INTERNAL_ERROR, "HTTP upgrade must occur after preface was sent"); } if (decoder.prefaceReceived()) { throw connectionError(PROTOCOL_ERROR, "HTTP upgrade must occur before HTTP/2 preface is received"); } // Apply the settings but no ACK is necessary. encoder.remoteSettings(settings); // Create a stream in the half-closed state. connection().remote().createStream(HTTP_UPGRADE_STREAM_ID, true); }
@Override public CompletableFuture<StreamWriteOperation> writeHeaders(Http2Headers headers, boolean endStream, Http2StreamListener http2StreamListener) { return doInEventLoop((cf, channelPromise) -> { log.debug("write headers {}", headers); int streamId = http2Connection.local().incrementAndGetNextStreamId(); Http2Stream stream = http2Connection.stream(streamId); if (stream == null) { try { stream = http2Connection.local().createStream(streamId, false); } catch (Http2Exception e) { throw new IotClientException(e); } } if (http2StreamListener != null) { setStreamListener(stream, http2StreamListener); } cf.setResult(new StreamWriteOperation(stream, this)); encoder.writeHeaders(ctx, streamId, headers, 0, endStream, channelPromise); ctx.pipeline().flush(); }); }
/** * Handles the server-side (cleartext) upgrade from HTTP to HTTP/2. * @param settings the settings for the remote endpoint. */ public void onHttpServerUpgrade(Http2Settings settings) throws Http2Exception { if (!connection().isServer()) { throw connectionError(PROTOCOL_ERROR, "Server-side HTTP upgrade requested for a client"); } if (!prefaceSent()) { // If the preface was not sent yet it most likely means the handler was not added to the pipeline before // calling this method. throw connectionError(INTERNAL_ERROR, "HTTP upgrade must occur after preface was sent"); } if (decoder.prefaceReceived()) { throw connectionError(PROTOCOL_ERROR, "HTTP upgrade must occur before HTTP/2 preface is received"); } // Apply the settings but no ACK is necessary. encoder.remoteSettings(settings); // Create a stream in the half-closed state. connection().remote().createStream(HTTP_UPGRADE_STREAM_ID, true); }
/** * Handles the client-side (cleartext) upgrade from HTTP to HTTP/2. * Reserves local stream 1 for the HTTP/2 response. */ public void onHttpClientUpgrade() throws Http2Exception { if (connection().isServer()) { throw connectionError(PROTOCOL_ERROR, "Client-side HTTP upgrade requested for a server"); } if (!prefaceSent()) { // If the preface was not sent yet it most likely means the handler was not added to the pipeline before // calling this method. throw connectionError(INTERNAL_ERROR, "HTTP upgrade must occur after preface was sent"); } if (decoder.prefaceReceived()) { throw connectionError(PROTOCOL_ERROR, "HTTP upgrade must occur before HTTP/2 preface is received"); } // Create a local stream used for the HTTP cleartext upgrade. connection().local().createStream(HTTP_UPGRADE_STREAM_ID, true); }
/** * Handles the client-side (cleartext) upgrade from HTTP to HTTP/2. * Reserves local stream 1 for the HTTP/2 response. */ public void onHttpClientUpgrade() throws Http2Exception { if (connection().isServer()) { throw connectionError(PROTOCOL_ERROR, "Client-side HTTP upgrade requested for a server"); } if (!prefaceSent()) { // If the preface was not sent yet it most likely means the handler was not added to the pipeline before // calling this method. throw connectionError(INTERNAL_ERROR, "HTTP upgrade must occur after preface was sent"); } if (decoder.prefaceReceived()) { throw connectionError(PROTOCOL_ERROR, "HTTP upgrade must occur before HTTP/2 preface is received"); } // Create a local stream used for the HTTP cleartext upgrade. connection().local().createStream(HTTP_UPGRADE_STREAM_ID, true); }
/** * Creates a stream with given stream id. * * @param conn the HTTP2 connection * @param streamId the id of the stream * @throws Http2Exception if a protocol-related error occurred */ private static synchronized void createStream(Http2Connection conn, int streamId) throws Http2Exception { conn.local().createStream(streamId, false); if (LOG.isDebugEnabled()) { LOG.debug("Stream created streamId: {}", streamId); } }
@Override public void createStream(Handler<AsyncResult<HttpClientStream>> completionHandler) { Future<HttpClientStream> fut; synchronized (this) { Http2Connection conn = handler.connection(); try { int id = conn.local().lastStreamCreated() == 0 ? 1 : conn.local().lastStreamCreated() + 2; Http2ClientStream stream = createStream(conn.local().createStream(id, false)); fut = Future.succeededFuture(stream); } catch (Exception e) { fut = Future.failedFuture(e); } } completionHandler.handle(fut); }
stream = encoder.connection().remote().createStream(streamId, true); } catch (Http2Exception e) { resetUnknownStream(ctx, streamId, http2Ex.error().code(), ctx.newPromise());
boolean allowHalfClosedRemote = false; if (stream == null && !connection.streamMayHaveExisted(streamId)) { stream = connection.remote().createStream(streamId, endOfStream);
/** * Handles the server-side (cleartext) upgrade from HTTP to HTTP/2. * @param settings the settings for the remote endpoint. */ public void onHttpServerUpgrade(Http2Settings settings) throws Http2Exception { if (!connection().isServer()) { throw connectionError(PROTOCOL_ERROR, "Server-side HTTP upgrade requested for a client"); } if (!prefaceSent()) { // If the preface was not sent yet it most likely means the handler was not added to the pipeline before // calling this method. throw connectionError(INTERNAL_ERROR, "HTTP upgrade must occur after preface was sent"); } if (decoder.prefaceReceived()) { throw connectionError(PROTOCOL_ERROR, "HTTP upgrade must occur before HTTP/2 preface is received"); } // Apply the settings but no ACK is necessary. encoder.remoteSettings(settings); // Create a stream in the half-closed state. connection().remote().createStream(HTTP_UPGRADE_STREAM_ID, true); }
/** * Handles the client-side (cleartext) upgrade from HTTP to HTTP/2. * Reserves local stream 1 for the HTTP/2 response. */ public void onHttpClientUpgrade() throws Http2Exception { if (connection().isServer()) { throw connectionError(PROTOCOL_ERROR, "Client-side HTTP upgrade requested for a server"); } if (!prefaceSent()) { // If the preface was not sent yet it most likely means the handler was not added to the pipeline before // calling this method. throw connectionError(INTERNAL_ERROR, "HTTP upgrade must occur after preface was sent"); } if (decoder.prefaceReceived()) { throw connectionError(PROTOCOL_ERROR, "HTTP upgrade must occur before HTTP/2 preface is received"); } // Create a local stream used for the HTTP cleartext upgrade. connection().local().createStream(HTTP_UPGRADE_STREAM_ID, true); }