use of org.apache.hc.core5.http2.frame.RawFrame in project httpcomponents-core by apache.
the class FrameOutputBuffer method write.
public void write(final RawFrame frame, final OutputStream outStream) throws IOException {
if (frame == null) {
return;
}
final int type = frame.getType();
final long streamId = frame.getStreamId();
final int flags = frame.getFlags();
final ByteBuffer payload = frame.getPayload();
final int payloadLen = payload != null ? payload.remaining() : 0;
if (payload != null && payload.remaining() > maxFramePayloadSize) {
throw new H2ConnectionException(H2Error.FRAME_SIZE_ERROR, "Frame size exceeds maximum");
}
buffer[0] = (byte) (payloadLen >> 16 & 0xff);
buffer[1] = (byte) (payloadLen >> 8 & 0xff);
buffer[2] = (byte) (payloadLen & 0xff);
buffer[3] = (byte) (type & 0xff);
buffer[4] = (byte) (flags & 0xff);
buffer[5] = (byte) (streamId >> 24 & 0xff);
buffer[6] = (byte) (streamId >> 16 & 0xff);
buffer[7] = (byte) (streamId >> 8 & 0xff);
buffer[8] = (byte) (streamId & 0xff);
int frameLen = FrameConsts.HEAD_LEN;
int padding = 0;
if ((flags & FrameFlag.PADDED.getValue()) > 0) {
padding = 16;
buffer[9] = (byte) (padding & 0xff);
frameLen++;
}
if (payload != null) {
payload.get(buffer, frameLen, payload.remaining());
frameLen += payloadLen;
}
for (int i = 0; i < padding; i++) {
buffer[frameLen++] = 0;
}
outStream.write(buffer, 0, frameLen);
metrics.incrementFramesTransferred();
metrics.incrementBytesTransferred(frameLen);
}
use of org.apache.hc.core5.http2.frame.RawFrame in project httpcomponents-core by apache.
the class AbstractH2StreamMultiplexer method incrementInputCapacity.
private void incrementInputCapacity(final int streamId, final AtomicInteger inputWindow, final int inputCapacity) throws IOException {
if (inputCapacity > 0) {
final int streamWinSize = inputWindow.get();
final int remainingCapacity = Integer.MAX_VALUE - streamWinSize;
final int chunk = Math.min(inputCapacity, remainingCapacity);
if (chunk != 0) {
final RawFrame windowUpdateFrame = frameFactory.createWindowUpdate(streamId, chunk);
commitFrame(windowUpdateFrame);
updateInputWindow(streamId, inputWindow, chunk);
}
}
}
use of org.apache.hc.core5.http2.frame.RawFrame in project httpcomponents-core by apache.
the class AbstractH2StreamMultiplexer method consumeContinuationFrame.
private void consumeContinuationFrame(final RawFrame frame, final H2Stream stream) throws HttpException, IOException {
final int streamId = frame.getStreamId();
final ByteBuffer payload = frame.getPayload();
continuation.copyPayload(payload);
if (frame.isFlagSet(FrameFlag.END_HEADERS)) {
final List<Header> headers = decodeHeaders(continuation.getContent());
if (stream.isRemoteInitiated() && streamId > processedRemoteStreamId) {
processedRemoteStreamId = streamId;
}
if (streamListener != null) {
streamListener.onHeaderInput(this, streamId, headers);
}
if (stream.isRemoteClosed()) {
throw new H2StreamResetException(H2Error.STREAM_CLOSED, "Stream already closed");
}
if (stream.isLocalReset()) {
return;
}
if (continuation.endStream) {
stream.setRemoteEndStream();
}
if (continuation.type == FrameType.PUSH_PROMISE.getValue()) {
stream.consumePromise(headers);
} else {
stream.consumeHeader(headers);
}
continuation = null;
}
}
use of org.apache.hc.core5.http2.frame.RawFrame in project httpcomponents-core by apache.
the class AbstractH2StreamMultiplexer method onInput.
public final void onInput(final ByteBuffer src) throws HttpException, IOException {
if (connState == ConnectionHandshake.SHUTDOWN) {
ioSession.clearEvent(SelectionKey.OP_READ);
} else {
for (; ; ) {
final RawFrame frame = inputBuffer.read(src, ioSession);
if (frame == null) {
break;
}
if (streamListener != null) {
streamListener.onFrameInput(this, frame.getStreamId(), frame);
}
consumeFrame(frame);
}
}
}
use of org.apache.hc.core5.http2.frame.RawFrame in project httpcomponents-core by apache.
the class AbstractH2StreamMultiplexer method consumeHeaderFrame.
private void consumeHeaderFrame(final RawFrame frame, final H2Stream stream) throws HttpException, IOException {
final int streamId = stream.getId();
if (!frame.isFlagSet(FrameFlag.END_HEADERS)) {
continuation = new Continuation(streamId, frame.getType(), frame.isFlagSet(FrameFlag.END_STREAM));
}
final ByteBuffer payload = frame.getPayloadContent();
if (frame.isFlagSet(FrameFlag.PRIORITY)) {
// Priority not supported
payload.getInt();
payload.get();
}
if (continuation == null) {
final List<Header> headers = decodeHeaders(payload);
if (stream.isRemoteInitiated() && streamId > processedRemoteStreamId) {
processedRemoteStreamId = streamId;
}
if (streamListener != null) {
streamListener.onHeaderInput(this, streamId, headers);
}
if (stream.isRemoteClosed()) {
throw new H2StreamResetException(H2Error.STREAM_CLOSED, "Stream already closed");
}
if (stream.isLocalReset()) {
return;
}
if (frame.isFlagSet(FrameFlag.END_STREAM)) {
stream.setRemoteEndStream();
}
stream.consumeHeader(headers);
} else {
continuation.copyPayload(payload);
}
}
Aggregations