Class 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
    Tobias Soloschenko
    See Also:
    Serialized Form
    • 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
        page - the page this header item is applied to
        pageRequest - the page request this header item is applied to
        pageResponse - 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 class HeaderItem
        The tokens this HeaderItem can be identified by. If any of the tokens has already been rendered, this HeaderItem 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.
         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;
        the time the page of this header item has been modified
      • applyPageCacheHeader

        protected void applyPageCacheHeader()
        Applies the cache header item to the response
      • push

        protected void push​(javax.servlet.http.HttpServletRequest request)
        Pushed all URLs of this header item to the client
        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
        pushItems - a list of items to be pushed to the client
        the current push header item
      • getContainerRequest

        public javax.servlet.http.HttpServletRequest getContainerRequest​(Request request)
        Gets the container request
        request - the wicket request to get the container request from
        the container request
      • isHttp2

        public boolean isHttp2​(javax.servlet.http.HttpServletRequest request)
        Checks if the given request is a http/2 request
        request - the request to check if it is a http/2 request
        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 of HttpServletRequest if not the API of the PushHeaderItem can't be used and a WicketRuntimeException is thrown.
        request - the request to get the container request from. The container request is checked if it is instance of HttpServletRequest
        the container request get from the given request casted to HttpServletRequest
        WicketRuntimeException - - if the container request is not a HttpServletRequest