use of org.apache.hc.core5.reactor.ProtocolIOSession in project httpcomponents-core by apache.
the class TestAbstractH2StreamMultiplexer method testInputMultipleFrames.
@Test
public void testInputMultipleFrames() throws Exception {
final WritableByteChannelMock writableChannel = new WritableByteChannelMock(1024);
final FrameOutputBuffer outbuffer = new FrameOutputBuffer(16 * 1024);
final byte[] data = new byte[FrameConsts.MIN_FRAME_SIZE];
for (int i = 0; i < FrameConsts.MIN_FRAME_SIZE; i++) {
data[i] = (byte) (i % 16);
}
final RawFrame frame1 = new RawFrame(FrameType.DATA.getValue(), 0, 1, ByteBuffer.wrap(data));
outbuffer.write(frame1, writableChannel);
final RawFrame frame2 = new RawFrame(FrameType.DATA.getValue(), 0, 1, ByteBuffer.wrap(data));
outbuffer.write(frame2, writableChannel);
final byte[] bytes = writableChannel.toByteArray();
final AbstractH2StreamMultiplexer streamMultiplexer = new H2StreamMultiplexerImpl(protocolIOSession, DefaultFrameFactory.INSTANCE, StreamIdGenerator.ODD, httpProcessor, CharCodingConfig.DEFAULT, H2Config.custom().setMaxFrameSize(FrameConsts.MIN_FRAME_SIZE).build(), h2StreamListener);
Assertions.assertThrows(H2ConnectionException.class, () -> streamMultiplexer.onInput(ByteBuffer.wrap(bytes)));
Mockito.verify(h2StreamListener).onFrameInput(Mockito.same(streamMultiplexer), Mockito.eq(1), Mockito.any());
Assertions.assertThrows(H2ConnectionException.class, () -> {
int pos = 0;
int remaining = bytes.length;
while (remaining > 0) {
final int chunk = Math.min(4096, remaining);
streamMultiplexer.onInput(ByteBuffer.wrap(bytes, pos, chunk));
pos += chunk;
remaining -= chunk;
}
Mockito.verify(h2StreamListener).onFrameInput(Mockito.same(streamMultiplexer), Mockito.eq(1), Mockito.any());
});
}
use of org.apache.hc.core5.reactor.ProtocolIOSession in project httpcomponents-core by apache.
the class ServerHttpProtocolNegotiationStarter method createHandler.
@Override
public HttpConnectionEventHandler createHandler(final ProtocolIOSession ioSession, final Object attachment) {
HttpVersionPolicy endpointPolicy = versionPolicy;
URIScheme uriScheme = URIScheme.HTTP;
if (attachment instanceof EndpointParameters) {
final EndpointParameters params = (EndpointParameters) attachment;
if (tlsStrategy != null && URIScheme.HTTPS.same(params.getScheme())) {
uriScheme = URIScheme.HTTPS;
tlsStrategy.upgrade(ioSession, params, params.getAttachment(), handshakeTimeout, null);
}
if (params.getAttachment() instanceof HttpVersionPolicy) {
endpointPolicy = (HttpVersionPolicy) params.getAttachment();
}
}
ioSession.registerProtocol(ApplicationProtocol.HTTP_1_1.id, new ServerHttp1UpgradeHandler(http1StreamHandlerFactory));
ioSession.registerProtocol(ApplicationProtocol.HTTP_2.id, new ServerH2UpgradeHandler(http2StreamHandlerFactory));
switch(endpointPolicy) {
case FORCE_HTTP_2:
return new ServerH2PrefaceHandler(ioSession, http2StreamHandlerFactory);
case FORCE_HTTP_1:
return new ServerHttp1IOEventHandler(http1StreamHandlerFactory.create(uriScheme.id, ioSession));
default:
return new HttpProtocolNegotiator(ioSession, null);
}
}
use of org.apache.hc.core5.reactor.ProtocolIOSession in project httpcomponents-core by apache.
the class ClientH2UpgradeHandler method upgrade.
@Override
public void upgrade(final ProtocolIOSession ioSession, final FutureCallback<ProtocolIOSession> callback) {
final HttpConnectionEventHandler protocolNegotiator = new ClientH2PrefaceHandler(ioSession, http2StreamHandlerFactory, true, callback);
ioSession.upgrade(protocolNegotiator);
try {
protocolNegotiator.connected(ioSession);
} catch (final IOException ex) {
protocolNegotiator.exception(ioSession, ex);
}
}
Aggregations