Class PushHeaderItem
- java.lang.Object
-
- org.apache.wicket.markup.head.HeaderItem
-
- org.apache.wicket.http2.markup.head.PushHeaderItem
-
- All Implemented Interfaces:
Serializable
,IClusterable
public class PushHeaderItem extends HeaderItem
A push header item to be used in the http/2 context and to reduce the latency of the web application. Follow these steps for your page:
- Override the setHeaders method and don't call super.setHeaders to disable caching
- Get the page request / response and store them as transient fields that are given into the PushHeaderItem
- Ensure a valid https connection (not self signed), because otherwise no caching information are accepted from Chrome or other browsers- Author:
- Tobias Soloschenko
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
HTTP2_PROTOCOL
The http2 protocol string
-
Constructor Summary
Constructors Constructor Description PushHeaderItem(Page page, Request pageRequest, Response pageResponse)
Creates a push header item based on the given page and the corresponding page request / page response.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
applyPageCacheHeader()
Applies the cache header item to the responsejavax.servlet.http.HttpServletRequest
checkHttpServletRequest(Request request)
Checks if the container request from the given request is instance ofHttpServletRequest
if not the API of the PushHeaderItem can't be used and aWicketRuntimeException
is thrown.boolean
equals(Object o)
javax.servlet.http.HttpServletRequest
getContainerRequest(Request request)
Gets the container requestprotected Instant
getPageModificationTime()
Gets the time the page of this header item has been modified.Iterable<?>
getRenderTokens()
Uses the URLs that has already been pushed to the client to ensure not to push them againint
hashCode()
boolean
isHttp2(javax.servlet.http.HttpServletRequest request)
Checks if the given request is a http/2 requestPushHeaderItem
push(List<PushItem> pushItems)
Creates a URL and pushes the resource to the client - this is only supported if http2 is enabledprotected void
push(javax.servlet.http.HttpServletRequest request)
Pushed all URLs of this header item to the clientvoid
render(Response response)
Pushes the previously created URLs to the client-
Methods inherited from class org.apache.wicket.markup.head.HeaderItem
getDependencies, getProvidedResources
-
-
-
-
Field Detail
-
HTTP2_PROTOCOL
public static final String HTTP2_PROTOCOL
The http2 protocol string- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PushHeaderItem
public PushHeaderItem(Page page, Request pageRequest, Response pageResponse)
Creates a push header item based on the given page and the corresponding page request / page response. To get the request and response- Parameters:
page
- the page this header item is applied topageRequest
- the page request this header item is applied topageResponse
- the page response this header item is applied to
-
-
Method Detail
-
getRenderTokens
public Iterable<?> getRenderTokens()
Uses the URLs that has already been pushed to the client to ensure not to push them again- Specified by:
getRenderTokens
in classHeaderItem
- Returns:
- The tokens this
HeaderItem
can be identified by. If any of the tokens has already been rendered, thisHeaderItem
will not be rendered.
-
getPageModificationTime
protected Instant getPageModificationTime()
Gets the time the page of this header item has been modified. The default implementation is to get the last modification date of the HTML file of the corresponding page, but it can be overridden to apply a custom behavior. For example place in a properties-file into the class path which contains the compile time.
Example:protected Time getPageModificationTime(){ Time time = getPageModificationTime(); // read properties file with build time and place it into a second time variable return time.before(buildTime) ? buildTime : time; }
- Returns:
- the time the page of this header item has been modified
-
applyPageCacheHeader
protected void applyPageCacheHeader()
Applies the cache header item to the response
-
render
public void render(Response response)
Pushes the previously created URLs to the client- Specified by:
render
in classHeaderItem
-
push
protected void push(javax.servlet.http.HttpServletRequest request)
Pushed all URLs of this header item to the client- Parameters:
request
- the request to push the URLs to
-
push
public PushHeaderItem push(List<PushItem> pushItems)
Creates a URL and pushes the resource to the client - this is only supported if http2 is enabled- Parameters:
pushItems
- a list of items to be pushed to the client- Returns:
- the current push header item
-
getContainerRequest
public javax.servlet.http.HttpServletRequest getContainerRequest(Request request)
Gets the container request- Parameters:
request
- the wicket request to get the container request from- Returns:
- the container request
-
isHttp2
public boolean isHttp2(javax.servlet.http.HttpServletRequest request)
Checks if the given request is a http/2 request- Parameters:
request
- the request to check if it is a http/2 request- Returns:
- if the request is a http/2 request
-
checkHttpServletRequest
public javax.servlet.http.HttpServletRequest checkHttpServletRequest(Request request)
Checks if the container request from the given request is instance ofHttpServletRequest
if not the API of the PushHeaderItem can't be used and aWicketRuntimeException
is thrown.- Parameters:
request
- the request to get the container request from. The container request is checked if it is instance ofHttpServletRequest
- Returns:
- the container request get from the given request casted to
HttpServletRequest
- Throws:
WicketRuntimeException
- - if the container request is not aHttpServletRequest
-
-