PushBuilder (Apache Tomcat 8.5.12 API Documentation)

org.apache.catalina.servlet4preview.http

## Interface PushBuilder

- All Known Implementing Classes:
    ApplicationPushBuilder

      public interface PushBuilder

  Builds a push request based on the `HttpServletRequest` from which this builder was obtained. The push request will be constructed on the following basis:
  - The request method is set to `GET`.
  - The path will not be set. This must be set explicitly via a call to `path(String)`.
  - Conditional, range, expectation, authorization and referer headers will be removed.
  - Cookies added to the associated response will be added to the push request unless maxAge <= 0 in which case any request cookie with the same name will be removed.
  - The referer header will be set to `HttpServletRequest.getRequestURL()` plus, if present, the query string from `HttpServletRequest.getQueryString()`.
  - If either of the headers `If-Modified-Since` or `If-None-Match` were present then `isConditional()` will be set to `true`.
  Since:
    Servlet 4.0

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `PushBuilder` | `addHeader(String name, String value)` Adds a HTTP header to the request.
    `PushBuilder` | `conditional(boolean conditional)` Sets if the request will be conditional.
    `PushBuilder` | `eTag(String eTag)` Sets the eTag to be used for conditional push requests.
    `String` | `getETag()` Obtain the eTag that will be used for the push request that will be generated by the next call to `push()`.
    `String` | `getHeader(String name)` Obtain a value for the given HTTP header.
    `Set<String>` | `getHeaderNames()`
    `String` | `getLastModified()` Obtain the last modified that will be used for the push request that will be generated by the next call to `push()`.
    `String` | `getMethod()` Obtain the name of the HTTP method that will be used for push requests generated by future calls to `push()`.
    `String` | `getPath()` Obtain the path that will be used for the push request that will be generated by the next call to `push()`.
    `String` | `getQueryString()` Obtain the query string that will be used for push requests generated by future calls to `push()`.
    `String` | `getSessionId()` Obtain the session ID that will be used for push requests generated by future calls to `push()`.
    `boolean` | `isConditional()` Will push requests generated by future calls to `push()` be conditional.
    `PushBuilder` | `lastModified(String lastModified)` Sets the last modified to be used for conditional push requests.
    `PushBuilder` | `method(String method)` Specify the HTTP method to use for the push request.
    `PushBuilder` | `path(String path)` Sets the URI path to be used for the push request.
    `void` | `push()` Generates the push request and sends it to the client unless pushes are not available for some reason.
    `PushBuilder` | `queryString(String queryString)` Specifies the query string to use in subsequent push requests generated by a call to `push()`.
    `PushBuilder` | `removeHeader(String name)` Removes an HTTP header from the request.
    `PushBuilder` | `sessionId(String sessionId)` Specifies the session ID to use in subsequent push requests generated by a call to `push()`.
    `PushBuilder` | `setHeader(String name, String value)` Sets a HTTP header on the request.

