use of org.apache.hc.core5.http2.frame.RawFrame in project httpcomponents-core by apache.
the class AbstractH2StreamMultiplexer method consumeDataFrame.
private void consumeDataFrame(final RawFrame frame, final H2Stream stream) throws HttpException, IOException {
final int streamId = stream.getId();
final ByteBuffer payload = frame.getPayloadContent();
if (payload != null) {
final int frameLength = frame.getLength();
final int streamWinSize = updateInputWindow(streamId, stream.getInputWindow(), -frameLength);
if (streamWinSize < lowMark && !stream.isRemoteClosed()) {
stream.produceInputCapacityUpdate();
}
final int connWinSize = updateInputWindow(0, connInputWindow, -frameLength);
if (connWinSize < CONNECTION_WINDOW_LOW_MARK) {
maximizeConnWindow(connWinSize);
}
}
if (stream.isRemoteClosed()) {
throw new H2StreamResetException(H2Error.STREAM_CLOSED, "Stream already closed");
}
if (frame.isFlagSet(FrameFlag.END_STREAM)) {
stream.setRemoteEndStream();
}
if (stream.isLocalReset()) {
return;
}
stream.consumeData(payload);
}
use of org.apache.hc.core5.http2.frame.RawFrame in project httpcomponents-core by apache.
the class AbstractH2StreamMultiplexer method streamDataFrame.
private void streamDataFrame(final int streamId, final AtomicInteger streamOutputWindow, final ByteBuffer payload, final int chunk) throws IOException {
final RawFrame dataFrame = frameFactory.createData(streamId, payload, false);
if (streamListener != null) {
streamListener.onFrameOutput(this, streamId, dataFrame);
}
updateOutputWindow(0, connOutputWindow, -chunk);
updateOutputWindow(streamId, streamOutputWindow, -chunk);
outputBuffer.write(dataFrame, ioSession);
}
use of org.apache.hc.core5.http2.frame.RawFrame in project httpcomponents-core by apache.
the class AbstractH2StreamMultiplexer method onConnect.
public final void onConnect() throws HttpException, IOException {
connState = ConnectionHandshake.ACTIVE;
final RawFrame settingsFrame = frameFactory.createSettings(new H2Setting(H2Param.HEADER_TABLE_SIZE, localConfig.getHeaderTableSize()), new H2Setting(H2Param.ENABLE_PUSH, localConfig.isPushEnabled() ? 1 : 0), new H2Setting(H2Param.MAX_CONCURRENT_STREAMS, localConfig.getMaxConcurrentStreams()), new H2Setting(H2Param.INITIAL_WINDOW_SIZE, localConfig.getInitialWindowSize()), new H2Setting(H2Param.MAX_FRAME_SIZE, localConfig.getMaxFrameSize()), new H2Setting(H2Param.MAX_HEADER_LIST_SIZE, localConfig.getMaxHeaderListSize()));
commitFrame(settingsFrame);
localSettingState = SettingsHandshake.TRANSMITTED;
maximizeConnWindow(connInputWindow.get());
if (streamListener != null) {
final int initInputWindow = connInputWindow.get();
streamListener.onInputFlowControl(this, 0, initInputWindow, initInputWindow);
final int initOutputWindow = connOutputWindow.get();
streamListener.onOutputFlowControl(this, 0, initOutputWindow, initOutputWindow);
}
}
use of org.apache.hc.core5.http2.frame.RawFrame in project httpcomponents-core by apache.
the class H2TlsAlpnRequestExecutionExample method main.
public static void main(final String[] args) throws Exception {
// Create and start requester
final H2Config h2Config = H2Config.custom().setPushEnabled(false).build();
final HttpAsyncRequester requester = H2RequesterBootstrap.bootstrap().setH2Config(h2Config).setTlsStrategy(new H2ClientTlsStrategy(SSLContexts.createSystemDefault(), (endpoint, sslEngine) -> {
// ====
return null;
})).setStreamListener(new H2StreamListener() {
@Override
public void onHeaderInput(final HttpConnection connection, final int streamId, final List<? extends Header> headers) {
for (int i = 0; i < headers.size(); i++) {
System.out.println(connection.getRemoteAddress() + " (" + streamId + ") << " + headers.get(i));
}
}
@Override
public void onHeaderOutput(final HttpConnection connection, final int streamId, final List<? extends Header> headers) {
for (int i = 0; i < headers.size(); i++) {
System.out.println(connection.getRemoteAddress() + " (" + streamId + ") >> " + headers.get(i));
}
}
@Override
public void onFrameInput(final HttpConnection connection, final int streamId, final RawFrame frame) {
}
@Override
public void onFrameOutput(final HttpConnection connection, final int streamId, final RawFrame frame) {
}
@Override
public void onInputFlowControl(final HttpConnection connection, final int streamId, final int delta, final int actualSize) {
}
@Override
public void onOutputFlowControl(final HttpConnection connection, final int streamId, final int delta, final int actualSize) {
}
}).create();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
System.out.println("HTTP requester shutting down");
requester.close(CloseMode.GRACEFUL);
}));
requester.start();
final HttpHost target = new HttpHost("https", "nghttp2.org", 443);
final String[] requestUris = new String[] { "/httpbin/ip", "/httpbin/user-agent", "/httpbin/headers" };
final CountDownLatch latch = new CountDownLatch(requestUris.length);
for (final String requestUri : requestUris) {
final Future<AsyncClientEndpoint> future = requester.connect(target, Timeout.ofSeconds(5));
final AsyncClientEndpoint clientEndpoint = future.get();
clientEndpoint.execute(AsyncRequestBuilder.get().setHttpHost(target).setPath(requestUri).build(), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), new FutureCallback<Message<HttpResponse, String>>() {
@Override
public void completed(final Message<HttpResponse, String> message) {
clientEndpoint.releaseAndReuse();
final HttpResponse response = message.getHead();
final String body = message.getBody();
System.out.println(requestUri + "->" + response.getCode() + " " + response.getVersion());
System.out.println(body);
latch.countDown();
}
@Override
public void failed(final Exception ex) {
clientEndpoint.releaseAndDiscard();
System.out.println(requestUri + "->" + ex);
latch.countDown();
}
@Override
public void cancelled() {
clientEndpoint.releaseAndDiscard();
System.out.println(requestUri + " cancelled");
latch.countDown();
}
});
}
latch.await();
System.out.println("Shutting down I/O reactor");
requester.initiateShutdown();
}
Aggregations