Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/AbstractTest.java4
-rw-r--r--jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/PushCacheFilterTest.java91
-rw-r--r--jetty-servlets/src/main/java/org/eclipse/jetty/servlets/PushCacheFilter.java2
3 files changed, 91 insertions, 6 deletions
diff --git a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/AbstractTest.java b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/AbstractTest.java
index 0c1e174042..62a0608abf 100644
--- a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/AbstractTest.java
+++ b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/AbstractTest.java
@@ -122,12 +122,8 @@ public class AbstractTest
public void dispose() throws Exception
{
if (client != null)
- {
client.stop();
- }
if (server != null)
- {
server.stop();
- }
}
}
diff --git a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/PushCacheFilterTest.java b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/PushCacheFilterTest.java
index 907bd4ebdc..8907abb7c5 100644
--- a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/PushCacheFilterTest.java
+++ b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/PushCacheFilterTest.java
@@ -80,7 +80,7 @@ public class PushCacheFilterTest extends AbstractTest
final Session session = newClient(new Session.Listener.Adapter());
// Request for the primary and secondary resource to build the cache.
- final String primaryURI = "http://localhost:" + connector.getLocalPort() + servletPath + primaryResource;
+ final String referrerURI = "http://localhost:" + connector.getLocalPort() + servletPath + primaryResource;
HttpFields primaryFields = new HttpFields();
MetaData.Request primaryRequest = newRequest("GET", primaryResource, primaryFields);
final CountDownLatch warmupLatch = new CountDownLatch(1);
@@ -94,7 +94,7 @@ public class PushCacheFilterTest extends AbstractTest
{
// Request for the secondary resource.
HttpFields secondaryFields = new HttpFields();
- secondaryFields.put(HttpHeader.REFERER, primaryURI);
+ secondaryFields.put(HttpHeader.REFERER, referrerURI);
MetaData.Request secondaryRequest = newRequest("GET", secondaryResource, secondaryFields);
session.newStream(new HeadersFrame(0, secondaryRequest, null, true), new Promise.Adapter<>(), new Stream.Listener.Adapter()
{
@@ -143,6 +143,93 @@ public class PushCacheFilterTest extends AbstractTest
}
@Test
+ public void testPushReferrerNoPath() throws Exception
+ {
+ final String primaryResource = "/primary.html";
+ final String secondaryResource = "/secondary.png";
+ final byte[] secondaryData = "SECONDARY".getBytes("UTF-8");
+ start(new HttpServlet()
+ {
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ {
+ String requestURI = req.getRequestURI();
+ ServletOutputStream output = resp.getOutputStream();
+ if (requestURI.endsWith(primaryResource))
+ output.print("<html><head></head><body>PRIMARY</body></html>");
+ else if (requestURI.endsWith(secondaryResource))
+ output.write(secondaryData);
+ }
+ });
+
+ final Session session = newClient(new Session.Listener.Adapter());
+
+ // Request for the primary and secondary resource to build the cache.
+ // The referrerURI does not point to the primary resource, so there will be no
+ // resource association with the primary resource and therefore won't be pushed.
+ final String referrerURI = "http://localhost:" + connector.getLocalPort();
+ HttpFields primaryFields = new HttpFields();
+ MetaData.Request primaryRequest = newRequest("GET", primaryResource, primaryFields);
+ final CountDownLatch warmupLatch = new CountDownLatch(1);
+ session.newStream(new HeadersFrame(0, primaryRequest, null, true), new Promise.Adapter<>(), new Stream.Listener.Adapter()
+ {
+ @Override
+ public void onData(Stream stream, DataFrame frame, Callback callback)
+ {
+ callback.succeeded();
+ if (frame.isEndStream())
+ {
+ // Request for the secondary resource.
+ HttpFields secondaryFields = new HttpFields();
+ secondaryFields.put(HttpHeader.REFERER, referrerURI);
+ MetaData.Request secondaryRequest = newRequest("GET", secondaryResource, secondaryFields);
+ session.newStream(new HeadersFrame(0, secondaryRequest, null, true), new Promise.Adapter<>(), new Stream.Listener.Adapter()
+ {
+ @Override
+ public void onData(Stream stream, DataFrame frame, Callback callback)
+ {
+ warmupLatch.countDown();
+ }
+ });
+ }
+ }
+ });
+ Assert.assertTrue(warmupLatch.await(5, TimeUnit.SECONDS));
+
+ // Request again the primary resource, we should not get the secondary resource pushed.
+ primaryRequest = newRequest("GET", primaryResource, primaryFields);
+ final CountDownLatch primaryResponseLatch = new CountDownLatch(1);
+ final CountDownLatch pushLatch = new CountDownLatch(1);
+ session.newStream(new HeadersFrame(0, primaryRequest, null, true), new Promise.Adapter<>(), new Stream.Listener.Adapter()
+ {
+ @Override
+ public Stream.Listener onPush(Stream stream, PushPromiseFrame frame)
+ {
+ return new Adapter()
+ {
+ @Override
+ public void onData(Stream stream, DataFrame frame, Callback callback)
+ {
+ callback.succeeded();
+ if (frame.isEndStream())
+ pushLatch.countDown();
+ }
+ };
+ }
+
+ @Override
+ public void onData(Stream stream, DataFrame frame, Callback callback)
+ {
+ callback.succeeded();
+ if (frame.isEndStream())
+ primaryResponseLatch.countDown();
+ }
+ });
+ Assert.assertFalse(pushLatch.await(1, TimeUnit.SECONDS));
+ Assert.assertTrue(primaryResponseLatch.await(5, TimeUnit.SECONDS));
+ }
+
+ @Test
public void testPushIsReset() throws Exception
{
final String primaryResource = "/primary.html";
diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/PushCacheFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/PushCacheFilter.java
index 9928eb2b4e..d6710d74db 100644
--- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/PushCacheFilter.java
+++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/PushCacheFilter.java
@@ -173,6 +173,8 @@ public class PushCacheFilter implements Filter
if ("GET".equalsIgnoreCase(request.getMethod()))
{
String referrerPath = referrerURI.getPath();
+ if (referrerPath == null)
+ referrerPath = "/";
if (referrerPath.startsWith(request.getContextPath()))
{
String referrerPathNoContext = referrerPath.substring(request.getContextPath().length());

Back to the top