
io.dropwizard.spdy.ReferrerPushStrategyFactory Maven / Gradle / Ivy
package io.dropwizard.spdy;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.dropwizard.util.Duration;
import io.dropwizard.validation.MinDuration;
import org.eclipse.jetty.spdy.server.http.PushStrategy;
import org.eclipse.jetty.spdy.server.http.ReferrerPushStrategy;
import javax.validation.constraints.Min;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* A SPDY push strategy that auto-populates push metadata based on referrer URLs.
*
* Configuration Parameters:
*
*
* Name
* Default
* Description
*
*
* {@code pushableOriginPatterns}
* (none)
*
* The list of origin patterns to which pushes are allowed. If not specified, all
* origins are allowed.
*
*
*
* {@code maxAssociatedResources}
* 32
* The maximum number of associated resources to push.
*
*
* {@code referrerPushPeriod}
* 5 seconds
* The amount of time after a request to consider following requests as secondary.
*
*
* {@code pushableFilenamePatterns}
*
* {@code *.css}, {@code *.js}, {@code *.png}, {@code *.jpeg}, {@code *.jpg},
* {@code *.gif}, {@code *.ico}
*
*
* The list of regular expressions which determine which secondary requests are pushable
* resources.
*
*
*
* {@code pushableContentTypes}
*
* {@code text/css}, {@code text/javascript}, {@code application/javascript},
* {@code application/x-javascript}, {@code image/png}, {@code image/x-png},
* {@code image/jpeg}, {@code image/gif}, {@code image/x-icon},
* {@code image/vnd.microsoft.icon}
*
*
* The list of MIME types of pushable resources.
*
*
*
* {@code nonPushableUserAgentPatterns}
* (none)
* The list of user-agent patterns to which patterns are not allowed.
*
*
*
* @see PushStrategyFactory
* @see ReferrerPushStrategy
*/
@JsonTypeName("referrer")
public class ReferrerPushStrategyFactory implements PushStrategyFactory {
private List pushableOriginPatterns;
@Min(1)
private int maxAssociatedResources = 32;
@MinDuration(value = 1, unit = TimeUnit.MILLISECONDS)
private Duration referrerPushPeriod = Duration.seconds(5);
private List pushableFilenamePatterns;
private List pushableContentTypes;
private List nonPushableUserAgentPatterns;
@JsonProperty
public List getPushableOriginPatterns() {
return pushableOriginPatterns;
}
@JsonProperty
public void setPushableOriginPatterns(List origins) {
this.pushableOriginPatterns = origins;
}
@JsonProperty
public int getMaxAssociatedResources() {
return maxAssociatedResources;
}
@JsonProperty
public void setMaxAssociatedResources(int maxAssociatedResources) {
this.maxAssociatedResources = maxAssociatedResources;
}
@JsonProperty
public Duration getReferrerPushPeriod() {
return referrerPushPeriod;
}
@JsonProperty
public void setReferrerPushPeriod(Duration referrerPushPeriod) {
this.referrerPushPeriod = referrerPushPeriod;
}
@JsonProperty
public List getPushableFilenamePatterns() {
return pushableFilenamePatterns;
}
@JsonProperty
public void setPushableFilenamePatterns(List pushableFilenamePatterns) {
this.pushableFilenamePatterns = pushableFilenamePatterns;
}
@JsonProperty
public List getPushableContentTypes() {
return pushableContentTypes;
}
@JsonProperty
public void setPushableContentTypes(List pushableContentTypes) {
this.pushableContentTypes = pushableContentTypes;
}
@JsonProperty
public List getNonPushableUserAgentPatterns() {
return nonPushableUserAgentPatterns;
}
@JsonProperty
public void setNonPushableUserAgentPatterns(List nonPushableUserAgentPatterns) {
this.nonPushableUserAgentPatterns = nonPushableUserAgentPatterns;
}
@Override
public PushStrategy build() {
final ReferrerPushStrategy strategy = new ReferrerPushStrategy();
if (pushableOriginPatterns != null) {
strategy.setAllowedPushOrigins(pushableOriginPatterns);
}
if (pushableContentTypes != null) {
strategy.setPushContentTypes(pushableContentTypes);
}
if (pushableFilenamePatterns != null) {
strategy.setPushRegexps(pushableFilenamePatterns);
}
if (nonPushableUserAgentPatterns != null) {
strategy.setUserAgentBlacklist(nonPushableUserAgentPatterns);
}
strategy.setMaxAssociatedResources(maxAssociatedResources);
strategy.setReferrerPushPeriod((int) referrerPushPeriod.toMilliseconds());
return strategy;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy