Search in sources :

Example 11 with Http1Config

use of org.apache.hc.core5.http.config.Http1Config in project httpcomponents-core by apache.

the class InternalClientProtocolNegotiationStarter method createHandler.

@Override
public IOEventHandler createHandler(final ProtocolIOSession ioSession, final Object attachment) {
    if (sslContext != null) {
        ioSession.startTls(sslContext, null, null, sslSessionInitializer, sslSessionVerifier, null);
    }
    final ClientHttp1StreamDuplexerFactory http1StreamHandlerFactory = new ClientHttp1StreamDuplexerFactory(httpProcessor != null ? httpProcessor : HttpProcessors.client(), http1Config, charCodingConfig, LoggingHttp1StreamListener.INSTANCE_CLIENT);
    final ClientH2StreamMultiplexerFactory http2StreamHandlerFactory = new ClientH2StreamMultiplexerFactory(httpProcessor != null ? httpProcessor : H2Processors.client(), exchangeHandlerFactory, h2Config, charCodingConfig, LoggingH2StreamListener.INSTANCE);
    ioSession.registerProtocol(ApplicationProtocol.HTTP_1_1.id, new ClientHttp1UpgradeHandler(http1StreamHandlerFactory));
    ioSession.registerProtocol(ApplicationProtocol.HTTP_2.id, new ClientH2UpgradeHandler(http2StreamHandlerFactory));
    switch(versionPolicy) {
        case FORCE_HTTP_2:
            return new ClientH2PrefaceHandler(ioSession, http2StreamHandlerFactory, false);
        case FORCE_HTTP_1:
            return new ClientHttp1IOEventHandler(http1StreamHandlerFactory.create(ioSession));
        default:
            return new HttpProtocolNegotiator(ioSession, null);
    }
}
Also used : ClientH2PrefaceHandler(org.apache.hc.core5.http2.impl.nio.ClientH2PrefaceHandler) ClientHttp1StreamDuplexerFactory(org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory) HttpProtocolNegotiator(org.apache.hc.core5.http2.impl.nio.HttpProtocolNegotiator) ClientH2StreamMultiplexerFactory(org.apache.hc.core5.http2.impl.nio.ClientH2StreamMultiplexerFactory) ClientH2UpgradeHandler(org.apache.hc.core5.http2.impl.nio.ClientH2UpgradeHandler) ClientHttp1UpgradeHandler(org.apache.hc.core5.http2.impl.nio.ClientHttp1UpgradeHandler) ClientHttp1IOEventHandler(org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler)

Example 12 with Http1Config

use of org.apache.hc.core5.http.config.Http1Config in project httpcomponents-core by apache.

the class InternalServerProtocolNegotiationStarter method createHandler.

@Override
public IOEventHandler createHandler(final ProtocolIOSession ioSession, final Object attachment) {
    if (sslContext != null) {
        ioSession.startTls(sslContext, null, null, sslSessionInitializer, sslSessionVerifier, null);
    }
    final ServerHttp1StreamDuplexerFactory http1StreamHandlerFactory = new ServerHttp1StreamDuplexerFactory(httpProcessor != null ? httpProcessor : HttpProcessors.server(), exchangeHandlerFactory, http1Config, charCodingConfig, LoggingHttp1StreamListener.INSTANCE_SERVER);
    final ServerH2StreamMultiplexerFactory http2StreamHandlerFactory = new ServerH2StreamMultiplexerFactory(httpProcessor != null ? httpProcessor : H2Processors.server(), exchangeHandlerFactory, h2Config, charCodingConfig, LoggingH2StreamListener.INSTANCE);
    ioSession.registerProtocol(ApplicationProtocol.HTTP_1_1.id, new ServerHttp1UpgradeHandler(http1StreamHandlerFactory));
    ioSession.registerProtocol(ApplicationProtocol.HTTP_2.id, new ServerH2UpgradeHandler(http2StreamHandlerFactory));
    switch(versionPolicy) {
        case FORCE_HTTP_2:
            return new ServerH2PrefaceHandler(ioSession, http2StreamHandlerFactory);
        case FORCE_HTTP_1:
            return new ServerHttp1IOEventHandler(http1StreamHandlerFactory.create(sslContext != null ? URIScheme.HTTPS.id : URIScheme.HTTP.id, ioSession));
        default:
            return new HttpProtocolNegotiator(ioSession, null);
    }
}
Also used : ServerHttp1StreamDuplexerFactory(org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexerFactory) ServerH2PrefaceHandler(org.apache.hc.core5.http2.impl.nio.ServerH2PrefaceHandler) HttpProtocolNegotiator(org.apache.hc.core5.http2.impl.nio.HttpProtocolNegotiator) ServerH2StreamMultiplexerFactory(org.apache.hc.core5.http2.impl.nio.ServerH2StreamMultiplexerFactory) ServerHttp1IOEventHandler(org.apache.hc.core5.http.impl.nio.ServerHttp1IOEventHandler) ServerHttp1UpgradeHandler(org.apache.hc.core5.http2.impl.nio.ServerHttp1UpgradeHandler) ServerH2UpgradeHandler(org.apache.hc.core5.http2.impl.nio.ServerH2UpgradeHandler)

