本文整理匯總了Java中io.netty.handler.codec.http.HttpContentCompressor類的典型用法代碼示例。如果您正苦於以下問題:Java HttpContentCompressor類的具體用法?Java HttpContentCompressor怎麽用?Java HttpContentCompressor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HttpContentCompressor類屬於io.netty.handler.codec.http包,在下文中一共展示了HttpContentCompressor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initChannel
import io.netty.handler.codec.http.HttpContentCompressor; //導入依賴的package包/類
@Override
protected void initChannel(Channel ch) throws Exception {
// create a new pipeline
ChannelPipeline pipeline = ch.pipeline();
SslHandler sslHandler = configureServerSSLOnDemand();
if (sslHandler != null) {
LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
pipeline.addLast("ssl", sslHandler);
}
pipeline.addLast("decoder", new HttpRequestDecoder(409, configuration.getMaxHeaderSize(), 8192));
pipeline.addLast("encoder", new HttpResponseEncoder());
if (configuration.isChunked()) {
pipeline.addLast("aggregator", new HttpObjectAggregator(configuration.getChunkedMaxContentLength()));
}
if (configuration.isCompression()) {
pipeline.addLast("deflater", new HttpContentCompressor());
}
pipeline.addLast("handler", channelFactory.getChannelHandler());
}
示例2: initChannel_adds_HttpContentCompressor_before_HttpResponseEncoder_for_outbound_handler
import io.netty.handler.codec.http.HttpContentCompressor; //導入依賴的package包/類
@Test
public void initChannel_adds_HttpContentCompressor_before_HttpResponseEncoder_for_outbound_handler() {
// given
HttpChannelInitializer hci = basicHttpChannelInitializerNoUtilityHandlers();
// when
hci.initChannel(socketChannelMock);
// then
ArgumentCaptor<ChannelHandler> channelHandlerArgumentCaptor = ArgumentCaptor.forClass(ChannelHandler.class);
verify(channelPipelineMock, atLeastOnce()).addLast(anyString(), channelHandlerArgumentCaptor.capture());
List<ChannelHandler> handlers = channelHandlerArgumentCaptor.getAllValues();
Pair<Integer, HttpContentCompressor> httpContentCompressor = findChannelHandler(handlers, HttpContentCompressor.class);
Pair<Integer, HttpResponseEncoder> httpResponseEncoder = findChannelHandler(handlers, HttpResponseEncoder.class);
assertThat(httpContentCompressor, notNullValue());
assertThat(httpResponseEncoder, notNullValue());
// HttpContentCompressor's index should be later than HttpResponseEncoder's index to verify that it comes BEFORE HttpResponseEncoder on the OUTBOUND handlers
// (since the outbound handlers are processed in reverse order).
assertThat(httpContentCompressor.getLeft(), is(greaterThan(httpResponseEncoder.getLeft())));
}
示例3: initChannel_adds_RequestInfoSetterHandler_after_HttpContentCompressor
import io.netty.handler.codec.http.HttpContentCompressor; //導入依賴的package包/類
@Test
public void initChannel_adds_RequestInfoSetterHandler_after_HttpContentCompressor() {
// given
HttpChannelInitializer hci = basicHttpChannelInitializerNoUtilityHandlers();
// when
hci.initChannel(socketChannelMock);
// then
ArgumentCaptor<ChannelHandler> channelHandlerArgumentCaptor = ArgumentCaptor.forClass(ChannelHandler.class);
verify(channelPipelineMock, atLeastOnce()).addLast(anyString(), channelHandlerArgumentCaptor.capture());
List<ChannelHandler> handlers = channelHandlerArgumentCaptor.getAllValues();
Pair<Integer, HttpContentCompressor> httpContentCompressor = findChannelHandler(handlers, HttpContentCompressor.class);
Pair<Integer, RequestInfoSetterHandler> requestInfoSetterHandler = findChannelHandler(handlers, RequestInfoSetterHandler.class);
assertThat(httpContentCompressor, notNullValue());
assertThat(requestInfoSetterHandler, notNullValue());
assertThat(requestInfoSetterHandler.getLeft(), is(greaterThan(httpContentCompressor.getLeft())));
//verify max size is passed through into RequestInfoSetterHandler
assertThat(extractField(requestInfoSetterHandler.getRight(), "globalConfiguredMaxRequestSizeInBytes"), is(42));
}
示例4: initChannel
import io.netty.handler.codec.http.HttpContentCompressor; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
if (sslCtx != null) {
pipeline.addLast(sslCtx.newHandler(ch.alloc()));
}
pipeline.addLast(new HttpRequestDecoder());
pipeline.addLast(new HttpResponseEncoder());
// Remove the following line if you don't want automatic content compression.
pipeline.addLast(new HttpContentCompressor());
pipeline.addLast(new HttpUploadServerHandler());
}
示例5: initializerFactory
import io.netty.handler.codec.http.HttpContentCompressor; //導入依賴的package包/類
@Bean(name = "channelInitializer")
public ChannelInitializer<SocketChannel> initializerFactory(final ApplicationContext contxt) {
return new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
SimpleChannelInboundHandler<?> channelInboundHandler = contxt.getBean(NettyHttpChannelHandler.class);
ChannelPipeline pipeline = ch.pipeline();
// HTTP
pipeline.addLast(new HttpRequestDecoder());
pipeline.addLast(new HttpResponseEncoder());
pipeline.addLast(new HttpContentCompressor());
pipeline.addLast(new ChunkedWriteHandler());
// 設置處理的Handler
pipeline.addLast(channelInboundHandler);
}
};
}
示例6: initChannel
import io.netty.handler.codec.http.HttpContentCompressor; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
// Add the generic handlers to the pipeline
// e.g. SSL handler
if (sslEngine != null) {
if (log.isDebugEnabled()) {
log.debug("adding ssl handler");
}
ch.pipeline().addLast("ssl", new SslHandler(this.sslEngine));
}
ch.pipeline().addLast("compressor", new HttpContentCompressor());
ch.pipeline().addLast("decoder", new HttpResponseDecoder());
ch.pipeline().addLast("encoder", new HttpRequestEncoder());
if (httpTraceLogEnabled) {
ch.pipeline().addLast(Constants.HTTP_TRACE_LOG_HANDLER,
new HTTPTraceLoggingHandler("tracelog.http.upstream", LogLevel.DEBUG));
}
RedirectHandler redirectHandler = new RedirectHandler(sslEngine, httpTraceLogEnabled, maxRedirectCount
, chunkDisabled, originalChannelContext, isIdleHandlerOfTargetChannelRemoved);
ch.pipeline().addLast(Constants.REDIRECT_HANDLER, redirectHandler);
}
示例7: initChannel
import io.netty.handler.codec.http.HttpContentCompressor; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
//inbound handler
pipeline.addLast(new HttpRequestDecoder());
pipeline.addLast(new HttpContentDecompressor());
//outbound handler
pipeline.addLast(new HttpResponseEncoder());
pipeline.addLast(new HttpContentCompressor());
//pipeline.addLast(new ChunkedWriteHandler());
pipeline.addLast(new HttpObjectAggregator(this.sc.getSize()));
pipeline.addLast(this.galeHttpHandler);
}
示例8: initChannel
import io.netty.handler.codec.http.HttpContentCompressor; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc()));
}
p.addLast(new HttpRequestDecoder());
// Uncomment the following line if you don't want to handle HttpChunks.
p.addLast(new HttpObjectAggregator(65536));
p.addLast(new HttpResponseEncoder());
// Remove the following line if you don't want automatic content
// compression.
p.addLast(new HttpContentCompressor());
p.addLast(new ApiRequestParser());
}
示例9: initChannel
import io.netty.handler.codec.http.HttpContentCompressor; //導入依賴的package包/類
public void initChannel(SocketChannel channel) {
ChannelPipeline pipeline = channel.pipeline();
// pipeline.addLast("tracker", connectionTracker);
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("aggregator", new HttpObjectAggregator(Integer.MAX_VALUE)); //TODO: fix
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("compressor", new HttpContentCompressor());
HttpResourceHandler resourceHandler = new HttpResourceHandler(dataHolder.getHttpServices(),
new ArrayList<HandlerHook>(), null, null);
pipeline.addLast(new DefaultEventExecutorGroup(200),
"router", new RequestRouter(resourceHandler, 0)); //TODO: remove limit
//TODO: see what can be done
/*if (pipelineModifier != null) {
pipelineModifier.apply(pipeline);
}*/
}
示例10: initChannel
import io.netty.handler.codec.http.HttpContentCompressor; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc()));
}
if (enableGzip) {
p.addLast(new HttpContentCompressor());
}
p.addLast(new HttpServerCodec(36192 * 2, 36192 * 8, 36192 * 16, false));
p.addLast(new HttpServerExpectContinueHandler());
p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
p.addLast(new ChunkedWriteHandler());
if (enableCors) {
CorsConfig corsConfig = CorsConfigBuilder.forAnyOrigin().allowNullOrigin().allowCredentials().build();
p.addLast(new CorsHandler(corsConfig));
}
if (null != blade.webSocketPath()) {
p.addLast(new WebSocketServerProtocolHandler(blade.webSocketPath(), null, true));
p.addLast(new WebSockerHandler(blade));
}
service.scheduleWithFixedDelay(() -> date = new AsciiString(DateKit.gmtDate(LocalDateTime.now())), 1000, 1000, TimeUnit.MILLISECONDS);
p.addLast(new HttpServerHandler());
}
示例11: initChannel
import io.netty.handler.codec.http.HttpContentCompressor; //導入依賴的package包/類
@Override
protected void initChannel(Channel channel) throws Exception {
// Create a default pipeline implementation.
ChannelPipeline pipeline = channel.pipeline();
// Uncomment the following line if you want HTTPS
// SSLEngine engine =
// SecureChatSslContextFactory.getServerContext().createSSLEngine();
// engine.setUseClientMode(false);
// pipeline.addLast("ssl", new SslHandler(engine));
pipeline.addLast("decoder", new HttpRequestDecoder());
//pipeline.addLast("aggregator", new HttpChunkAggregator(65536));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
pipeline.addLast("deflater", new HttpContentCompressor());
pipeline.addLast("handler", new HttpDataServerHandler(userName, appId));
}
示例12: initChannel
import io.netty.handler.codec.http.HttpContentCompressor; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) throws Exception {
// Create a default pipeline implementation.
ChannelPipeline pipeline = ch.pipeline();
if (HttpUploadServer.isSSL) {
SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
engine.setUseClientMode(false);
pipeline.addLast("ssl", new SslHandler(engine));
}
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("encoder", new HttpResponseEncoder());
// Remove the following line if you don't want automatic content
// compression.
pipeline.addLast("deflater", new HttpContentCompressor());
pipeline.addLast("handler", new HttpUploadServerHandler());
}
示例13: initChannel
import io.netty.handler.codec.http.HttpContentCompressor; //導入依賴的package包/類
@Override
public void initChannel(final SocketChannel ch) throws Exception {
final ChannelPipeline p = ch.pipeline();
// Uncomment the following line if you want HTTPS
//SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
//engine.setUseClientMode(false);
//p.addLast("ssl", new SslHandler(engine));
p.addLast("decoder", new HttpRequestDecoder(16384, 8192, 16384));
p.addLast("encoder", new HttpResponseEncoder());
p.addLast("aggregator", new HttpObjectAggregator(maxContentLength));
p.addLast("chunkedWriter", new ChunkedWriteHandler());
p.addLast("static", staticFileServerHandler);
// the compressor is behind the static handler to avoid compression of static files
// Netty doesn't handle it very well :(
if (supportZip) {
p.addLast("compressor", new HttpContentCompressor());
}
p.addLast("idleState", new IdleStateHandler(0, 0, idleTimeoutMs, TimeUnit.MILLISECONDS));
p.addLast("handler", new HttpRequestDispatcherHandler(contextPath, dispatcher, staticResolver,
marshallerRegistry, activeChannels, acceptKeepAlive, metricFactory, requestTimeoutMs));
}
示例14: initChannel
import io.netty.handler.codec.http.HttpContentCompressor; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("http-request-decoder", new HttpRequestDecoder());
pipeline.addLast("deflater", new HttpContentDecompressor());
pipeline.addLast("http-object-aggregator", new HttpObjectAggregator(1048576));
pipeline.addLast("http-response-encoder", new HttpResponseEncoder());
pipeline.addLast("inflater", new HttpContentCompressor());
// Alters the pipeline depending on either REST or WebSockets requests
pipeline.addLast("api-protocol-switcher", apiProtocolSwitcher);
pipeline.addLast("debugger", debugger);
// Logging handlers for API requests
pipeline.addLast("api-request-logger", apiRequestLogger);
// pipeline.addLast(rxJavaGroup, "rxjava-handler", rxjavaHandler);
// JAX-RS handlers
pipeline.addLast(jaxRsGroup, "jax-rs-handler", jaxRsHandlers);
}
示例15: initChannel
import io.netty.handler.codec.http.HttpContentCompressor; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
// p.addLast("log", new LoggingHandler(LogLevel.ERROR));
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc()));
}
p.addLast(new HttpRequestDecoder());
p.addLast(new HttpResponseEncoder());
p.addLast("http compressor", new HttpContentCompressor());
// p.addLast(new HttpObjectAggregator(1048576));
p.addLast("http dispatcher", reqDis);
p.addLast("idleStateHandler", new IdleStateHandler(10, 10, 0));
p.addLast("heartbeatHandler", new HeartbeatHandler());
}