Search in sources :

Example 1 with Http2Setting

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

the class RemoteSettingsManagement method applyRemoteSettings.

public void applyRemoteSettings(SettingsFrame settings) {
    for (Http2Setting setting : settings.getSettings()) {
        SettingsParameter key = setting.getKnownName();
        if (key == null)
            //TODO: forward unknown settings to clients
            continue;
        //unknown setting so skip it
        apply(key, setting.getValue());
    }
}
Also used : SettingsParameter(com.webpieces.http2parser.api.dto.lib.SettingsParameter) Http2Setting(com.webpieces.http2parser.api.dto.lib.Http2Setting)

Example 2 with Http2Setting

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

the class HeaderSettings method createSettingsFrame.

public static SettingsFrame createSettingsFrame(HeaderSettings localSettings) {
    SettingsFrame f = new SettingsFrame();
    if (localSettings.getHeaderTableSize() != DEFAULT.getHeaderTableSize())
        f.addSetting(new Http2Setting(SettingsParameter.SETTINGS_HEADER_TABLE_SIZE, localSettings.getHeaderTableSize()));
    if (localSettings.isPushEnabled() != DEFAULT.isPushEnabled()) {
        long enabled = 1;
        if (!localSettings.isPushEnabled())
            enabled = 0;
        f.addSetting(new Http2Setting(SettingsParameter.SETTINGS_ENABLE_PUSH, enabled));
    }
    if (localSettings.getMaxConcurrentStreams() != DEFAULT.getMaxConcurrentStreams())
        f.addSetting(new Http2Setting(SettingsParameter.SETTINGS_MAX_CONCURRENT_STREAMS, localSettings.getMaxConcurrentStreams()));
    if (localSettings.getInitialWindowSize() != DEFAULT.getInitialWindowSize())
        f.addSetting(new Http2Setting(SettingsParameter.SETTINGS_INITIAL_WINDOW_SIZE, localSettings.getInitialWindowSize()));
    if (localSettings.getMaxFrameSize() != DEFAULT.getMaxFrameSize())
        f.addSetting(new Http2Setting(SettingsParameter.SETTINGS_MAX_FRAME_SIZE, localSettings.getMaxFrameSize()));
    if (localSettings.getMaxHeaderListSize() != DEFAULT.getMaxHeaderListSize())
        f.addSetting(new Http2Setting(SettingsParameter.SETTINGS_MAX_HEADER_LIST_SIZE, localSettings.getMaxHeaderListSize()));
    return f;
}
Also used : SettingsFrame(com.webpieces.http2parser.api.dto.SettingsFrame) Http2Setting(com.webpieces.http2parser.api.dto.lib.Http2Setting)

Example 3 with Http2Setting

use of com.webpieces.http2parser.api.dto.lib.Http2Setting 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 = dataGen.emptyWrapper();
    } else if (castFrame.getSettings().size() == 0) {
        dataPayload = dataGen.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.http2parser.api.dto.SettingsFrame) Http2Setting(com.webpieces.http2parser.api.dto.lib.Http2Setting) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with Http2Setting

use of com.webpieces.http2parser.api.dto.lib.Http2Setting 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.http2parser.api.dto.SettingsFrame) Http2Setting(com.webpieces.http2parser.api.dto.lib.Http2Setting) FrameHeaderData(com.webpieces.http2parser.impl.FrameHeaderData) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 5 with Http2Setting

use of com.webpieces.http2parser.api.dto.lib.Http2Setting 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.http2parser.api.dto.SettingsFrame) Http2Setting(com.webpieces.http2parser.api.dto.lib.Http2Setting) Test(org.junit.Test)

Aggregations

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