use of com.webpieces.http2parser.api.dto.PushPromiseFrame in project webpieces by deanhiller.
the class PushPromiseMarshaller method marshal.
@Override
public DataWrapper marshal(Http2Frame frame) {
PushPromiseFrame castFrame = (PushPromiseFrame) frame;
int originalStreamId = castFrame.getPromisedStreamId();
int streamId = originalStreamId & 0x7FFFFFFF;
if (streamId != originalStreamId)
throw new RuntimeException("your promisedStreamId is too large per spec. frame=" + frame);
int paddingSize = castFrame.getPadding().getReadableSize();
byte value = 0x0;
if (castFrame.isEndHeaders())
value |= 0x4;
if (paddingSize > 0)
value |= 0x8;
ByteBuffer prelude = bufferPool.nextBuffer(4);
prelude.putInt(castFrame.getPromisedStreamId());
prelude.flip();
DataWrapper headersDW = castFrame.getHeaderFragment();
DataWrapper finalDW = dataGen.chainDataWrappers(dataGen.wrapByteBuffer(prelude), headersDW);
DataWrapper payload = PaddingUtil.padDataIfNeeded(finalDW, castFrame.getPadding());
return super.marshalFrame(frame, value, payload);
}
use of com.webpieces.http2parser.api.dto.PushPromiseFrame in project webpieces by deanhiller.
the class HpackParserImpl method combineAndSendHeadersToClient.
private void combineAndSendHeadersToClient(UnmarshalStateImpl state) {
List<HasHeaderFragment> hasHeaderFragmentList = state.getHeadersToCombine();
// Now we set the full header list on the first frame and just return that
HasHeaderFragment firstFrame = hasHeaderFragmentList.get(0);
DataWrapper allSerializedHeaders = dataGen.emptyWrapper();
for (HasHeaderFragment iterFrame : hasHeaderFragmentList) {
allSerializedHeaders = dataGen.chainDataWrappers(allSerializedHeaders, iterFrame.getHeaderFragment());
}
Map<Http2HeaderName, Http2Header> knownHeaders = new HashMap<>();
List<Http2Header> headers = decoding.decode(state, allSerializedHeaders, firstFrame.getStreamId(), header -> knownHeaders.put(header.getKnownName(), header));
if (firstFrame instanceof HeadersFrame) {
HeadersFrame f = (HeadersFrame) firstFrame;
Http2Headers fullHeaders = createCorrectType(knownHeaders, headers, state.getLogId(), f.getStreamId());
fullHeaders.setStreamId(f.getStreamId());
fullHeaders.setPriorityDetails(f.getPriorityDetails());
fullHeaders.setEndOfStream(f.isEndOfStream());
state.getParsedFrames().add(fullHeaders);
} else if (firstFrame instanceof PushPromiseFrame) {
PushPromiseFrame f = (PushPromiseFrame) firstFrame;
Http2Push fullHeaders = new Http2Push(headers);
fullHeaders.setStreamId(f.getStreamId());
fullHeaders.setPromisedStreamId(f.getPromisedStreamId());
state.getParsedFrames().add(fullHeaders);
}
hasHeaderFragmentList.clear();
}
use of com.webpieces.http2parser.api.dto.PushPromiseFrame in project webpieces by deanhiller.
the class HeaderEncoding method translateToFrames.
public List<Http2Frame> translateToFrames(long maxFrameSize, Encoder encoder, Http2Push p) {
PushPromiseFrame frame = new PushPromiseFrame();
frame.setStreamId(p.getStreamId());
frame.setPromisedStreamId(p.getPromisedStreamId());
List<Http2Header> headerList = p.getHeaders();
List<Http2Frame> headerFrames = toHeaderFrames(maxFrameSize, encoder, frame, headerList);
return headerFrames;
}
use of com.webpieces.http2parser.api.dto.PushPromiseFrame in project webpieces by deanhiller.
the class HpackParserImpl method validateHeader.
private void validateHeader(UnmarshalStateImpl state, HasHeaderFragment lowLevelFrame) {
List<HasHeaderFragment> list = state.getHeadersToCombine();
HasHeaderFragment first = list.get(0);
int streamId = first.getStreamId();
if (first instanceof PushPromiseFrame) {
PushPromiseFrame f = (PushPromiseFrame) first;
streamId = f.getPromisedStreamId();
}
String logId = state.getLogId();
if (list.size() == 1) {
if (!(first instanceof HeadersFrame) && !(first instanceof PushPromiseFrame))
throw new ConnectionException(CancelReasonCode.HEADERS_MIXED_WITH_FRAMES, logId, lowLevelFrame.getStreamId(), "First has header frame must be HeadersFrame or PushPromiseFrame first frame=" + first);
} else if (streamId != lowLevelFrame.getStreamId()) {
throw new ConnectionException(CancelReasonCode.HEADERS_MIXED_WITH_FRAMES, logId, lowLevelFrame.getStreamId(), "Headers/continuations from two different streams per spec cannot be" + " interleaved. frames=" + list);
} else if (!(lowLevelFrame instanceof ContinuationFrame)) {
throw new ConnectionException(CancelReasonCode.HEADERS_MIXED_WITH_FRAMES, logId, lowLevelFrame.getStreamId(), "Must be continuation frame and wasn't. frames=" + list);
}
}
use of com.webpieces.http2parser.api.dto.PushPromiseFrame in project webpieces by deanhiller.
the class PushPromiseMarshaller method unmarshal.
@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
PushPromiseFrame frame = new PushPromiseFrame();
super.unmarshalFrame(state, frame);
if (frame.getStreamId() == 0)
throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "pushpromise frame had invalid stream id=" + frame.getStreamId());
byte flags = state.getFrameHeaderData().getFlagsByte();
frame.setEndHeaders((flags & 0x4) == 0x4);
boolean isPadded = (flags & 0x8) == 0x8;
List<? extends DataWrapper> split = dataGen.split(framePayloadData, 4);
ByteBuffer prelude = bufferPool.createWithDataWrapper(split.get(0));
DataSplit padSplit = PaddingUtil.extractPayloadAndPadding(isPadded, split.get(1), frame.getStreamId());
frame.setHeaderFragment(padSplit.getPayload());
frame.setPadding(padSplit.getPadding());
frame.setPromisedStreamId(prelude.getInt());
bufferPool.releaseBuffer(prelude);
return frame;
}
Aggregations