Class IndexHtmlResponse

java.lang.Object
com.vaadin.flow.server.communication.IndexHtmlResponse

public class IndexHtmlResponse extends Object
This represents the state of a Index HTML response being generated. The Index HTML response contains of the full DOM of the HTML document as well as the HTTP headers that will be included in the corresponding HTTP response.
Since:
3.0
  • Constructor Details

    • IndexHtmlResponse

      public IndexHtmlResponse(VaadinRequest vaadinRequest, VaadinResponse vaadinResponse, org.jsoup.nodes.Document document, UI ui)
      Create a response object for client side bootstrapping with UI.
      Parameters:
      vaadinRequest - the vaadin request which is handling
      vaadinResponse - the corresponding vaadin response
      document - the Document object of the response page
      ui - the UI for the bootstrap
    • IndexHtmlResponse

      public IndexHtmlResponse(VaadinRequest vaadinRequest, VaadinResponse vaadinResponse, org.jsoup.nodes.Document document)
      Create a response object for client side bootstrapping.
      Parameters:
      vaadinRequest - the vaadin request which is handling
      vaadinResponse - the corresponding vaadin response
      document - the Document object of the response page
  • Method Details

    • getVaadinRequest

      public VaadinRequest getVaadinRequest()
      Get the request which triggers the Index HTML response.
      Returns:
      the Vaadin request
    • getVaadinResponse

      public VaadinResponse getVaadinResponse()
      Get the Vaadin response object including all the headers which will be sent to browser.
      Returns:
      the Vaadin response
    • getDocument

      public org.jsoup.nodes.Document getDocument()
      Get the index.html response in form of a Document instance.
      Returns:
      the index document
    • getUI

      public Optional<UI> getUI()
      Gets the UI that will be displayed on the generated HTML page.
      Returns:
      the UI
    • getCspNonce

      public @Nullable String getCspNonce()
      Gets the nonce of this response, which Vaadin puts on every <script> element of the document and allows in the script-src directive of the Content Security Policy.

      A new nonce is created for every response when the application runs with the CspMode.STRICT mode. Scripts added by an IndexHtmlRequestListener get the nonce automatically, but the value can also be used for other content that needs it. The nonce is not put on the scripts in development mode.

      Returns:
      the nonce, or null if the mode is not CspMode.STRICT
      Since:
      25.4
    • getContentSecurityPolicy

      public @Nullable ContentSecurityPolicy getContentSecurityPolicy()
      Gets the Content Security Policy that is sent with this response.

      The policy is created when the application runs with the CspMode.STRICT mode. An IndexHtmlRequestListener can add or override directives for resources of the application, such as connect-src, img-src, frame-src or report-to.

      Do not change script-src: it holds the nonce and 'strict-dynamic', so replacing it with ContentSecurityPolicy.setDirective(String, String...) blocks every script of the page, and host sources added to it are ignored by the browser. To load a script from another origin, add a <script> element to the document, which gets the nonce, or load it from a script that is already trusted.

      The header is written after all listeners have run. It is not written in development mode, because the development server and the development tools need eval. In production mode, the request fails with an IllegalStateException if the response already has a Content-Security-Policy header when the page is written, for example from a servlet filter that runs before Vaadin. A filter that writes its header only when the response is committed, such as Spring Security's HeaderWriterFilter by default, cannot be detected; its policy should be configured here instead.

      Returns:
      the mutable policy, or null if the mode is not CspMode.STRICT
      Since:
      25.4