Search in sources :

Example 1 with SettingsFrame

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;
}
Also used : SettingsFrame(com.webpieces.http2.api.dto.lowlevel.SettingsFrame) Http2Setting(com.webpieces.http2.api.dto.lowlevel.lib.Http2Setting) FrameHeaderData(com.webpieces.http2parser.impl.FrameHeaderData) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 2 with SettingsFrame

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);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) SettingsFrame(com.webpieces.http2.api.dto.lowlevel.SettingsFrame) Http2Setting(com.webpieces.http2.api.dto.lowlevel.lib.Http2Setting) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with SettingsFrame

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);
}
Also used : SettingsFrame(com.webpieces.http2.api.dto.lowlevel.SettingsFrame) Http2Setting(com.webpieces.http2.api.dto.lowlevel.lib.Http2Setting) Test(org.junit.Test)

Example 4 with SettingsFrame

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);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) SettingsFrame(com.webpieces.http2.api.dto.lowlevel.SettingsFrame) Test(org.junit.Test)

Example 5 with SettingsFrame

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());
}
Also used : SettingsFrame(com.webpieces.http2.api.dto.lowlevel.SettingsFrame)

Aggregations

SettingsFrame (com.webpieces.http2.api.dto.lowlevel.SettingsFrame)14 Test (org.junit.Test)8 Http2Setting (com.webpieces.http2.api.dto.lowlevel.lib.Http2Setting)6 HeaderSettings (com.webpieces.http2engine.impl.shared.data.HeaderSettings)5 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)4 DataWrapper (org.webpieces.data.api.DataWrapper)3 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)1 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)1 SettingsParameter (com.webpieces.http2.api.dto.lowlevel.lib.SettingsParameter)1 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)1 FrameHeaderData (com.webpieces.http2parser.impl.FrameHeaderData)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Preface (org.webpieces.http2client.mock.Preface)1 RequestsSent (org.webpieces.http2client.util.RequestsSent)1