use of com.webpieces.http2parser.api.dto.error.ConnectionException 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.error.ConnectionException in project webpieces by deanhiller.
the class HpackParserImpl method processFrame.
private void processFrame(UnmarshalStateImpl state, Http2Frame frame) {
List<HasHeaderFragment> headerFragList = state.getHeadersToCombine();
if (frame instanceof HasHeaderFragment) {
HasHeaderFragment headerFrame = (HasHeaderFragment) frame;
headerFragList.add(headerFrame);
validateHeader(state, headerFrame);
if (headerFrame.isEndHeaders())
combineAndSendHeadersToClient(state);
return;
} else if (headerFragList.size() > 0) {
throw new ConnectionException(CancelReasonCode.HEADERS_MIXED_WITH_FRAMES, state.getLogId(), frame.getStreamId(), "Parser in the middle of accepting headers(spec " + "doesn't allow frames between header fragments). frame=" + frame + " list=" + headerFragList);
}
if (frame instanceof UnknownFrame && ignoreUnkownFrames) {
//do nothing
} else if (frame instanceof Http2Msg) {
state.getParsedFrames().add((Http2Msg) frame);
} else {
throw new IllegalStateException("bug forgot support for frame=" + frame);
}
}
use of com.webpieces.http2parser.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class HeaderDecoding method decodeImpl.
private List<Http2Header> decodeImpl(UnmarshalStateImpl state, DataWrapper data, int streamId, Consumer<Http2Header> knownHeaders) throws IOException {
List<Http2Header> headers = new ArrayList<>();
byte[] bytes = data.createByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
Decoder decoder = state.getDecoder();
//TODO(dhiller): make this an async syncrhonized block instead so threads can keep running!!!
synchronized (decoder) {
decoder.decode(in, (n, v, s) -> addToHeaders(headers, knownHeaders, n, v, s, state.getLogId(), streamId));
decoder.endHeaderBlock();
}
if (data.getReadableSize() > 0 && headers.size() == 0)
throw new ConnectionException(CancelReasonCode.COMPRESSION_ERROR, state.getLogId(), streamId, "Header data came in, but no headers came out");
return headers;
}
use of com.webpieces.http2parser.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class DataMarshaller method unmarshal.
@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
DataFrame frame = new DataFrame();
super.unmarshalFrame(state, frame);
byte flags = state.getFrameHeaderData().getFlagsByte();
frame.setEndOfStream((flags & 0x1) == 0x1);
boolean isPadded = (flags & 0x8) == 0x8;
DataSplit split = PaddingUtil.extractPayloadAndPadding(isPadded, framePayloadData, frame.getStreamId());
frame.setData(split.getPayload());
frame.setPadding(split.getPadding());
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.error.ConnectionException in project webpieces by deanhiller.
the class DataMarshaller method marshal.
@Override
public DataWrapper marshal(Http2Frame frame) {
DataFrame castFrame = (DataFrame) frame;
int paddingSize = castFrame.getPadding().getReadableSize();
if (frame.getStreamId() == 0)
throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "data frame had invalid stream id=" + frame.getStreamId());
byte value = (byte) 0x0;
if (castFrame.isEndOfStream())
value |= 0x1;
if (paddingSize > 0)
value |= 0x8;
DataWrapper dataPayload = PaddingUtil.padDataIfNeeded(castFrame.getData(), castFrame.getPadding());
return super.marshalFrame(frame, value, dataPayload);
}
Aggregations