- - ### Method Detail

    - #### method

          PushBuilder method(String method)

      Specify the HTTP method to use for the push request.
      Parameters:
        `method` - The method to use for the push request
      Returns:
        This builder instance
      Throws:
        `IllegalArgumentException` - if an HTTP method is specified that is known not to be cacheable and safe. POST, PUT, DELETE, CONNECT, OPTIONS and TRACE will trigger the exception.

    - #### queryString

          PushBuilder queryString(String queryString)

      Specifies the query string to use in subsequent push requests generated by a call to `push()`. This will be appended to any query string specified in the call to `path(String)`.
      Parameters:
        `queryString` - The query string to use to generate push requests
      Returns:
        This builder instance

    - #### sessionId

          PushBuilder sessionId(String sessionId)

      Specifies the session ID to use in subsequent push requests generated by a call to `push()`. The session ID will be presented the same way as it is on the original request (cookie or URL parameter). The default is determined in the following order:
      - the requested session ID for the originating request
      - the session ID generated in the originated request
      - `null`
      Parameters:
        `sessionId` - The session ID to use to generate push requests
      Returns:
        This builder instance

    - #### conditional

          PushBuilder conditional(boolean conditional)

      Sets if the request will be conditional. If `true` the values from `getETag()` and `getLastModified()` will be used to construct appropriate headers.
      Parameters:
        `conditional` - Should generated push requests be conditional
      Returns:
        This builder instance

    - #### setHeader

          PushBuilder setHeader(String name,
                              String value)

      Sets a HTTP header on the request. Any existing headers of the same name are first remove.
      Parameters:
        `name` - The name of the header to set
        `value` - The value of the header to set
      Returns:
        This builder instance

    - #### addHeader

          PushBuilder addHeader(String name,
                              String value)

      Adds a HTTP header to the request.
      Parameters:
        `name` - The name of the header to add
        `value` - The value of the header to add
      Returns:
        This builder instance

    - #### removeHeader

          PushBuilder removeHeader(String name)

      Removes an HTTP header from the request.
      Parameters:
        `name` - The name of the header to remove
      Returns:
        This builder instance

    - #### path

          PushBuilder path(String path)

      Sets the URI path to be used for the push request. This must be called before every call to `push()`. If the path includes a query string, the query string will be appended to the existing query string (if any) and no de-duplication will occur.
      Parameters:
        `path` - Paths beginning with '/' are treated as absolute paths. All other paths are treated as relative to the context path of the request used to create this builder instance. The path may include a query string.
      Returns:
        This builder instance

    - #### eTag

          PushBuilder eTag(String eTag)

      Sets the eTag to be used for conditional push requests. This will be set to `null` after a call to `push()` so it must be explicitly set for every push request that requires it.
      Parameters:
        `eTag` - The eTag use for the push request
      Returns:
        This builder instance

    - #### lastModified

          PushBuilder lastModified(String lastModified)

      Sets the last modified to be used for conditional push requests. This will be set to `null` after a call to `push()` so it must be explicitly set for every push request that requires it.
      Parameters:
        `lastModified` - The last modified value to use for the push request
      Returns:
        This builder instance

    - #### push

          void push()

      Generates the push request and sends it to the client unless pushes are not available for some reason. After calling this method the following fields are set to `null`:
      - `path`
      - `eTag`
      - `lastModified`
      Throws:
        `IllegalStateException` - If this method is called when `path` is `null`
        `IllegalArgumentException` - If the request to push requires a body

    - #### getMethod

          String getMethod()

      Obtain the name of the HTTP method that will be used for push requests generated by future calls to `push()`.
      Returns:
        The HTTP method to be used for future push requests

    - #### getQueryString

          String getQueryString()

      Obtain the query string that will be used for push requests generated by future calls to `push()`.
      Returns:
        The query string that will be appended to push requests.

    - #### getSessionId

          String getSessionId()

      Obtain the session ID that will be used for push requests generated by future calls to `push()`.
      Returns:
        The session that will be used for push requests.

    - #### isConditional

          boolean isConditional()

      Will push requests generated by future calls to `push()` be conditional.
      Returns:
        `true` if push requests will be conditional

    - #### getHeaderNames

          Set<String> getHeaderNames()

      Returns:
        The current set of names of HTTP headers to be used the next time `push()` is called.

    - #### getHeader

          String getHeader(String name)

      Obtain a value for the given HTTP header. TODO Servlet 4.0 Clarify the behaviour of this method
      Parameters:
        `name` - The name of the header whose value is to be returned
      Returns:
        The value of the given header. If multiple values are defined then any may be returned

    - #### getPath

          String getPath()

      Obtain the path that will be used for the push request that will be generated by the next call to `push()`.
      Returns:
        The path value that will be associated with the next push request

    - #### getETag

          String getETag()

      Obtain the eTag that will be used for the push request that will be generated by the next call to `push()`.
      Returns:
        The eTag value that will be associated with the next push request

    - #### getLastModified

          String getLastModified()

      Obtain the last modified that will be used for the push request that will be generated by the next call to `push()`.
      Returns:
        The last modified value that will be associated with the next push request

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.