diff --git a/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ReferrerPushStrategy.java b/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ReferrerPushStrategy.java index 6070f1c1dc3..0d7857f931a 100644 --- a/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ReferrerPushStrategy.java +++ b/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ReferrerPushStrategy.java @@ -24,6 +24,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; import java.util.regex.Pattern; import org.eclipse.jetty.spdy.api.Headers; @@ -213,17 +214,23 @@ public class ReferrerPushStrategy implements PushStrategy private class MainResource { private final String name; - private final long created = System.nanoTime(); private final Set resources = Collections.newSetFromMap(new ConcurrentHashMap()); + private final AtomicLong firstResourceAdded = new AtomicLong(-1); - MainResource(String name) + private MainResource(String name) { this.name = name; } public boolean addResource(String url, String origin, String referrer) { - long delay = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - created); + // We start the push period here and not when initializing the main resource, because a browser with a + // prefilled cache won't request the subresources. If the browser with warmed up cache now hits the main + // resource after a server restart, the push period shouldn't start until the first subresource is + // being requested. + firstResourceAdded.compareAndSet(-1, System.nanoTime()); + + long delay = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - firstResourceAdded.get()); if (!referrer.startsWith(origin) && !isPushOriginAllowed(origin)) { logger.debug("Skipped store of push metadata {} for {}: Origin: {} doesn't match or origin not allowed",