Search in sources :

Example 16 with Http2Msg

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

Example 17 with Http2Msg

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

the class TestSMaxConcurrentSetting method testSend2ndPushHeadersOnlyOnCompletionOfFirst.

@Test
public void testSend2ndPushHeadersOnlyOnCompletionOfFirst() throws InterruptedException, ExecutionException, TimeoutException {
    WriterHolder sent = sendTwoRequests();
    DataFrame data1 = Http2Requests.createData1(sent.getResp1().getStreamId(), true);
    // ending this promise stream starts the next
    sent.getWriter1().processPiece(data1);
    List<Http2Msg> frames = mockChannel.getFramesAndClear();
    Assert.assertEquals(2, frames.size());
    Assert.assertEquals(sent.getResp2(), frames.get(0));
    DataFrame dataRecv1 = (DataFrame) frames.get(1);
    Assert.assertEquals(sent.getResp1().getStreamId(), dataRecv1.getStreamId());
    StreamWriter writer2 = sent.getFuture2().get(2, TimeUnit.SECONDS);
    DataFrame data2 = Http2Requests.createData1(sent.getResp2().getStreamId(), true);
    writer2.processPiece(data2);
    DataFrame dataRecv2 = (DataFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(sent.getResp2().getStreamId(), dataRecv2.getStreamId());
}
Also used : StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) Test(org.junit.Test)

Example 18 with Http2Msg

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

the class TestSMaxConcurrentSetting method testSend2ndPushHeadersOnlyOnAfterSettingsFrameMaxConcurrentBigger.

@Test
public void testSend2ndPushHeadersOnlyOnAfterSettingsFrameMaxConcurrentBigger() throws InterruptedException, ExecutionException, TimeoutException {
    WriterHolder sent = sendTwoRequests();
    // client increases max concurrent
    HeaderSettings settings = new HeaderSettings();
    settings.setMaxConcurrentStreams(2L);
    mockChannel.send(HeaderSettings.createSettingsFrame(settings));
    List<Http2Msg> frames = mockChannel.getFramesAndClear();
    Assert.assertEquals(2, frames.size());
    Assert.assertEquals(sent.getResp2(), frames.get(0));
    SettingsFrame dataRecv1 = (SettingsFrame) frames.get(1);
    Assert.assertTrue(dataRecv1.isAck());
    StreamWriter writer2 = sent.getFuture2().get(2, TimeUnit.SECONDS);
    DataFrame data2 = Http2Requests.createData1(sent.getResp2().getStreamId(), true);
    writer2.processPiece(data2);
    DataFrame dataRecv2 = (DataFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(sent.getResp2().getStreamId(), dataRecv2.getStreamId());
}
Also used : SettingsFrame(com.webpieces.http2.api.dto.lowlevel.SettingsFrame) HeaderSettings(com.webpieces.http2engine.impl.shared.data.HeaderSettings) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) Test(org.junit.Test)

Example 19 with Http2Msg

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

the class TestC3InitialHttpConnections 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() {
    // verify settings on connect were sent
    List<Http2Msg> frames = mockChannel.getFramesAndClear();
    Preface preface = (Preface) frames.get(0);
    preface.verify();
    Http2Msg settings1 = frames.get(1);
    Assert.assertEquals(HeaderSettings.createSettingsFrame(localSettings), settings1);
    // server's settings frame is finally coming in as well with maxConcurrent=1
    HeaderSettings settings = new HeaderSettings();
    settings.setMaxConcurrentStreams(1L);
    mockChannel.write(HeaderSettings.createSettingsFrame(settings));
    // ack client frame
    mockChannel.write(new SettingsFrame(true));
    SettingsFrame clientAck = (SettingsFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(true, clientAck.isAck());
}
Also used : SettingsFrame(com.webpieces.http2.api.dto.lowlevel.SettingsFrame) HeaderSettings(com.webpieces.http2engine.impl.shared.data.HeaderSettings) Preface(org.webpieces.http2client.mock.Preface) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) Test(org.junit.Test)

Example 20 with Http2Msg

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

the class TestCMaxConcurrentSetting method testSend2ndRequestOnlyOnAfterSettingsFrameMaxConcurrentBigger.

@Test
public void testSend2ndRequestOnlyOnAfterSettingsFrameMaxConcurrentBigger() throws InterruptedException, ExecutionException {
    RequestsSent sent = sendTwoRequests();
    Assert.assertFalse(sent.getRequest2().getFuture().isDone());
    // server's settings frame is finally coming in as well with maxConcurrent=1
    HeaderSettings settings = new HeaderSettings();
    settings.setMaxConcurrentStreams(2L);
    mockChannel.write(HeaderSettings.createSettingsFrame(settings));
    // ack client frame
    mockChannel.write(new SettingsFrame(true));
    List<Http2Msg> msgs = mockChannel.getFramesAndClear();
    Assert.assertEquals(sent.getRequest2().getRequest(), msgs.get(0));
    Assert.assertTrue(sent.getRequest2().getFuture().isDone());
    SettingsFrame ack = (SettingsFrame) msgs.get(1);
    Assert.assertEquals(true, ack.isAck());
}
Also used : SettingsFrame(com.webpieces.http2.api.dto.lowlevel.SettingsFrame) HeaderSettings(com.webpieces.http2engine.impl.shared.data.HeaderSettings) RequestsSent(org.webpieces.http2client.util.RequestsSent) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) Test(org.junit.Test)

Aggregations

Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)27 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)12 Test (org.junit.Test)12 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)8 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)8 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)7 DataWrapper (org.webpieces.data.api.DataWrapper)7 XFuture (org.webpieces.util.futures.XFuture)7 HeaderSettings (com.webpieces.http2engine.impl.shared.data.HeaderSettings)6 SettingsFrame (com.webpieces.http2.api.dto.lowlevel.SettingsFrame)5 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)4 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)4 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)3 Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)3 Http2Trailers (com.webpieces.http2.api.dto.highlevel.Http2Trailers)3 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)3 UnmarshalState (com.webpieces.hpack.api.UnmarshalState)2 CancelReasonCode (com.webpieces.http2.api.dto.error.CancelReasonCode)2 StreamException (com.webpieces.http2.api.dto.error.StreamException)2 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)2