use of com.webpieces.http2.api.dto.error.ConnectionException 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 = DATA_GEN.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;
}
use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class HpackParserImpl method processFrameImpl.
private void processFrameImpl(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.addParsedMessage((Http2Msg) frame);
} else {
throw new IllegalStateException("bug forgot support for frame=" + frame);
}
}
use of com.webpieces.http2.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.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class ResponseListener method failure.
@Override
public void failure(Throwable e) {
ConnectionCancelled connCancelled = new ConnectionFailure(new ConnectionException(CancelReasonCode.BUG, logId, 0, "Failure from connection", e));
responseListener.cancel(new ShutdownStream(0, connCancelled));
}
use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class SettingsMarshaller method validate.
private void validate(Http2Setting http2Setting) {
SettingsParameter key = SettingsParameter.lookup(http2Setting.getId());
long value = http2Setting.getValue();
if (key == null)
// unknown setting
return;
switch(key) {
case SETTINGS_ENABLE_PUSH:
if (value != 0 && value != 1)
throw new ConnectionException(CancelReasonCode.INVALID_SETTING, 0, "push setting must be 0 or 1 but was=" + value);
break;
case SETTINGS_INITIAL_WINDOW_SIZE:
validateWindowSize(value);
break;
case SETTINGS_MAX_FRAME_SIZE:
validateMaxFrameSize(value);
break;
case SETTINGS_HEADER_TABLE_SIZE:
case SETTINGS_MAX_CONCURRENT_STREAMS:
case SETTINGS_MAX_HEADER_LIST_SIZE:
break;
default:
throw new IllegalArgumentException("case statement missing new setting=" + key + " with value=" + value);
}
}
Aggregations