Class WebResponse.Builder

Object
org.mozilla.geckoview.WebMessage.Builder
org.mozilla.geckoview.WebResponse.Builder
Enclosing class:
WebResponse

@AnyThread public static class WebResponse.Builder extends WebMessage.Builder
Builder offers a convenient way to create WebResponse instances.
  • Constructor Details

    • Builder

      public Builder(@NonNull String uri)
      Constructs a new Builder instance with the specified URI.
      Parameters:
      uri - A URI String.
  • Method Details

    • uri

      @NonNull public WebResponse.Builder uri(@NonNull String uri)
      Description copied from class: WebMessage.Builder
      Set the URI
      Overrides:
      uri in class WebMessage.Builder
      Parameters:
      uri - A URI String
      Returns:
      This Builder instance.
    • header

      @NonNull public WebResponse.Builder header(@NonNull String key, @NonNull String value)
      Description copied from class: WebMessage.Builder
      Set a HTTP header. This may be called multiple times for additional headers. If an existing header of the same name exists, it will be replaced by this value.

      Please note that the HTTP header keys are case-insensitive. It means you can retrieve "Content-Type" with map.get("content-type"), and value for "Content-Type" will be overwritten by map.put("cONTENt-TYpe", value); The keys are also sorted in natural order.

      Overrides:
      header in class WebMessage.Builder
      Parameters:
      key - The key for the HTTP header, e.g. "content-type".
      value - The value for the HTTP header, e.g. "application/json".
      Returns:
      This Builder instance.
    • addHeader

      @NonNull public WebResponse.Builder addHeader(@NonNull String key, @NonNull String value)
      Description copied from class: WebMessage.Builder
      Add a HTTP header. This may be called multiple times for additional headers. If an existing header of the same name exists, the values will be merged.

      Please note that the HTTP header keys are case-insensitive. It means you can retrieve "Content-Type" with map.get("content-type"), and value for "Content-Type" will be overwritten by map.put("cONTENt-TYpe", value); The keys are also sorted in natural order.

      Overrides:
      addHeader in class WebMessage.Builder
      Parameters:
      key - The key for the HTTP header, e.g. "content-type".
      value - The value for the HTTP header, e.g. "application/json".
      Returns:
      This Builder instance.
    • body

      @NonNull public WebResponse.Builder body(@NonNull InputStream stream)
      Sets the InputStream containing the body of this response.
      Parameters:
      stream - An InputStream with the body of the response.
      Returns:
      This Builder instance.
    • requestExternalApp

      @NonNull public WebResponse.Builder requestExternalApp(boolean requestExternalApp)
      Requests that the content be passed to an external Android application. The default is false. For example, set to true to request that the user have the option to open the content in another Android application.
      Parameters:
      requestExternalApp - request that the content be opened in another application.
      Returns:
      This Builder instance.
    • skipConfirmation

      @NonNull public WebResponse.Builder skipConfirmation(boolean skipConfirmation)
      Specifies if a confirmation to begin downloading is necessary or not. (The confirmation that a download occurred will still be shown.) The default is false, which is to request a download confirmation. Skipping the confirmation is only advisable if the user has already opted to download.
      Parameters:
      skipConfirmation - whether to skip or show the confirm download flow
      Returns:
      This Builder instance.
    • isSecure

      @NonNull public WebResponse.Builder isSecure(boolean isSecure)
      Parameters:
      isSecure - Whether or not this response is secure.
      Returns:
      This Builder instance.
    • certificate

      @NonNull public WebResponse.Builder certificate(@NonNull X509Certificate certificate)
      Parameters:
      certificate - The certificate used.
      Returns:
      This Builder instance.
    • statusCode

      @NonNull public WebResponse.Builder statusCode(int code)
      Set the HTTP status code, e.g. 200.
      Parameters:
      code - A int representing the HTTP status code.
      Returns:
      This Builder instance.
    • redirected

      @NonNull public WebResponse.Builder redirected(boolean redirected)
      Set whether or not this response was the result of a redirect.
      Parameters:
      redirected - A boolean representing whether or not the request was redirected.
      Returns:
      This Builder instance.
    • build

      @NonNull public WebResponse build()
      Returns:
      A WebResponse constructed with the values from this Builder instance.