Search in sources :

Example 51 with HttpResponseEncoder

use of io.netty.handler.codec.http.HttpResponseEncoder in project reactor-netty by reactor.

the class HttpClientTest method abort.

@Test
void abort() {
    disposableServer = TcpServer.create().port(0).handle((in, out) -> in.receive().take(1).thenMany(Flux.defer(() -> out.withConnection(c -> c.addHandlerFirst(new HttpResponseEncoder())).sendObject(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.ACCEPTED)).then(Mono.delay(Duration.ofSeconds(2)).then())))).wiretap(true).bindNow();
    ConnectionProvider pool = ConnectionProvider.create("abort", 1);
    HttpClient client = createHttpClientForContextWithPort(pool);
    client.get().uri("/").responseSingle((r, buf) -> Mono.just(r.status().code())).log().block(Duration.ofSeconds(30));
    client.get().uri("/").responseContent().log().blockLast(Duration.ofSeconds(30));
    client.get().uri("/").responseContent().log().blockLast(Duration.ofSeconds(30));
    pool.dispose();
}
Also used : Arrays(java.util.Arrays) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) StepVerifier(reactor.test.StepVerifier) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) Tuples(reactor.util.function.Tuples) Disabled(org.junit.jupiter.api.Disabled) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) HttpResources(reactor.netty.http.HttpResources) TcpClient(reactor.netty.tcp.TcpClient) Future(java.util.concurrent.Future) Loggers(reactor.util.Loggers) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) CharsetUtil(io.netty.util.CharsetUtil) Path(java.nio.file.Path) LoopResources(reactor.netty.resources.LoopResources) HttpObjectDecoder(io.netty.handler.codec.http.HttpObjectDecoder) Context(reactor.util.context.Context) Set(java.util.Set) ConnectionPoolMetrics(reactor.netty.resources.ConnectionPoolMetrics) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) CountDownLatch(java.util.concurrent.CountDownLatch) SSLException(javax.net.ssl.SSLException) AddressResolverGroup(io.netty.resolver.AddressResolverGroup) HttpServer(reactor.netty.http.server.HttpServer) LogLevel(io.netty.handler.logging.LogLevel) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) SocketUtils(reactor.netty.SocketUtils) HttpProtocol(reactor.netty.http.HttpProtocol) Nullable(reactor.util.annotation.Nullable) ArrayList(java.util.ArrayList) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) SslProvider(reactor.netty.tcp.SslProvider) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) SslContext(io.netty.handler.ssl.SslContext) Files(java.nio.file.Files) Publisher(org.reactivestreams.Publisher) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) Field(java.lang.reflect.Field) Channel(io.netty.channel.Channel) AtomicLong(java.util.concurrent.atomic.AtomicLong) DefaultEventExecutor(io.netty.util.concurrent.DefaultEventExecutor) Flux(reactor.core.publisher.Flux) FutureMono(reactor.netty.FutureMono) Paths(java.nio.file.Paths) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) ConnectionProvider(reactor.netty.resources.ConnectionProvider) DnsAddressResolverGroup(io.netty.resolver.dns.DnsAddressResolverGroup) Sinks(reactor.core.publisher.Sinks) SocketAddress(java.net.SocketAddress) Http11SslContextSpec(reactor.netty.http.Http11SslContextSpec) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) URISyntaxException(java.net.URISyntaxException) BiFunction(java.util.function.BiFunction) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ChannelId(io.netty.channel.ChannelId) Http2SslContextSpec(reactor.netty.http.Http2SslContextSpec) TimeoutException(java.util.concurrent.TimeoutException) BaseHttpTest(reactor.netty.BaseHttpTest) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) TransportConfig(reactor.netty.transport.TransportConfig) SocketChannel(java.nio.channels.SocketChannel) HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteBufFlux(reactor.netty.ByteBufFlux) NettyPipeline(reactor.netty.NettyPipeline) Logger(reactor.util.Logger) ByteBufMono(reactor.netty.ByteBufMono) URI(java.net.URI) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) ChannelGroup(io.netty.channel.group.ChannelGroup) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) StandardOpenOption(java.nio.file.StandardOpenOption) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) InetSocketAddress(java.net.InetSocketAddress) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) HttpVersion(io.netty.handler.codec.http.HttpVersion) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Tuple2(reactor.util.function.Tuple2) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Queues(reactor.util.concurrent.Queues) Charset(java.nio.charset.Charset) ByteBuf(io.netty.buffer.ByteBuf) Connection(reactor.netty.Connection) ExecutorService(java.util.concurrent.ExecutorService) HttpHeaderValues(io.netty.handler.codec.http.HttpHeaderValues) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) HttpMethod(io.netty.handler.codec.http.HttpMethod) CertificateException(java.security.cert.CertificateException) ServerSocketChannel(java.nio.channels.ServerSocketChannel) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) TcpServer(reactor.netty.tcp.TcpServer) ChannelHandler(io.netty.channel.ChannelHandler) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) ConnectionProvider(reactor.netty.resources.ConnectionProvider) BaseHttpTest(reactor.netty.BaseHttpTest) Test(org.junit.jupiter.api.Test)

Example 52 with HttpResponseEncoder

use of io.netty.handler.codec.http.HttpResponseEncoder in project apollo by apollo-rsps.

the class HttpChannelInitializer method initChannel.

@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("chunker", new HttpObjectAggregator(MAX_REQUEST_LENGTH));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("timeout", new IdleStateHandler(NetworkConstants.IDLE_TIME, 0, 0));
    pipeline.addLast("handler", handler);
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

HttpResponseEncoder (io.netty.handler.codec.http.HttpResponseEncoder)52 HttpRequestDecoder (io.netty.handler.codec.http.HttpRequestDecoder)45 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)28 ChannelPipeline (io.netty.channel.ChannelPipeline)25 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)12 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)11 HttpContentCompressor (io.netty.handler.codec.http.HttpContentCompressor)11 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)10 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)10 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)10 SocketChannel (io.netty.channel.socket.SocketChannel)9 Channel (io.netty.channel.Channel)8 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)8 Test (org.junit.jupiter.api.Test)8 EventLoopGroup (io.netty.channel.EventLoopGroup)7 HttpContentDecompressor (io.netty.handler.codec.http.HttpContentDecompressor)7 SslHandler (io.netty.handler.ssl.SslHandler)7 InetSocketAddress (java.net.InetSocketAddress)7 Unpooled (io.netty.buffer.Unpooled)6 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)6