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);
}
}
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);
}
}
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));
}
Aggregations