package io.undertow.protocols.http2;
import org.xnio.Bits;
import java.nio.ByteBuffer;
class Http2PushPromiseParser extends Http2HeaderBlockParser {
private int paddingLength = 0;
private int promisedStreamId;
private static final int STREAM_MASK = ~(1 << 7);
Http2PushPromiseParser(int frameLength, HpackDecoder hpackDecoder, boolean client, int maxHeaders, int streamId, int maxHeaderListSize) {
super(frameLength, hpackDecoder, client, maxHeaders, streamId, maxHeaderListSize);
}
@Override
protected boolean handleBeforeHeader(ByteBuffer resource, Http2FrameHeaderParser headerParser) {
boolean hasPadding = Bits.anyAreSet(headerParser.flags, Http2Channel.HEADERS_FLAG_PADDED);
int reqLength = (hasPadding ? 1 : 0) + 4;
if (resource.remaining() < reqLength) {
return false;
}
if (hasPadding) {
paddingLength = (resource.get() & 0xFF);
}
promisedStreamId = (resource.get() & STREAM_MASK) << 24;
promisedStreamId += (resource.get() & 0xFF) << 16;
promisedStreamId += (resource.get() & 0xFF) << 8;
promisedStreamId += (resource.get() & 0xFF);
return true;
}
protected int getPaddingLength() {
return paddingLength;
}
public int getPromisedStreamId() {
return promisedStreamId;
}
}