Class WebRequest.Builder

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

@AnyThread public static class WebRequest.Builder extends WebMessage.Builder
Builder offers a convenient way for constructing WebRequest instances.
  • Constructor Details

    • Builder

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

    • uri

      @NonNull public WebRequest.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 WebRequest.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 WebRequest.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 WebRequest.Builder body(@Nullable ByteBuffer buffer)
      Set the body.
      Parameters:
      buffer - A ByteBuffer with the data. Must be allocated directly via ByteBuffer.allocateDirect(int).
      Returns:
      This Builder instance.
    • body

      @NonNull public WebRequest.Builder body(@Nullable String bodyString)
      Set the body.
      Parameters:
      bodyString - A String with the data.
      Returns:
      This Builder instance.
    • method

      @NonNull public WebRequest.Builder method(@NonNull String method)
      Set the HTTP method.
      Parameters:
      method - The HTTP method String.
      Returns:
      This Builder instance.
    • cacheMode

      @NonNull public WebRequest.Builder cacheMode(int mode)
      Set the cache mode.
      Parameters:
      mode - One of the CACHE_* flags.
      Returns:
      This Builder instance.
    • referrer

      @NonNull public WebRequest.Builder referrer(@Nullable String referrer)
      Set the HTTP Referer header.
      Parameters:
      referrer - A URI String
      Returns:
      This Builder instance.
    • beConservative

      @NonNull public WebRequest.Builder beConservative(boolean beConservative)
      Set the beConservative property.
      Parameters:
      beConservative - If true, do not use newer protocol features that might have interop problems on the Internet. Intended only for use with critical infrastructure.
      Returns:
      This Builder instance.
    • build

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