Example 13 with Http1Config

use of org.apache.hc.core5.http.config.Http1Config in project httpcomponents-core by apache.

the class TestChunkDecoder method testTooManyFooters.

@Test
public void testTooManyFooters() throws Exception {
    final String s = "10\r\n1234567890123456\r\n" + "0\r\nFooter1: blah\r\nFooter2: blah\r\nFooter3: blah\r\nFooter4: blah\r\n\r\n";
    final ReadableByteChannel channel1 = new ReadableByteChannelMock(new String[] { s }, StandardCharsets.US_ASCII);
    final SessionInputBuffer inbuf1 = new SessionInputBufferImpl(1024, 256, 0, StandardCharsets.US_ASCII);
    final BasicHttpTransportMetrics metrics1 = new BasicHttpTransportMetrics();
    final ChunkDecoder decoder1 = new ChunkDecoder(channel1, inbuf1, metrics1);
    final ByteBuffer dst = ByteBuffer.allocate(1024);
    final int bytesRead = decoder1.read(dst);
    Assertions.assertEquals(16, bytesRead);
    Assertions.assertEquals("1234567890123456", CodecTestUtils.convert(dst));
    final List<? extends Header> trailers = decoder1.getTrailers();
    Assertions.assertNotNull(trailers);
    Assertions.assertEquals(4, trailers.size());
    final Http1Config http1Config = Http1Config.custom().setMaxHeaderCount(3).build();
    final ReadableByteChannel channel2 = new ReadableByteChannelMock(new String[] { s }, StandardCharsets.US_ASCII);
    final SessionInputBuffer inbuf2 = new SessionInputBufferImpl(1024, 256, 0, StandardCharsets.US_ASCII);
    final BasicHttpTransportMetrics metrics2 = new BasicHttpTransportMetrics();
    final ChunkDecoder decoder2 = new ChunkDecoder(channel2, inbuf2, http1Config, metrics2);
    dst.clear();
    Assertions.assertThrows(MessageConstraintException.class, () -> decoder2.read(dst));
}
Also used : ReadableByteChannel(java.nio.channels.ReadableByteChannel) SessionInputBuffer(org.apache.hc.core5.http.nio.SessionInputBuffer) BasicHttpTransportMetrics(org.apache.hc.core5.http.impl.BasicHttpTransportMetrics) ReadableByteChannelMock(org.apache.hc.core5.http.ReadableByteChannelMock) ByteBuffer(java.nio.ByteBuffer) Http1Config(org.apache.hc.core5.http.config.Http1Config) Test(org.junit.jupiter.api.Test)

Aggregations

Http1Config (org.apache.hc.core5.http.config.Http1Config)6 IOSession (org.apache.hc.core5.reactor.IOSession)5 HttpHost (org.apache.hc.core5.http.HttpHost)4 CharCodingConfig (org.apache.hc.core5.http.config.CharCodingConfig)4 IOEventHandlerFactory (org.apache.hc.core5.reactor.IOEventHandlerFactory)4 ByteBuffer (java.nio.ByteBuffer)3 List (java.util.List)3 Supplier (org.apache.hc.core5.function.Supplier)3 BasicHttpTransportMetrics (org.apache.hc.core5.http.impl.BasicHttpTransportMetrics)3 DefaultConnectionReuseStrategy (org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy)3 Http1StreamListener (org.apache.hc.core5.http.impl.Http1StreamListener)3 HttpProcessors (org.apache.hc.core5.http.impl.HttpProcessors)3 ClientHttp1StreamDuplexerFactory (org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory)3 ServerHttp1StreamDuplexerFactory (org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexerFactory)3 AsyncServerExchangeHandler (org.apache.hc.core5.http.nio.AsyncServerExchangeHandler)3 AsyncServerRequestHandler (org.apache.hc.core5.http.nio.AsyncServerRequestHandler)3 HandlerFactory (org.apache.hc.core5.http.nio.HandlerFactory)3 TlsStrategy (org.apache.hc.core5.http.nio.ssl.TlsStrategy)3 BasicAsyncServerExpectationDecorator (org.apache.hc.core5.http.nio.support.BasicAsyncServerExpectationDecorator)3 DefaultAsyncResponseExchangeHandlerFactory (org.apache.hc.core5.http.nio.support.DefaultAsyncResponseExchangeHandlerFactory)3