Java Code Examples for software.amazon.awssdk.http.Protocol#HTTP2

The following examples show how to use software.amazon.awssdk.http.Protocol#HTTP2 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestAdapter.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * Configures the headers in the specified Netty HTTP request.
 */
private void addHeadersToRequest(DefaultHttpRequest httpRequest, SdkHttpRequest request) {
    httpRequest.headers().add(HOST, getHostHeaderValue(request));

    String scheme = request.getUri().getScheme();
    if (Protocol.HTTP2 == protocol && !StringUtils.isBlank(scheme)) {
        httpRequest.headers().add(ExtensionHeaderNames.SCHEME.text(), scheme);
    }

    // Copy over any other headers already in our request
    request.headers().entrySet().stream()
            /*
             * Skip the Host header to avoid sending it twice, which will
             * interfere with some signing schemes.
             */
            .filter(e -> !IGNORE_HEADERS.contains(e.getKey()))
            .forEach(e -> e.getValue().forEach(h -> httpRequest.headers().add(e.getKey(), h)));
}
 
Example 2
Source File: Http2PingHandler.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private void start(Protocol protocol, ChannelHandlerContext ctx) {
    if (protocol == Protocol.HTTP2 && periodicPing == null) {
        periodicPing = ctx.channel()
                          .eventLoop()
                          .scheduleAtFixedRate(() -> doPeriodicPing(ctx.channel()), 0, pingTimeoutMillis, MILLISECONDS);
    }
}
 
Example 3
Source File: ChannelPipelineInitializer.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public void channelCreated(Channel ch) {
    ch.attr(PROTOCOL_FUTURE).set(new CompletableFuture<>());
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {

        // Need to provide host and port to enable SNI
        // https://github.com/netty/netty/issues/3801#issuecomment-104274440
        SslHandler sslHandler = sslCtx.newHandler(ch.alloc(), poolKey.getHost(), poolKey.getPort());
        configureSslEngine(sslHandler.engine());

        pipeline.addLast(sslHandler);
        pipeline.addLast(SslCloseCompletionEventHandler.getInstance());

        // Use unpooled allocator to avoid increased heap memory usage from Netty 4.1.43.
        // See https://github.com/netty/netty/issues/9768
        if (sslProvider == SslProvider.JDK) {
            ch.config().setOption(ChannelOption.ALLOCATOR, UnpooledByteBufAllocator.DEFAULT);
        }
    }

    if (protocol == Protocol.HTTP2) {
        configureHttp2(ch, pipeline);
    } else {
        configureHttp11(ch, pipeline);
    }

    if (configuration.reapIdleConnections()) {
        pipeline.addLast(new IdleConnectionReaperHandler(configuration.idleTimeoutMillis()));
    }

    if (configuration.connectionTtlMillis() > 0) {
        pipeline.addLast(new OldConnectionReaperHandler(configuration.connectionTtlMillis()));
    }

    pipeline.addLast(FutureCancelHandler.getInstance());

    // Only add it for h1 channel because it does not apply to
    // h2 connection channel. It will be attached
    // to stream channels when they are created.
    if (protocol == Protocol.HTTP1_1) {
        pipeline.addLast(UnusedChannelExceptionHandler.getInstance());
    }

    pipeline.addLast(new LoggingHandler(LogLevel.DEBUG));
}