List of usage examples for io.netty.handler.codec.http HttpClientUpgradeHandler HttpClientUpgradeHandler
public HttpClientUpgradeHandler(SourceCodec sourceCodec, UpgradeCodec upgradeCodec, int maxContentLength)
From source file:Http2ClientInitializer.java
License:Apache License
/** * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2. */// w w w . jav a 2 s . com private void configureClearText(SocketChannel ch) { HttpClientCodec sourceCodec = new HttpClientCodec(); Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec(connectionHandler); HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, 65536); ch.pipeline().addLast(sourceCodec); ch.pipeline().addLast(upgradeHandler); ch.pipeline().addLast(new UpgradeRequestHandler()); ch.pipeline().addLast(new UserEventLogger()); }
From source file:ccwihr.client.t2.Http2ClientInitializer.java
License:Apache License
/** * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2. */// ww w. j a v a 2s.c o m private void configureClearText(SocketChannel ch) { HttpClientCodec sourceCodec = new HttpClientCodec(); Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec(connectionHandler); HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, 65536); ch.pipeline().addLast(sourceCodec, upgradeHandler, new UpgradeRequestHandler(), new UserEventLogger()); }
From source file:com.linecorp.armeria.client.http.HttpClientPipelineConfigurator.java
License:Apache License
private void configureAsHttp(Channel ch) { final ChannelPipeline pipeline = ch.pipeline(); final boolean attemptUpgrade; switch (httpPreference) { case HTTP1_REQUIRED: attemptUpgrade = false;//from ww w . jav a 2s. co m break; case HTTP2_PREFERRED: attemptUpgrade = !SessionProtocolNegotiationCache.isUnsupported(remoteAddress, H2C); break; case HTTP2_REQUIRED: attemptUpgrade = true; break; default: // Should never reach here. throw new Error(); } if (attemptUpgrade) { final Http2ClientConnectionHandler http2Handler = newHttp2ConnectionHandler(ch); if (options.useHttp2Preface()) { pipeline.addLast(new DowngradeHandler()); pipeline.addLast(http2Handler); } else { Http1ClientCodec http1Codec = newHttp1Codec(); Http2ClientUpgradeCodec http2ClientUpgradeCodec = new Http2ClientUpgradeCodec(http2Handler); HttpClientUpgradeHandler http2UpgradeHandler = new HttpClientUpgradeHandler(http1Codec, http2ClientUpgradeCodec, (int) Math.min(Integer.MAX_VALUE, UPGRADE_RESPONSE_MAX_LENGTH)); pipeline.addLast(http1Codec); pipeline.addLast(new WorkaroundHandler()); pipeline.addLast(http2UpgradeHandler); pipeline.addLast(new UpgradeRequestHandler(http2Handler.responseDecoder())); } } else { pipeline.addLast(newHttp1Codec()); // NB: We do not call finishSuccessfully() immediately here // because it assumes HttpSessionHandler to be in the pipeline, // which is only true after the connection attempt is successful. pipeline.addLast(new ChannelInboundHandlerAdapter() { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { ctx.pipeline().remove(this); finishSuccessfully(pipeline, H1C); ctx.fireChannelActive(); } }); } }
From source file:com.linecorp.armeria.client.HttpClientPipelineConfigurator.java
License:Apache License
private void configureAsHttp(Channel ch) { final ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(TrafficLoggingHandler.CLIENT); final boolean attemptUpgrade; switch (httpPreference) { case HTTP1_REQUIRED: attemptUpgrade = false;/*www . j a v a 2 s . com*/ break; case HTTP2_PREFERRED: assert remoteAddress != null; attemptUpgrade = !SessionProtocolNegotiationCache.isUnsupported(remoteAddress, H2C); break; case HTTP2_REQUIRED: attemptUpgrade = true; break; default: // Should never reach here. throw new Error(); } if (attemptUpgrade) { final Http2ClientConnectionHandler http2Handler = newHttp2ConnectionHandler(ch); if (clientFactory.useHttp2Preface()) { pipeline.addLast(new DowngradeHandler()); pipeline.addLast(http2Handler); } else { final Http1ClientCodec http1Codec = newHttp1Codec(clientFactory.maxHttp1InitialLineLength(), clientFactory.maxHttp1HeaderSize(), clientFactory.maxHttp1ChunkSize()); final Http2ClientUpgradeCodec http2ClientUpgradeCodec = new Http2ClientUpgradeCodec(http2Handler); final HttpClientUpgradeHandler http2UpgradeHandler = new HttpClientUpgradeHandler(http1Codec, http2ClientUpgradeCodec, (int) Math.min(Integer.MAX_VALUE, UPGRADE_RESPONSE_MAX_LENGTH)); pipeline.addLast(http1Codec); pipeline.addLast(new WorkaroundHandler()); pipeline.addLast(http2UpgradeHandler); pipeline.addLast(new UpgradeRequestHandler(http2Handler.responseDecoder())); } } else { pipeline.addLast(newHttp1Codec(clientFactory.maxHttp1InitialLineLength(), clientFactory.maxHttp1HeaderSize(), clientFactory.maxHttp1ChunkSize())); // NB: We do not call finishSuccessfully() immediately here // because it assumes HttpSessionHandler to be in the pipeline, // which is only true after the connection attempt is successful. pipeline.addLast(new ChannelInboundHandlerAdapter() { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { ctx.pipeline().remove(this); finishSuccessfully(pipeline, H1C); ctx.fireChannelActive(); } }); } }
From source file:com.linecorp.armeria.client.HttpConfigurator.java
License:Apache License
private void configureAsHttp(Channel ch) { final ChannelPipeline pipeline = ch.pipeline(); final boolean attemptUpgrade; switch (httpPreference) { case HTTP1_REQUIRED: attemptUpgrade = false;//w ww . j a va 2s.co m break; case HTTP2_PREFERRED: attemptUpgrade = !SessionProtocolNegotiationCache.isUnsupported(remoteAddress, H2C); break; case HTTP2_REQUIRED: attemptUpgrade = true; break; default: // Should never reach here. throw new Error(); } if (attemptUpgrade) { if (options.useHttp2Preface()) { pipeline.addLast(new DowngradeHandler()); pipeline.addLast(newHttp2ConnectionHandler(ch)); } else { Http1ClientCodec http1Codec = newHttp1Codec(); Http2ClientUpgradeCodec http2ClientUpgradeCodec = new Http2ClientUpgradeCodec( newHttp2ConnectionHandler(ch)); HttpClientUpgradeHandler http2UpgradeHandler = new HttpClientUpgradeHandler(http1Codec, http2ClientUpgradeCodec, options.maxFrameLength()); pipeline.addLast(http1Codec); pipeline.addLast(new WorkaroundHandler()); pipeline.addLast(http2UpgradeHandler); pipeline.addLast(new UpgradeRequestHandler()); } } else { pipeline.addLast(newHttp1Codec()); // NB: We do not call finishSuccessfully() immediately here // because it assumes HttpSessionHandler to be in the pipeline, // which is only true after the connection attempt is successful. pipeline.addLast(new ChannelInboundHandlerAdapter() { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { ctx.pipeline().remove(this); finishSuccessfully(pipeline, H1C); ctx.fireChannelActive(); } }); } }
From source file:com.linkedin.r2.transport.http.client.Http2InitializerHandler.java
License:Apache License
/** * Sets up HTTP/2 over TCP through protocol upgrade (h2c) pipeline *//* ww w.ja v a2s. c om*/ private void configureHttpPipeline(ChannelHandlerContext ctx, Request request) throws Exception { Http2StreamCodec http2Codec = new Http2StreamCodecBuilder().connection(_connection) .maxContentLength(_maxResponseSize).maxHeaderSize(_maxHeaderSize) .gracefulShutdownTimeoutMillis(_gracefulShutdownTimeout).streamingTimeout(_streamingTimeout) .scheduler(_scheduler).build(); HttpClientCodec sourceCodec = new HttpClientCodec(MAX_INITIAL_LINE_LENGTH, _maxHeaderSize, _maxChunkSize); Http2ClientUpgradeCodec targetCodec = new Http2ClientUpgradeCodec(http2Codec); HttpClientUpgradeHandler upgradeCodec = new HttpClientUpgradeHandler(sourceCodec, targetCodec, MAX_CLIENT_UPGRADE_CONTENT_LENGTH); Http2SchemeHandler schemeHandler = new Http2SchemeHandler(HttpScheme.HTTP.toString()); String host = request.getURI().getAuthority(); int port = request.getURI().getPort(); String path = request.getURI().getPath(); Http2UpgradeHandler upgradeHandler = new Http2UpgradeHandler(host, port, path); Http2StreamResponseHandler responseHandler = new Http2StreamResponseHandler(); Http2ChannelPoolHandler channelPoolHandler = new Http2ChannelPoolHandler(); ctx.pipeline().addBefore(ctx.name(), "sourceCodec", sourceCodec); ctx.pipeline().addBefore(ctx.name(), "upgradeCodec", upgradeCodec); ctx.pipeline().addBefore(ctx.name(), "upgradeHandler", upgradeHandler); ctx.pipeline().addBefore(ctx.name(), "schemeHandler", schemeHandler); ctx.pipeline().addBefore(ctx.name(), "responseHandler", responseHandler); ctx.pipeline().addBefore(ctx.name(), "channelHandler", channelPoolHandler); _setupComplete = true; }
From source file:com.vmware.xenon.common.http.netty.NettyHttpClientRequestInitializer.java
License:Open Source License
/** * initChannel is called by Netty when a channel is first used. *///from w ww. j ava 2 s .c o m @Override public void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); ch.config().setAllocator(NettyChannelContext.ALLOCATOR); ch.config().setSendBufferSize(NettyChannelContext.BUFFER_SIZE); ch.config().setReceiveBufferSize(NettyChannelContext.BUFFER_SIZE); if (this.pool.getSSLContext() != null) { if (this.isHttp2Only) { throw new IllegalArgumentException("HTTP/2 with SSL is not supported"); } SSLEngine engine = this.pool.getSSLContext().createSSLEngine(); engine.setUseClientMode(true); p.addLast(SSL_HANDLER, new SslHandler(engine)); } HttpClientCodec http1_codec = new HttpClientCodec(NettyChannelContext.MAX_INITIAL_LINE_LENGTH, NettyChannelContext.MAX_HEADER_SIZE, NettyChannelContext.MAX_CHUNK_SIZE, false, false); // The HttpClientCodec combines the HttpRequestEncoder and the HttpResponseDecoder, and it // also provides a method for upgrading the protocol, which we use to support HTTP/2. p.addLast(HTTP1_CODEC, http1_codec); if (this.isHttp2Only) { try { NettyHttpToHttp2Handler connectionHandler = makeHttp2ConnectionHandler(); Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec(connectionHandler); HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(http1_codec, upgradeCodec, this.requestPayloadSizeLimit); p.addLast(UPGRADE_HANDLER, upgradeHandler); p.addLast(UPGRADE_REQUEST, new UpgradeRequestHandler()); // This promise will be triggered when we negotiate the settings. // That's important because we can't send user data until the negotiation is done ChannelPromise settingsPromise = ch.newPromise(); p.addLast("settings-handler", new Http2SettingsHandler(settingsPromise)); ch.attr(NettyChannelContext.SETTINGS_PROMISE_KEY).set(settingsPromise); p.addLast(EVENT_LOGGER, new NettyHttp2UserEventLogger(this.debugLogging)); } catch (Throwable ex) { Utils.log(NettyHttpClientRequestInitializer.class, NettyHttpClientRequestInitializer.class.getSimpleName(), Level.WARNING, "Channel Initializer exception: %s", ex); throw ex; } } else { // The HttpObjectAggregator is not needed for HTTP/2. For HTTP/1.1 it // aggregates the HttpMessage and HttpContent into the FullHttpResponse p.addLast(AGGREGATOR_HANDLER, new HttpObjectAggregator(this.requestPayloadSizeLimit)); } p.addLast(XENON_HANDLER, new NettyHttpServerResponseHandler(this.pool)); }
From source file:http2.client.Http2ClientInitializer.java
License:Apache License
/** * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2. *//*from ww w. jav a2 s . com*/ private void configureClearText(SocketChannel ch) { // HttpClientCodec sourceCodec = new HttpClientCodec(); Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec(connectionHandler); HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, 65536); ch.pipeline().addLast(sourceCodec, upgradeHandler, new UpgradeRequestHandler(), new UserEventLogger()); }
From source file:io.aos.netty5.http2.client.Http2ClientInitializer.java
License:Apache License
/** * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2. *///from w w w . j a va 2 s . co m private void configureClearText(SocketChannel ch) { HttpClientCodec sourceCodec = new HttpClientCodec(); Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec(connectionHandler); HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, 65536); ch.pipeline().addLast("Http2SourceCodec", sourceCodec); ch.pipeline().addLast("Http2UpgradeHandler", upgradeHandler); ch.pipeline().addLast("Http2UpgradeRequestHandler", new UpgradeRequestHandler()); ch.pipeline().addLast("Logger", new UserEventLogger()); }
From source file:io.bsoa.rpc.grpc.client12.Http2ClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { final Http2Connection connection = new DefaultHttp2Connection(false); connectionHandler = new HttpToHttp2ConnectionHandlerBuilder() .frameListener(new DelegatingDecompressorFrameListener(connection, new InboundHttp2ToHttpAdapterBuilder(connection).maxContentLength(maxContentLength) .propagateSettings(true).build())) .frameLogger(logger).connection(connection).build(); responseHandler = new HttpResponseHandler(); settingsHandler = new Http2SettingsHandler(ch.newPromise()); HttpClientCodec sourceCodec = new HttpClientCodec(); Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec("connectionHandler", connectionHandler); HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, 65536); ch.pipeline().addLast("sourceCodec?", sourceCodec); ch.pipeline().addLast("upgradeHandlerupgrade", upgradeHandler); ch.pipeline().addLast("UpgradeRequestHandler?upgrade", new UpgradeRequestHandler()); ch.pipeline().addLast("UserEventLogger", new UserEventLogger()); System.out.println("======1=======>" + ch.pipeline().names() + "<=========" + ch.pipeline().toMap()); }