@Before public void setUp() throws Exception { serverAddress = createServer(); pushStrategy = new ReferrerPushStrategy(); pushStrategy.setReferrerPushPeriod(referrerPushPeriod); defaultFactory = new HTTPSPDYServerConnectionFactory(version, new HttpConfiguration(), pushStrategy); connector.addConnectionFactory(defaultFactory); if (connector.getConnectionFactory(NPNServerConnectionFactory.class) != null) connector .getConnectionFactory(NPNServerConnectionFactory.class) .setDefaultProtocol(defaultFactory.getProtocol()); else connector.setDefaultProtocol(defaultFactory.getProtocol()); mainRequestHeaders = createHeadersWithoutReferrer(mainResource); associatedCSSRequestHeaders = createHeaders(cssResource); associatedJSRequestHeaders = createHeaders("/application.js"); }
@Test public void testMaxAssociatedResources() throws Exception { pushStrategy.setMaxAssociatedResources(1); connector.addConnectionFactory(defaultFactory); connector.setDefaultProtocol(defaultFactory.getProtocol()); // TODO I don't think this is right Session session = sendMainRequestAndCSSRequest(null); sendRequest(session, associatedJSRequestHeaders, null, null); run2ndClientRequests(false, true); }
protected InetSocketAddress startServer(short version, ServerSessionFrameListener listener) throws Exception { if (server == null) server = newServer(); if (connector == null) connector = newSPDYServerConnector(server, listener); if (listener == null) listener = connector .getConnectionFactory(SPDYServerConnectionFactory.class) .getServerSessionFrameListener(); ConnectionFactory spdy = new SPDYServerConnectionFactory(version, listener); connector.addConnectionFactory(spdy); connector.setPort(0); server.addConnector(connector); if (connector.getConnectionFactory(NPNServerConnectionFactory.class) != null) connector .getConnectionFactory(NPNServerConnectionFactory.class) .setDefaultProtocol(spdy.getProtocol()); else connector.setDefaultProtocol(spdy.getProtocol()); server.start(); return new InetSocketAddress("localhost", connector.getLocalPort()); }
@Override public Connection newConnection(Connector connector, EndPoint endPoint) { final Connection connection = connectionFactory.newConnection(connector, endPoint); connection.addListener( new Connection.Listener() { private Timer.Context context; @Override public void onOpened(Connection connection) { this.context = timer.time(); } @Override public void onClosed(Connection connection) { context.stop(); } }); return connection; }
@Override public List<String> getProtocols() { return connectionFactory.getProtocols(); }
@Override public String getProtocol() { return connectionFactory.getProtocol(); }