Search in sources :

Example 6 with Http2Setting

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Setting 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);
    }
}
Also used : SettingsParameter(com.webpieces.http2.api.dto.lowlevel.lib.SettingsParameter) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 7 with Http2Setting

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Setting in project webpieces by deanhiller.

the class SettingsMarshaller method unmarshal.

private List<Http2Setting> unmarshal(ByteBuffer payloadByteBuffer) {
    List<Http2Setting> settings = new ArrayList<>();
    while (payloadByteBuffer.hasRemaining()) {
        int id = UnsignedData.getUnsignedShort(payloadByteBuffer);
        long value = UnsignedData.getUnsignedInt(payloadByteBuffer);
        Http2Setting http2Setting = new Http2Setting(id, value);
        settings.add(http2Setting);
        validate(http2Setting);
    }
    return settings;
}
Also used : Http2Setting(com.webpieces.http2.api.dto.lowlevel.lib.Http2Setting) ArrayList(java.util.ArrayList)

Example 8 with Http2Setting

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Setting in project webpieces by deanhiller.

the class SettingsMarshaller method marshalOut.

private DataWrapper marshalOut(List<Http2Setting> settings) {
    DataWrapper dataPayload;
    ByteBuffer payload = bufferPool.nextBuffer(6 * settings.size());
    for (Http2Setting setting : settings) {
        UnsignedData.putUnsignedShort(payload, setting.getId());
        UnsignedData.putUnsignedInt(payload, setting.getValue());
    }
    payload.flip();
    dataPayload = DATA_GEN.wrapByteBuffer(payload);
    return dataPayload;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Http2Setting(com.webpieces.http2.api.dto.lowlevel.lib.Http2Setting) ByteBuffer(java.nio.ByteBuffer)

Example 9 with Http2Setting

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Setting in project webpieces by deanhiller.

the class TestHttp2Settings method testParseSettings.

@Test
public void testParseSettings() {
    DataWrapper data = Util.hexToBytes(basicSettings());
    parser.parse(memento, data);
    SettingsFrame frame = (SettingsFrame) assertGood();
    Assert.assertEquals(0, frame.getStreamId());
    Assert.assertFalse(frame.isAck());
    Assert.assertEquals(frame.getSettings().size(), 2);
    Http2Setting setting = frame.getSettings().get(0);
    // first setting must be push from order in the bytes
    Assert.assertEquals(SettingsParameter.SETTINGS_ENABLE_PUSH, setting.getKnownName());
    Assert.assertEquals(1, setting.getValue());
}
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) Test(org.junit.Test)

Aggregations

Http2Setting (com.webpieces.http2.api.dto.lowlevel.lib.Http2Setting)8 SettingsFrame (com.webpieces.http2.api.dto.lowlevel.SettingsFrame)5 DataWrapper (org.webpieces.data.api.DataWrapper)3 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)2 SettingsParameter (com.webpieces.http2.api.dto.lowlevel.lib.SettingsParameter)2 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 FrameHeaderData (com.webpieces.http2parser.impl.FrameHeaderData)1 List (java.util.List)1