spdy: push referrer call period starts when first resource is added. Before it started when main resource was created

This commit is contained in:
Thomas Becker 2012-07-06 16:55:45 +02:00
parent 652fcc3552
commit 77c673c89b
1 changed files with 10 additions and 3 deletions

View File

@ -24,6 +24,7 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.eclipse.jetty.spdy.api.Headers; import org.eclipse.jetty.spdy.api.Headers;
@ -213,17 +214,23 @@ public class ReferrerPushStrategy implements PushStrategy
private class MainResource private class MainResource
{ {
private final String name; private final String name;
private final long created = System.nanoTime();
private final Set<String> resources = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>()); private final Set<String> resources = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
private final AtomicLong firstResourceAdded = new AtomicLong(-1);
MainResource(String name) private MainResource(String name)
{ {
this.name = name; this.name = name;
} }
public boolean addResource(String url, String origin, String referrer) 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)) if (!referrer.startsWith(origin) && !isPushOriginAllowed(origin))
{ {
logger.debug("Skipped store of push metadata {} for {}: Origin: {} doesn't match or origin not allowed", logger.debug("Skipped store of push metadata {} for {}: Origin: {} doesn't match or origin not allowed",