use of com.webpieces.http2.api.dto.lowlevel.SettingsFrame in project webpieces by deanhiller.
the class SettingsMarshaller method unmarshal.
@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper payload) {
FrameHeaderData frameHeaderData = state.getFrameHeaderData();
int payloadLength = frameHeaderData.getPayloadLength();
int streamId = frameHeaderData.getStreamId();
SettingsFrame frame = new SettingsFrame();
super.unmarshalFrame(state, frame);
byte flags = state.getFrameHeaderData().getFlagsByte();
frame.setAck((flags & 0x1) == 0x1);
if (frame.isAck()) {
if (payloadLength != 0) {
throw new ConnectionException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "size of payload of a settings frame ack must be 0 but was=" + payloadLength);
}
} else if (payloadLength % 6 != 0) {
throw new ConnectionException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "payload size must be a multiple of 6 but was=" + state.getFrameHeaderData().getPayloadLength());
} else if (streamId != 0)
throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, streamId, "settings frame had stream id=" + streamId);
ByteBuffer payloadByteBuffer = bufferPool.createWithDataWrapper(payload);
List<Http2Setting> settingsList = unmarshal(payloadByteBuffer);
frame.setSettings(settingsList);
bufferPool.releaseBuffer(payloadByteBuffer);
return frame;
}
use of com.webpieces.http2.api.dto.lowlevel.SettingsFrame in project webpieces by deanhiller.
the class SettingsMarshaller method marshal.
@Override
public DataWrapper marshal(Http2Frame frame) {
if (frame.getStreamId() != 0)
throw new IllegalArgumentException("SettingsFrame can never be any other stream id except 0 which is already set");
SettingsFrame castFrame = (SettingsFrame) frame;
for (Http2Setting setting : castFrame.getSettings()) {
validate(setting);
}
byte flags = 0x0;
if (castFrame.isAck())
flags |= 0x1;
DataWrapper dataPayload;
if (castFrame.isAck()) {
if (castFrame.getSettings() != null && castFrame.getSettings().size() > 0)
throw new IllegalArgumentException("Ack SettingsFrame can not have setting in it");
dataPayload = DATA_GEN.emptyWrapper();
} else if (castFrame.getSettings().size() == 0) {
dataPayload = DATA_GEN.emptyWrapper();
} else {
List<Http2Setting> settings = castFrame.getSettings();
dataPayload = marshalOut(settings);
}
return super.marshalFrame(frame, flags, dataPayload);
}
use of com.webpieces.http2.api.dto.lowlevel.SettingsFrame in project webpieces by deanhiller.
the class TestHttp2Settings method testMarshalSettings.
@Test
public void testMarshalSettings() {
SettingsFrame frame = new SettingsFrame();
frame.addSetting(new Http2Setting(SettingsParameter.SETTINGS_ENABLE_PUSH, 1L));
frame.addSetting(new Http2Setting(SettingsParameter.SETTINGS_MAX_CONCURRENT_STREAMS, 256L));
byte[] data = parser.marshal(frame).createByteArray();
String hexFrame = Util.toHexString(data);
Assert.assertEquals(basicSettings(), hexFrame);
}
use of com.webpieces.http2.api.dto.lowlevel.SettingsFrame in project webpieces by deanhiller.
the class TestHttp2Settings method testParseAck.
@Test
public void testParseAck() {
DataWrapper data = Util.hexToBytes(ackFrame());
parser.parse(memento, data);
SettingsFrame frame = (SettingsFrame) assertGood();
Assert.assertEquals(0, frame.getStreamId());
Assert.assertTrue(frame.isAck());
Assert.assertEquals(frame.getSettings().size(), 0);
}
use of com.webpieces.http2.api.dto.lowlevel.SettingsFrame in project webpieces by deanhiller.
the class TestS6x5SettingsFrameErrors method simulateClientSendingPrefaceAndSettings.
@Override
protected void simulateClientSendingPrefaceAndSettings() {
// null out the settings stuff
mockChannel.sendPreface();
SettingsFrame settings = (SettingsFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(0, settings.getStreamId());
}
Aggregations