Search in sources :

Example 1 with Preface

use of org.webpieces.http2client.mock.Preface 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.http2parser.api.dto.SettingsFrame) HeaderSettings(com.webpieces.http2engine.impl.shared.data.HeaderSettings) Preface(org.webpieces.http2client.mock.Preface) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) Test(org.junit.Test)

Example 2 with Preface

use of org.webpieces.http2client.mock.Preface in project webpieces by deanhiller.

the class TestC3InitialHttpsConnections method setUp.

@Before
public void setUp() throws InterruptedException, ExecutionException {
    mockChannel.setIncomingFrameDefaultReturnValue(CompletableFuture.completedFuture(mockChannel));
    Http2Config config = new Http2Config();
    //start with 1 max concurrent
    config.setInitialRemoteMaxConcurrent(1);
    config.setLocalSettings(localSettings);
    InjectionConfig injConfig = new InjectionConfig(mockTime, config);
    Http2Client client = Http2ClientFactory.createHttpClient(mockChanMgr, injConfig);
    mockChanMgr.addSSLChannelToReturn(mockChannel);
    InetSocketAddress addr = new InetSocketAddress("somehost.com", 555);
    String host = addr.getHostName();
    int port = addr.getPort();
    ForTestSslClientEngineFactory ssl = new ForTestSslClientEngineFactory();
    SSLEngine engine = ssl.createSslEngine(host, port);
    socket = client.createHttpsSocket("simple", engine);
    CompletableFuture<Http2Socket> connect = socket.connect(addr);
    Assert.assertTrue(connect.isDone());
    Assert.assertEquals(socket, connect.get());
    //verify settings on connect were sent
    //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);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SSLEngine(javax.net.ssl.SSLEngine) ForTestSslClientEngineFactory(org.webpieces.http2client.integ.ForTestSslClientEngineFactory) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) Http2Config(com.webpieces.http2engine.api.client.Http2Config) Http2Socket(org.webpieces.http2client.api.Http2Socket) Preface(org.webpieces.http2client.mock.Preface) Http2Client(org.webpieces.http2client.api.Http2Client) Before(org.junit.Before)

Aggregations

Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)2 Preface (org.webpieces.http2client.mock.Preface)2 Http2Config (com.webpieces.http2engine.api.client.Http2Config)1 InjectionConfig (com.webpieces.http2engine.api.client.InjectionConfig)1 HeaderSettings (com.webpieces.http2engine.impl.shared.data.HeaderSettings)1 SettingsFrame (com.webpieces.http2parser.api.dto.SettingsFrame)1 InetSocketAddress (java.net.InetSocketAddress)1 SSLEngine (javax.net.ssl.SSLEngine)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Http2Client (org.webpieces.http2client.api.Http2Client)1 Http2Socket (org.webpieces.http2client.api.Http2Socket)1 ForTestSslClientEngineFactory (org.webpieces.http2client.integ.ForTestSslClientEngineFactory)1