Search in sources :

Example 6 with SettingsFrame

use of com.webpieces.http2.api.dto.lowlevel.SettingsFrame 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.http2.api.dto.lowlevel.lib.SettingsParameter) Http2Setting(com.webpieces.http2.api.dto.lowlevel.lib.Http2Setting)

Example 7 with SettingsFrame

use of com.webpieces.http2.api.dto.lowlevel.SettingsFrame 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.http2.api.dto.lowlevel.SettingsFrame) Http2Setting(com.webpieces.http2.api.dto.lowlevel.lib.Http2Setting)

Example 8 with SettingsFrame

use of com.webpieces.http2.api.dto.lowlevel.SettingsFrame 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)

Example 9 with SettingsFrame

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

the class TestHttp2Settings method testMarshalAck.

@Test
public void testMarshalAck() {
    SettingsFrame frame = new SettingsFrame();
    frame.setAck(true);
    byte[] data = parser.marshal(frame).createByteArray();
    String hexFrame = Util.toHexString(data);
    Assert.assertEquals(ackFrame(), hexFrame);
}
Also used : SettingsFrame(com.webpieces.http2.api.dto.lowlevel.SettingsFrame) Test(org.junit.Test)

Example 10 with SettingsFrame

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

the class TestS3InitialHttpConnections method testSection3_4WithH2cTokenPriorKnowledge.

/**
 * Only will work with webpieces and 'jetty with alpn installed'
 *
 * should send PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n
 * and server sends back it's preface...
 * The server connection preface consists of a potentially empty SETTINGS
 * frame (Section 6.5) that MUST be the first frame the server sends in the HTTP/2 connection.
 *
 * SettingsFrame{streamId=0, ack=false, settings=[{SETTINGS_HEADER_TABLE_SIZE: 4096}, {SETTINGS_MAX_CONCURRENT_STREAMS: 1024}, {SETTINGS_INITIAL_WINDOW_SIZE: 65535}, {SETTINGS_MAX_HEADER_LIST_SIZE: 8192}]}
 * SettingsFrame{streamId=0, ack=true, settings=[]}
 */
@Test
public void testSection3_4WithH2cTokenPriorKnowledge() {
    HeaderSettings settings = Http2Requests.createSomeSettings();
    mockChannel.sendPrefaceAndSettings(HeaderSettings.createSettingsFrame(settings));
    List<Http2Msg> frames = mockChannel.getFramesAndClear();
    Assert.assertEquals(2, frames.size());
    SettingsFrame serverSettings = (SettingsFrame) frames.get(0);
    Assert.assertFalse(serverSettings.isAck());
    SettingsFrame ackClientSettings = (SettingsFrame) frames.get(1);
    Assert.assertTrue(ackClientSettings.isAck());
}
Also used : SettingsFrame(com.webpieces.http2.api.dto.lowlevel.SettingsFrame) HeaderSettings(com.webpieces.http2engine.impl.shared.data.HeaderSettings) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) Test(org.junit.Test)

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