/** * Extract sender configuration from transport configuration. * * @param transportsConfiguration {@link TransportsConfiguration} which sender configurations should be extracted. * @param scheme scheme of the transport. * @return extracted {@link SenderConfiguration}. */ public static SenderConfiguration getSenderConfiguration(TransportsConfiguration transportsConfiguration, String scheme) { Map<String, SenderConfiguration> senderConfigurations = transportsConfiguration.getSenderConfigurations().stream().collect(Collectors .toMap(senderConf -> senderConf.getScheme().toLowerCase(Locale.getDefault()), config -> config)); return Constants.HTTPS_SCHEME.equals(scheme) ? senderConfigurations.get(Constants.HTTPS_SCHEME) : senderConfigurations.get(Constants.HTTP_SCHEME); }
@Override public Object makeObject() throws Exception { Bootstrap clientBootstrap = instantiateAndConfigBootStrap(eventLoopGroup, eventLoopClass, bootstrapConfiguration); ConnectionAvailabilityFuture connectionAvailabilityFuture = new ConnectionAvailabilityFuture(); HttpClientChannelInitializer httpClientChannelInitializer = instantiateAndConfigClientInitializer( senderConfiguration, clientBootstrap, httpRoute, connectionManager, connectionAvailabilityFuture); clientBootstrap.handler(httpClientChannelInitializer); // Connect to proxy server if proxy is enabled ChannelFuture channelFuture; if (senderConfiguration.getProxyServerConfiguration() != null && senderConfiguration.getScheme() .equals(HTTP_SCHEME)) { channelFuture = clientBootstrap.connect(new InetSocketAddress( senderConfiguration.getProxyServerConfiguration().getProxyHost(), senderConfiguration.getProxyServerConfiguration().getProxyPort() )); } else { channelFuture = clientBootstrap.connect(new InetSocketAddress(httpRoute.getHost(), httpRoute.getPort())); } connectionAvailabilityFuture.setSocketAvailabilityFuture(channelFuture); connectionAvailabilityFuture.setForceHttp2(senderConfiguration.isForceHttp2()); TargetChannel targetChannel = new TargetChannel(httpClientChannelInitializer, channelFuture, httpRoute, connectionAvailabilityFuture); httpClientChannelInitializer.setHttp2ClientChannel(targetChannel.getHttp2ClientChannel()); LOG.debug("Created channel: {}", httpRoute); return targetChannel; }
private void handleOutboundConnectionHeader(KeepAliveConfig keepAliveConfig, HttpCarbonMessage httpOutboundRequest) { switch (keepAliveConfig) { case AUTO: if (Float.valueOf(httpVersion) >= Constants.HTTP_1_1) { httpOutboundRequest .setHeader(HttpHeaderNames.CONNECTION.toString(), Constants.CONNECTION_KEEP_ALIVE); } else { httpOutboundRequest.setHeader(HttpHeaderNames.CONNECTION.toString(), Constants.CONNECTION_CLOSE); } break; case ALWAYS: httpOutboundRequest.setHeader(HttpHeaderNames.CONNECTION.toString(), Constants.CONNECTION_KEEP_ALIVE); break; case NEVER: httpOutboundRequest.setHeader(HttpHeaderNames.CONNECTION.toString(), Constants.CONNECTION_CLOSE); break; default: //Do nothing break; } // Add proxy-authorization header if proxy is enabled and scheme is http if (senderConfiguration.getScheme().equals(HTTP_SCHEME) && senderConfiguration.getProxyServerConfiguration() != null && senderConfiguration.getProxyServerConfiguration().getProxyUsername() != null && senderConfiguration.getProxyServerConfiguration().getProxyPassword() != null) { setProxyAuthorizationHeader(httpOutboundRequest); } }
final HttpRoute route = getTargetRoute(senderConfiguration.getScheme(), httpOutboundRequest); if (isHttp2) {