aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Becker2012-05-14 12:50:49 (EDT)
committerThomas Becker2012-05-14 12:50:49 (EDT)
commitfdf6dac1d38c0635bef326d8e987883f1a76b7c0 (patch)
treed48777f37a73130cefb29cbaf2c27f19148b8423
parent5687aa8beb51d2f347753cd9d9351c0d819664fb (diff)
downloadorg.eclipse.jetty.project-fdf6dac1d38c0635bef326d8e987883f1a76b7c0.zip
org.eclipse.jetty.project-fdf6dac1d38c0635bef326d8e987883f1a76b7c0.tar.gz
org.eclipse.jetty.project-fdf6dac1d38c0635bef326d8e987883f1a76b7c0.tar.bz2
spdy: no push if the main request contains if-modified-since headerrefs/changes/73/5973/1
-rw-r--r--jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ServerHTTPSPDYAsyncConnection.java9
-rw-r--r--jetty-spdy/spdy-jetty-http/src/test/java/org/eclipse/jetty/spdy/http/ReferrerPushStrategyTest.java105
2 files changed, 113 insertions, 1 deletions
diff --git a/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ServerHTTPSPDYAsyncConnection.java b/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ServerHTTPSPDYAsyncConnection.java
index cc24c8d..f82b3f0 100644
--- a/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ServerHTTPSPDYAsyncConnection.java
+++ b/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ServerHTTPSPDYAsyncConnection.java
@@ -393,7 +393,7 @@ public class ServerHTTPSPDYAsyncConnection extends AbstractHttpConnection implem
{
if (!stream.isUnidirectional())
stream.reply(replyInfo);
- if (replyInfo.getHeaders().get("status").value().startsWith("200") && !stream.isClosed())
+ if (replyInfo.getHeaders().get("status").value().startsWith("200") && !stream.isClosed() && !isIfModifiedSinceHeaderPresent())
{
// We have a 200 OK with some content to send
@@ -426,6 +426,13 @@ public class ServerHTTPSPDYAsyncConnection extends AbstractHttpConnection implem
}
}
+ private boolean isIfModifiedSinceHeaderPresent()
+ {
+ if (headers.get("if-modified-since") != null)
+ return true;
+ return false;
+ }
+
private Buffer consumeContent(long maxIdleTime) throws IOException, InterruptedException
{
while (true)
diff --git a/jetty-spdy/spdy-jetty-http/src/test/java/org/eclipse/jetty/spdy/http/ReferrerPushStrategyTest.java b/jetty-spdy/spdy-jetty-http/src/test/java/org/eclipse/jetty/spdy/http/ReferrerPushStrategyTest.java
index c362ae0..f18ff00 100644
--- a/jetty-spdy/spdy-jetty-http/src/test/java/org/eclipse/jetty/spdy/http/ReferrerPushStrategyTest.java
+++ b/jetty-spdy/spdy-jetty-http/src/test/java/org/eclipse/jetty/spdy/http/ReferrerPushStrategyTest.java
@@ -363,4 +363,109 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
Assert.assertTrue(mainStreamLatch.await(5, TimeUnit.SECONDS));
Assert.assertFalse(pushLatch.await(1, TimeUnit.SECONDS));
}
+
+ @Test
+ public void testRequestWithIfModifiedSinceHeaderPreventsPush() throws Exception
+ {
+ InetSocketAddress address = startHTTPServer(new AbstractHandler()
+ {
+ @Override
+ public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ {
+ String url = request.getRequestURI();
+ PrintWriter output = response.getWriter();
+ if (url.endsWith(".html"))
+ output.print("<html><head/><body>HELLO</body></html>");
+ else if (url.endsWith(".css"))
+ output.print("body { background: #FFF; }");
+ baseRequest.setHandled(true);
+ }
+ });
+ Session session1 = startClient(address, null);
+
+ final CountDownLatch mainResourceLatch = new CountDownLatch(1);
+ Headers mainRequestHeaders = new Headers();
+ mainRequestHeaders.put("method", "GET");
+ String mainResource = "/index.html";
+ mainRequestHeaders.put("url", mainResource);
+ mainRequestHeaders.put("version", "HTTP/1.1");
+ mainRequestHeaders.put("scheme", "http");
+ mainRequestHeaders.put("host", "localhost:" + connector.getLocalPort());
+ mainRequestHeaders.put("If-Modified-Since", "Tue, 27 Mar 2012 16:36:52 GMT");
+ session1.syn(new SynInfo(mainRequestHeaders, true), new StreamFrameListener.Adapter()
+ {
+ @Override
+ public void onData(Stream stream, DataInfo dataInfo)
+ {
+ dataInfo.consume(dataInfo.length());
+ if (dataInfo.isClose())
+ mainResourceLatch.countDown();
+ }
+ });
+ Assert.assertTrue(mainResourceLatch.await(5, TimeUnit.SECONDS));
+
+ final CountDownLatch associatedResourceLatch = new CountDownLatch(1);
+ Headers associatedRequestHeaders = new Headers();
+ associatedRequestHeaders.put("method", "GET");
+ associatedRequestHeaders.put("url", "/style.css");
+ associatedRequestHeaders.put("version", "HTTP/1.1");
+ associatedRequestHeaders.put("scheme", "http");
+ associatedRequestHeaders.put("host", "localhost:" + connector.getLocalPort());
+ associatedRequestHeaders.put("referer", "http://localhost:" + connector.getLocalPort() + mainResource);
+ session1.syn(new SynInfo(associatedRequestHeaders, true), new StreamFrameListener.Adapter()
+ {
+ @Override
+ public void onData(Stream stream, DataInfo dataInfo)
+ {
+ dataInfo.consume(dataInfo.length());
+ if (dataInfo.isClose())
+ associatedResourceLatch.countDown();
+ }
+ });
+ Assert.assertTrue(associatedResourceLatch.await(5, TimeUnit.SECONDS));
+
+ // Create another client, and perform the same request for the main resource, we expect the css NOT being pushed as the main request contains an
+ // if-modified-since header
+
+ final CountDownLatch mainStreamLatch = new CountDownLatch(2);
+ final CountDownLatch pushDataLatch = new CountDownLatch(1);
+ Session session2 = startClient(address, new SessionFrameListener.Adapter()
+ {
+ @Override
+ public StreamFrameListener onSyn(Stream stream, SynInfo synInfo)
+ {
+ Assert.assertTrue(stream.isUnidirectional());
+ return new StreamFrameListener.Adapter()
+ {
+ @Override
+ public void onData(Stream stream, DataInfo dataInfo)
+ {
+ dataInfo.consume(dataInfo.length());
+ if (dataInfo.isClose())
+ pushDataLatch.countDown();
+ }
+ };
+ }
+ });
+ session2.syn(new SynInfo(mainRequestHeaders, true), new StreamFrameListener.Adapter()
+ {
+ @Override
+ public void onReply(Stream stream, ReplyInfo replyInfo)
+ {
+ Assert.assertFalse(replyInfo.isClose());
+ mainStreamLatch.countDown();
+ }
+
+ @Override
+ public void onData(Stream stream, DataInfo dataInfo)
+ {
+ dataInfo.consume(dataInfo.length());
+ if (dataInfo.isClose())
+ mainStreamLatch.countDown();
+ }
+ });
+
+ Assert.assertTrue(mainStreamLatch.await(5, TimeUnit.SECONDS));
+ Assert.assertFalse("We don't expect data to be pushed as the main request contained an if-modified-since header",pushDataLatch.await(1, TimeUnit.SECONDS));
+ }
}