Class HttpSender.Request.Builder

  • Enclosing class:
    HttpSender.Request

    public static class HttpSender.Request.Builder
    extends java.lang.Object
    • Method Detail

      • withHeader

        public final HttpSender.Request.Builder withHeader​(java.lang.String name,
                                                           java.lang.String value)
        Add a header to the request.
        Parameters:
        name - The name of the header.
        value - The value of the header.
        Returns:
        This request builder.
      • withBasicAuthentication

        public final HttpSender.Request.Builder withBasicAuthentication​(@Nullable
                                                                        java.lang.String user,
                                                                        @Nullable
                                                                        java.lang.String password)
        If user and password are non-empty, set basic authentication on the request.
        Parameters:
        user - A user name, if available.
        password - A password, if available.
        Returns:
        This request builder.
      • withJsonContent

        public final HttpSender.Request.Builder withJsonContent​(java.lang.String content)
        Set the request body as JSON content type.
        Parameters:
        content - The request body.
        Returns:
        This request builder.
      • withPlainText

        public final HttpSender.Request.Builder withPlainText​(java.lang.String content)
        Set the request body as plain text content type.
        Parameters:
        content - The request body.
        Returns:
        This request builder.
      • withContent

        public final HttpSender.Request.Builder withContent​(java.lang.String type,
                                                            java.lang.String content)
        Set the request body.
        Parameters:
        type - The value of the "Content-Type" header to add.
        content - The request body.
        Returns:
        This request builder.
      • withContent

        public final HttpSender.Request.Builder withContent​(java.lang.String type,
                                                            byte[] content)
        Set the request body.
        Parameters:
        type - The value of the "Content-Type" header to add.
        content - The request body.
        Returns:
        This request builder.
      • acceptJson

        public HttpSender.Request.Builder acceptJson()
        Add header to accept application/json data.
        Returns:
        This request builder.
      • accept

        public HttpSender.Request.Builder accept​(java.lang.String type)
        Add accept header.
        Parameters:
        type - The value of the "Accept" header to add.
        Returns:
        This request builder.
      • compress

        public final HttpSender.Request.Builder compress()
                                                  throws java.io.IOException
        Add a "Content-Encoding" header of "gzip" and compress the request body.
        Returns:
        This request builder.
        Throws:
        java.io.IOException - If compression fails.
      • compressWhen

        public final HttpSender.Request.Builder compressWhen​(java.util.function.Supplier<java.lang.Boolean> when)
                                                      throws java.io.IOException
        Add a "Content-Encoding" header of "gzip" and compress the request body when the supplied condition is true.
        Parameters:
        when - Condition that governs when to compress the request body.
        Returns:
        This request builder.
        Throws:
        java.io.IOException - If compression fails.
      • send

        public HttpSender.Response send()
                                 throws java.lang.Throwable
        Throws:
        java.lang.Throwable