Class HttpClientRequest

  • All Implemented Interfaces:
    StreamBase, WriteStream<Buffer>

    public class HttpClientRequest
    extends Object
    implements WriteStream<Buffer>
    Represents a client-side HTTP request.

    Instances are created by an HttpClient instance, via one of the methods corresponding to the specific HTTP methods, or the generic request methods. On creation the request will not have been written to the wire.

    Once a request has been obtained, headers can be set on it, and data can be written to its body if required. Once you are ready to send the request, one of the end(java.lang.String) methods should be called.

    Nothing is actually sent until the request has been internally assigned an HTTP connection.

    The HttpClient instance will return an instance of this class immediately, even if there are no HTTP connections available in the pool. Any requests sent before a connection is assigned will be queued internally and actually sent when an HTTP connection becomes available from the pool.

    The headers of the request are queued for writing either when the end(java.lang.String) method is called, or, when the first part of the body is written, whichever occurs first.

    This class supports both chunked and non-chunked HTTP.

    It implements WriteStream so it can be used with Pipe to pipe data with flow control.

    An example of using this class is as follows:

    NOTE: This class has been automatically generated from the original non Mutiny-ified interface using Vert.x codegen.

    • Constructor Detail

      • HttpClientRequest

        public HttpClientRequest​(io.vertx.core.http.HttpClientRequest delegate)
      • HttpClientRequest

        public HttpClientRequest​(Object delegate)
    • Method Detail

      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • write

        public io.smallrye.mutiny.Uni<Void> write​(Buffer data)
        Same as but with an handler called when the operation completes

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Specified by:
        write in interface WriteStream<Buffer>
        Parameters:
        data -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • writeAndAwait

        public Void writeAndAwait​(Buffer data)
        Blocking variant of io.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Specified by:
        writeAndAwait in interface WriteStream<Buffer>
        Parameters:
        data -
        Returns:
        the Void instance produced by the operation.
      • writeAndForget

        public void writeAndForget​(Buffer data)
        Variant of io.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer) that ignores the result of the operation.

        This method subscribes on the result of io.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from io.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer) but you don't need to compose it with other operations.

        Specified by:
        writeAndForget in interface WriteStream<Buffer>
        Parameters:
        data -
      • setWriteQueueMaxSize

        public HttpClientRequest setWriteQueueMaxSize​(int maxSize)
        Specified by:
        setWriteQueueMaxSize in interface WriteStream<Buffer>
        Parameters:
        maxSize - the max size of the write stream
        Returns:
        a reference to this, so the API can be used fluently
      • setHost

        public HttpClientRequest setHost​(String host)
        Parameters:
        host - the host part of the HTTP/1.1 host header or HTTP/2 authority pseudo header
        Returns:
        a reference to this, so the API can be used fluently
      • getHost

        public String getHost()
        Returns:
        the host value of the HTTP/1.1 host header or HTTP/2 authority pseudo header
      • setPort

        public HttpClientRequest setPort​(int port)
        Parameters:
        port - the port part of the HTTP/1.1 host header or HTTP/2 authority pseudo header
        Returns:
        a reference to this, so the API can be used fluently
      • getPort

        public int getPort()
        Returns:
        the port value of the HTTP/1.1 host header or HTTP/2 authority pseudo header
      • setFollowRedirects

        public HttpClientRequest setFollowRedirects​(boolean followRedirects)
        Parameters:
        followRedirects - true to follow HTTP redirects
        Returns:
        a reference to this, so the API can be used fluently
      • setMaxRedirects

        public HttpClientRequest setMaxRedirects​(int maxRedirects)
        Parameters:
        maxRedirects - the number of HTTP redirect to follow
        Returns:
        a reference to this, so the API can be used fluently
      • setChunked

        public HttpClientRequest setChunked​(boolean chunked)
        Parameters:
        chunked - true if chunked encoding
        Returns:
        a reference to this, so the API can be used fluently
      • isChunked

        public boolean isChunked()
        Returns:
        Is the request chunked?
      • getMethod

        public io.vertx.core.http.HttpMethod getMethod()
        Returns:
      • setMethod

        public HttpClientRequest setMethod​(io.vertx.core.http.HttpMethod method)
        Parameters:
        method - the HTTP method
        Returns:
        a reference to this, so the API can be used fluently
      • absoluteURI

        public String absoluteURI()
        Returns:
        the absolute URI corresponding to the HTTP request
      • getURI

        public String getURI()
        Returns:
        The URI of the request.
      • setURI

        public HttpClientRequest setURI​(String uri)
        Parameters:
        uri - the request uri
        Returns:
        a reference to this, so the API can be used fluently
      • path

        public String path()
        Returns:
        The path part of the uri. For example /somepath/somemorepath/someresource.foo
      • query

        public String query()
        Returns:
        the query part of the uri. For example someparam=32&someotherparam=x
      • headers

        public MultiMap headers()
        Returns:
        The HTTP headers
      • putHeader

        public HttpClientRequest putHeader​(String name,
                                           String value)
        Parameters:
        name - The header name
        value - The header value
        Returns:
        a reference to this, so the API can be used fluently
      • version

        public io.vertx.core.http.HttpVersion version()
        Returns:
        the HTTP version for this request
      • write

        public io.smallrye.mutiny.Uni<Void> write​(String chunk)
        Same as write(io.vertx.mutiny.core.buffer.Buffer) but with an handler called when the operation completes

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        chunk -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • writeAndAwait

        public Void writeAndAwait​(String chunk)
        Blocking variant of write(String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        chunk -
        Returns:
        the Void instance produced by the operation.
      • writeAndForget

        public void writeAndForget​(String chunk)
        Variant of write(String) that ignores the result of the operation.

        This method subscribes on the result of write(String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from write(String) but you don't need to compose it with other operations.

        Parameters:
        chunk -
      • write

        public io.smallrye.mutiny.Uni<Void> write​(String chunk,
                                                  String enc)
        Same as write(io.vertx.mutiny.core.buffer.Buffer) but with an handler called when the operation completes

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        chunk -
        enc -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • writeAndAwait

        public Void writeAndAwait​(String chunk,
                                  String enc)
        Blocking variant of write(String,String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        chunk -
        enc -
        Returns:
        the Void instance produced by the operation.
      • writeAndForget

        public void writeAndForget​(String chunk,
                                   String enc)
        Variant of write(String,String) that ignores the result of the operation.

        This method subscribes on the result of write(String,String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from write(String,String) but you don't need to compose it with other operations.

        Parameters:
        chunk -
        enc -
      • sendHead

        public io.smallrye.mutiny.Uni<Void> sendHead()
        Like sendHead() but with an handler after headers have been sent. The handler will be called with the HttpVersion if it can be determined or null otherwise.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendHeadAndAwait

        public Void sendHeadAndAwait()
        Blocking variant of sendHead().

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Returns:
        the Void instance produced by the operation.
      • sendHeadAndForget

        public HttpClientRequest sendHeadAndForget()
        Variant of sendHead() that ignores the result of the operation.

        This method subscribes on the result of sendHead(), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from sendHead() but you don't need to compose it with other operations.

        Returns:
        the instance of HttpClientRequest to chain method calls.
      • connect

        public io.smallrye.mutiny.Uni<HttpClientResponse> connect()
        Create an HTTP tunnel to the server.

        Send an HTTP request to the server, then configures the transport to exchange raw buffers when the server replies with an appropriate response:

        • 200 for HTTP CONNECT method
        • 101 for HTTP/1.1 GET with Upgrade connection header

        The handler is called after response headers are received.

        Use HttpClientResponse.netSocket() to get a for the interacting more conveniently with the server.

        HTTP/1.1 pipe-lined requests are not supported.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • connectAndAwait

        public HttpClientResponse connectAndAwait()
        Blocking variant of connect().

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Returns:
        the HttpClientResponse instance produced by the operation.
      • connectAndForget

        public void connectAndForget()
        Variant of connect() that ignores the result of the operation.

        This method subscribes on the result of connect(), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from connect() but you don't need to compose it with other operations.

      • response

        public io.smallrye.mutiny.Uni<HttpClientResponse> response()
        Set a callback for the associated HttpClientResponse.

        This method does not modify the current request being sent.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • responseAndAwait

        public HttpClientResponse responseAndAwait()
        Blocking variant of response().

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Returns:
        the HttpClientResponse instance produced by the operation.
      • responseAndForget

        public HttpClientRequest responseAndForget()
        Variant of response() that ignores the result of the operation.

        This method subscribes on the result of response(), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from response() but you don't need to compose it with other operations.

        Returns:
        the instance of HttpClientRequest to chain method calls.
      • send

        public io.smallrye.mutiny.Uni<HttpClientResponse> send()
        Send the request with an empty body.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendAndAwait

        public HttpClientResponse sendAndAwait()
        Blocking variant of send().

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Returns:
        the HttpClientResponse instance produced by the operation.
      • sendAndForget

        public void sendAndForget()
        Variant of send() that ignores the result of the operation.

        This method subscribes on the result of send(), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from send() but you don't need to compose it with other operations.

      • send

        public io.smallrye.mutiny.Uni<HttpClientResponse> send​(String body)
        Send the request with a string body.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        body -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendAndAwait

        public HttpClientResponse sendAndAwait​(String body)
        Blocking variant of send(String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        body -
        Returns:
        the HttpClientResponse instance produced by the operation.
      • sendAndForget

        public void sendAndForget​(String body)
        Variant of send(String) that ignores the result of the operation.

        This method subscribes on the result of send(String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from send(String) but you don't need to compose it with other operations.

        Parameters:
        body -
      • send

        public io.smallrye.mutiny.Uni<HttpClientResponse> send​(Buffer body)
        Send the request with a buffer body.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        body -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendAndAwait

        public HttpClientResponse sendAndAwait​(Buffer body)
        Blocking variant of send(io.vertx.mutiny.core.buffer.Buffer).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        body -
        Returns:
        the HttpClientResponse instance produced by the operation.
      • send

        public io.smallrye.mutiny.Uni<HttpClientResponse> send​(ReadStream<Buffer> body)
        Send the request with a stream body.

        If the HttpHeaders is set then the request assumes this is the length of the {stream}, otherwise the request will set a chunked HttpHeaders.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        body -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendAndAwait

        public HttpClientResponse sendAndAwait​(ReadStream<Buffer> body)
        Blocking variant of io.vertx.mutiny.core.http.HttpClientRequest#send(io.vertx.mutiny.core.streams.ReadStream).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        body -
        Returns:
        the HttpClientResponse instance produced by the operation.
      • sendAndForget

        public void sendAndForget​(ReadStream<Buffer> body)
        Variant of io.vertx.mutiny.core.http.HttpClientRequest#send(io.vertx.mutiny.core.streams.ReadStream) that ignores the result of the operation.

        This method subscribes on the result of io.vertx.mutiny.core.http.HttpClientRequest#send(io.vertx.mutiny.core.streams.ReadStream), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from io.vertx.mutiny.core.http.HttpClientRequest#send(io.vertx.mutiny.core.streams.ReadStream) but you don't need to compose it with other operations.

        Parameters:
        body -
      • send

        public io.smallrye.mutiny.Uni<HttpClientResponse> send​(org.reactivestreams.Publisher<Buffer> body)
        Send the request with a stream body.

        If the HttpHeaders is set then the request assumes this is the length of the {stream}, otherwise the request will set a chunked HttpHeaders.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        body -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendAndAwait

        public HttpClientResponse sendAndAwait​(org.reactivestreams.Publisher<Buffer> body)
        Blocking variant of send(Publisher<Buffer>).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        body -
        Returns:
        the HttpClientResponse instance produced by the operation.
      • sendAndForget

        public void sendAndForget​(org.reactivestreams.Publisher<Buffer> body)
        Variant of send(Publisher<Buffer>) that ignores the result of the operation.

        This method subscribes on the result of send(Publisher<Buffer>), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from send(Publisher<Buffer>) but you don't need to compose it with other operations.

        Parameters:
        body -
      • end

        public io.smallrye.mutiny.Uni<Void> end​(String chunk)
        Same as end(java.lang.String) but with an handler called when the operation completes

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        chunk -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • endAndAwait

        public Void endAndAwait​(String chunk)
        Blocking variant of end(String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        chunk -
        Returns:
        the Void instance produced by the operation.
      • endAndForget

        public void endAndForget​(String chunk)
        Variant of end(String) that ignores the result of the operation.

        This method subscribes on the result of end(String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from end(String) but you don't need to compose it with other operations.

        Parameters:
        chunk -
      • end

        public io.smallrye.mutiny.Uni<Void> end​(String chunk,
                                                String enc)
        Same as end(java.lang.String) but with an handler called when the operation completes

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        chunk -
        enc -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • endAndAwait

        public Void endAndAwait​(String chunk,
                                String enc)
        Blocking variant of end(String,String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        chunk -
        enc -
        Returns:
        the Void instance produced by the operation.
      • endAndForget

        public void endAndForget​(String chunk,
                                 String enc)
        Variant of end(String,String) that ignores the result of the operation.

        This method subscribes on the result of end(String,String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from end(String,String) but you don't need to compose it with other operations.

        Parameters:
        chunk -
        enc -
      • end

        public io.smallrye.mutiny.Uni<Void> end​(Buffer chunk)
        Same as end(java.lang.String) but with an handler called when the operation completes

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Specified by:
        end in interface WriteStream<Buffer>
        Parameters:
        chunk -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • endAndAwait

        public Void endAndAwait​(Buffer chunk)
        Blocking variant of end(io.vertx.mutiny.core.buffer.Buffer).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Specified by:
        endAndAwait in interface WriteStream<Buffer>
        Parameters:
        chunk -
        Returns:
        the Void instance produced by the operation.
      • end

        public io.smallrye.mutiny.Uni<Void> end()
        Same as end(java.lang.String) but with an handler called when the operation completes

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Specified by:
        end in interface WriteStream<Buffer>
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • endAndAwait

        public Void endAndAwait()
        Blocking variant of end(java.lang.String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Specified by:
        endAndAwait in interface WriteStream<Buffer>
        Returns:
        the Void instance produced by the operation.
      • setTimeout

        public HttpClientRequest setTimeout​(long timeoutMs)
        Parameters:
        timeoutMs - The quantity of time in milliseconds.
        Returns:
        a reference to this, so the API can be used fluently
      • reset

        public boolean reset()
        Returns:
      • reset

        public boolean reset​(long code)
        Parameters:
        code - the error code
        Returns:
        true when reset has been performed
      • reset

        public boolean reset​(long code,
                             Throwable cause)
        Parameters:
        code - the error code
        cause - an optional cause that can be attached to the error code
        Returns:
        true when reset has been performed
      • writeCustomFrame

        public HttpClientRequest writeCustomFrame​(int type,
                                                  int flags,
                                                  Buffer payload)
        Parameters:
        type - the 8-bit frame type
        flags - the 8-bit frame flags
        payload - the frame payload
        Returns:
        a reference to this, so the API can be used fluently
      • streamId

        public int streamId()
        Returns:
        the id of the stream of this response, when it is not yet determined, i.e the request has not been yet sent or it is not supported HTTP/1.x
      • writeCustomFrame

        public HttpClientRequest writeCustomFrame​(HttpFrame frame)
        Parameters:
        frame - the frame to write
        Returns:
        the instance of HttpClientRequest to chain method calls.
      • setStreamPriority

        public HttpClientRequest setStreamPriority​(io.vertx.core.http.StreamPriority streamPriority)
        Parameters:
        streamPriority - the priority of this request's stream
        Returns:
        the instance of HttpClientRequest to chain method calls.
      • getStreamPriority

        public io.vertx.core.http.StreamPriority getStreamPriority()
        Returns:
        the priority of the associated HTTP/2 stream for HTTP/2 otherwise null
      • newInstance

        public static HttpClientRequest newInstance​(io.vertx.core.http.HttpClientRequest arg)