use of com.webpieces.http2parser.api.dto.HeadersFrame in project webpieces by deanhiller.
the class HeadersMarshaller method unmarshal.
@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
HeadersFrame frame = new HeadersFrame();
super.unmarshalFrame(state, frame);
byte flagsByte = state.getFrameHeaderData().getFlagsByte();
frame.setEndOfStream((flagsByte & 0x1) == 0x1);
frame.setEndHeaders((flagsByte & 0x4) == 0x4);
boolean isPadded = (flagsByte & 0x8) == 0x8;
PriorityDetails priorityDetails = null;
if ((flagsByte & 0x20) == 0x20) {
priorityDetails = new PriorityDetails();
frame.setPriorityDetails(priorityDetails);
}
DataSplit padSplit = PaddingUtil.extractPayloadAndPadding(isPadded, framePayloadData, frame.getStreamId());
frame.setPadding(padSplit.getPadding());
DataWrapper paddingStripped = padSplit.getPayload();
if (priorityDetails != null) {
//1 bit Exclusive flag, 31 bits stream dependency, and 8 bits weight = 5 bytes....
List<? extends DataWrapper> split = dataGen.split(paddingStripped, 5);
ByteBuffer preludeBytes = bufferPool.createWithDataWrapper(split.get(0));
int firstInt = preludeBytes.getInt();
priorityDetails.setStreamDependencyIsExclusive((firstInt >>> 31) == 0x1);
int streamDependency = firstInt & 0x7FFFFFFF;
if (streamDependency == frame.getStreamId()) {
// Can't depend on self
throw new ConnectionException(CancelReasonCode.BAD_STREAM_DEPENDENCY, streamDependency, "stream id=" + streamDependency + " depends on itself");
}
priorityDetails.setStreamDependency(streamDependency);
priorityDetails.setWeight((short) (preludeBytes.get() & 0xFF));
frame.setHeaderFragment(split.get(1));
bufferPool.releaseBuffer(preludeBytes);
} else {
frame.setHeaderFragment(paddingStripped);
}
if (frame.getStreamId() == 0)
throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "headers frame had invalid stream id=" + frame.getStreamId());
return frame;
}
use of com.webpieces.http2parser.api.dto.HeadersFrame in project webpieces by deanhiller.
the class HeadersMarshaller method marshal.
@Override
public DataWrapper marshal(Http2Frame frame) {
HeadersFrame castFrame = (HeadersFrame) frame;
if (frame.getStreamId() == 0)
throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "Headers frame cannot be streamId 0");
int paddingSize = castFrame.getPadding().getReadableSize();
byte value = 0x0;
if (castFrame.isEndOfStream())
value |= 0x1;
if (castFrame.isEndHeaders())
value |= 0x4;
if (paddingSize > 0)
value |= 0x8;
if (castFrame.isPriority())
value |= 0x20;
DataWrapper preludeDW;
PriorityDetails priorityDetails = castFrame.getPriorityDetails();
if (priorityDetails != null) {
preludeDW = PriorityMarshaller.marshalPriorityDetails(bufferPool, priorityDetails, frame);
} else {
preludeDW = dataGen.emptyWrapper();
}
DataWrapper unpadded = dataGen.chainDataWrappers(preludeDW, castFrame.getHeaderFragment());
DataWrapper payload = PaddingUtil.padDataIfNeeded(unpadded, castFrame.getPadding());
return super.marshalFrame(frame, value, payload);
}
use of com.webpieces.http2parser.api.dto.HeadersFrame 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.HeadersFrame in project webpieces by deanhiller.
the class HeaderEncoding method translateToFrames.
public List<Http2Frame> translateToFrames(long maxFrameSize, Encoder encoder, Http2Headers headers) {
HeadersFrame frame = new HeadersFrame();
frame.setStreamId(headers.getStreamId());
frame.setEndOfStream(headers.isEndOfStream());
frame.setPriorityDetails(headers.getPriorityDetails());
List<Http2Header> headerList = headers.getHeaders();
List<Http2Frame> headerFrames = toHeaderFrames(maxFrameSize, encoder, frame, headerList);
return headerFrames;
}
use of com.webpieces.http2parser.api.dto.HeadersFrame 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);
}
}
Aggregations