Top Description Methods
io.vertx.core.http

public Interface HttpClientRequest

extends WriteStream<Buffer>
Known Direct Implementers
io.vertx.core.http.impl.HttpClientRequestBase, io.vertx.core.http.impl.HttpClientRequestImpl
Annotations
@VertxGen
Imports
io.vertx.codegen.annotations.*, io.vertx.core.AsyncResult, .Future, .Handler, .MultiMap, io.vertx.core.buffer.Buffer, io.vertx.core.net.HostAndPort, .NetSocket, io.vertx.core.streams.ReadStream, .WriteStream, java.util.function.Function

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() 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() 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 io.vertx.core.streams.WriteStream so it can be used with io.vertx.core.streams.Pipe to pipe data with flow control.

An example of using this class is as follows:

Author
Tim Fox

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the absolute URI corresponding to the HTTP request
absoluteURI
()

public HttpClientRequest

Returns:

a reference to this, so the API can be used fluently
authority
(HostAndPort
override the request authority
authority
)

Override the request authority, when using HTTP/1.x this overrides the request host header, when using HTTP/2 this sets the authority pseudo header.

public void
connect(Handler<AsyncResult<HttpClientResponse>>
the response completion handler
handler
)

Create an HTTP tunnel to the server.

public Future<HttpClientResponse>
connect()

Like connect(Handler) but returns a Future of the asynchronous result

public HttpConnection

Returns:

the HttpConnection associated with this request
connection
()

public HttpClientRequest

Returns:

a reference to this, so the API can be used fluently
continueHandler
(@Nullable Handler<Void> handler)

If you send an HTTP request with the header Expect set to the value 100-continue and the server responds with an interim HTTP response with a status code of 100 and a Continue handler has been set using this method, then the handler will be called.

public HttpClientRequest
public HttpClientRequest

Returns:

a reference to this, so the API can be used fluently
earlyHintsHandler
(@Nullable Handler<MultiMap> handler)

If the server responds with an interim HTTP response with a status code of 103 and a Early Hints handler has been set using this method, then the handler will be called.

public Future<Void>

Returns:

a future completed with the result
end
(String
the data chunk
chunk
)

Redeclares as abstract: io.vertx.core.streams.WriteStream.end.

Same as end(Buffer) but writes a String in UTF-8 encoding

public void
end(String chunk, Handler<AsyncResult<Void>> handler)

Redeclares as abstract: io.vertx.core.streams.WriteStream.end.

Same as end(String) but with an handler called when the operation completes

public Future<Void>

Returns:

a future completed with the result
end
(String
the data chunk
chunk
,
String
the encoding
enc
)

Same as end(Buffer) but writes a String with the specified encoding

public void
end(String chunk, String enc, Handler<AsyncResult<Void>> handler)

Same as end(String, String) but with an handler called when the operation completes

public Future<Void>

Returns:

a future completed with the result
end
(Buffer
the data to write
chunk
)

Redeclares as abstract: io.vertx.core.streams.WriteStream.end.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Same as end() but writes some data to the request body before ending.

public void
end(Buffer chunk, Handler<AsyncResult<Void>> handler)

Redeclares as abstract: io.vertx.core.streams.WriteStream.end.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Same as end(String) but with an handler called when the operation completes

public Future<Void>

Returns:

a future completed with the result
end
()

Redeclares as abstract: io.vertx.core.streams.WriteStream.end.

Ends the request.

public void
end(Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.streams.WriteStream.end.

Redeclares as abstract: io.vertx.core.streams.WriteStream.end.

Same as end() but with an handler called when the operation completes

public HttpClientRequest
public String

Returns:

the host value of the HTTP/1.1 host header or HTTP/2 authority pseudo header
getHost
()
Deprecated

public int

Returns:

the maximum number of HTTP redirections to follow
getMaxRedirects
()

public HttpMethod
getMethod()

The HTTP method for the request.

public int

Returns:

the port value of the HTTP/1.1 host header or HTTP/2 authority pseudo header
getPort
()
Deprecated

public StreamPriority

Returns:

the priority of the associated HTTP/2 stream for HTTP/2 otherwise null
getStreamPriority
()

public String

Returns:

The URI of the request.
getURI
()

public MultiMap

Returns:

The HTTP headers
headers
()

public default HttpClientRequest

Returns:

a reference to this, so the API can be used fluently
idleTimeout
(long
the amount of time in milliseconds.
timeout
)

Sets the amount of time after which, if the request does not return any data within the timeout period, the request/response is closed and the related futures are failed with a java.util.concurrent.TimeoutException, e.g. Future<HttpClientResponse> or Future<Buffer> response body.

public boolean

Returns:

Is the request chunked?
isChunked
()

public boolean

Returns:

whether HTTP redirections should be followed
isFollowRedirects
()

public int

Returns:

the number of followed redirections for the current HTTP request
numberOfRedirections
()

public String

Returns:

The path part of the uri. For example /somepath/somemorepath/someresource.foo
path
()

public HttpClientRequest

Returns:

a reference to this, so the API can be used fluently
pushHandler
(Handler<HttpClientRequest>
the handler
handler
)

Set a push handler for this request.

public HttpClientRequest

Returns:

a reference to this, so the API can be used fluently
putHeader
(String
The header name
name
,
String
The header value
value
)

Put an HTTP header

public HttpClientRequest
putHeader(CharSequence name, CharSequence value)

Like putHeader(String, String) but using CharSequence

public HttpClientRequest

Returns:

@return a reference to this, so the API can be used fluently
putHeader
(String
The header name
name
,
Iterable<String>
The header values
values
)

Put an HTTP header with multiple values

public HttpClientRequest
putHeader(CharSequence name, Iterable<CharSequence> values)

Like putHeader(String, Iterable) but using CharSequence

public String

Returns:

the query part of the uri. For example someparam=32&someotherparam=x
query
()

public HttpClientRequest
public default boolean
reset()

Reset this stream with the error code 0.

public boolean

Returns:

true when reset has been performed
reset
(long
the error code
code
)

Reset this request:

  • for HTTP/2, this performs send an HTTP/2 reset frame with the specified error code
  • for HTTP/1.x, this closes the connection when the current request is inflight
public boolean

Returns:

true when reset has been performed
reset
(long
the error code
code
,
Throwable
an optional cause that can be attached to the error code
cause
)

Reset this request:

  • for HTTP/2, send an HTTP/2 reset frame with the specified error code
  • for HTTP/1.x, close the connection when the current request is inflight
public HttpClientRequest

Returns:

a reference to this, so the API can be used fluently
response
(Handler<AsyncResult<HttpClientResponse>>
the completion handler
handler
)

Set a callback for the associated HttpClientResponse.

public Future<HttpClientResponse>

Returns:

a future of the HttpClientResponse, see response(Handler)
response
()

public default void
send(Handler<AsyncResult<HttpClientResponse>>
the completion handler for the HttpClientResponse
handler
)

Send the request with an empty body.

public default Future<HttpClientResponse>
send()

Like send(Handler) but returns a Future of the asynchronous result

public default void
send(String body, Handler<AsyncResult<HttpClientResponse>>
the completion handler for the HttpClientResponse
handler
)

Send the request with a string body.

public default Future<HttpClientResponse>
send(String body)

Like send(String, Handler) but returns a Future of the asynchronous result

public default void
send(Buffer body, Handler<AsyncResult<HttpClientResponse>>
the completion handler for the HttpClientResponse
handler
)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Send the request with a buffer body.

public default Future<HttpClientResponse>
send(Buffer body)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Like send(Buffer, Handler) but returns a Future of the asynchronous result

public default void
send(ReadStream<Buffer> body, Handler<AsyncResult<HttpClientResponse>>
the completion handler for the HttpClientResponse
handler
)

Send the request with a stream body.

public default Future<HttpClientResponse>
send(ReadStream<Buffer> body)

Like send(ReadStream, Handler) but returns a Future of the asynchronous result

public Future<Void>

Returns:

a reference to this, so the API can be used fluently
sendHead
()

Forces the head of the request to be written before end() is called on the request or any data is written to it.

public HttpClientRequest
sendHead(Handler<AsyncResult<Void>> completionHandler)

Like sendHead() but with an handler after headers have been sent.

public HttpClientRequest

Returns:

a reference to this, so the API can be used fluently
setChunked
(boolean
true if chunked encoding
chunked
)

If chunked is true then the request will be set into HTTP chunked mode

public HttpClientRequest

Returns:

a reference to this, so the API can be used fluently
setFollowRedirects
(boolean
true to follow HTTP redirects
followRedirects
)

Set the request to follow HTTP redirects up to HttpClientOptions#getMaxRedirects().

public HttpClientRequest

Returns:

a reference to this, so the API can be used fluently
setHost
(String
the host part of the HTTP/1.1 host header or HTTP/2 authority pseudo header
host
)
Deprecated instead use authority(HostAndPort)

Set the host value of the HTTP/1.1 host header or HTTP/2 authority pseudo header

The initial value is the same as the server socket address host.

public HttpClientRequest

Returns:

a reference to this, so the API can be used fluently
setMaxRedirects
(int
the number of HTTP redirect to follow
maxRedirects
)

Set the max number of HTTP redirects this request will follow.

public HttpClientRequest

Returns:

a reference to this, so the API can be used fluently
setMethod
(HttpMethod
the HTTP method
method
)

Set the HTTP method for this request.

public HttpClientRequest

Returns:

a reference to this, so the API can be used fluently
setPort
(int
the port part of the HTTP/1.1 host header or HTTP/2 authority pseudo header
port
)
Deprecated instead use authority(HostAndPort)

Set the port value of the HTTP/1.1 host header or HTTP/2 authority pseudo header

Keep in mind that this won't change the actual server socket address for this request.

public default HttpClientRequest
setStreamPriority(StreamPriority
the priority of this request's stream
streamPriority
)

Sets the priority of the associated stream.

public HttpClientRequest
setTimeout(long timeout)
Deprecated instead use idleTimeout(long)

Like idleTimeout(long) but with a confusing name (hence the deprecation).

public HttpClientRequest

Returns:

a reference to this, so the API can be used fluently
setURI
(String
the request uri
uri
)

Set the request uri.

public HttpClientRequest
setWriteQueueMaxSize(int
the max size of the write stream
maxSize
)

Redeclares io.vertx.core.streams.WriteStream.setWriteQueueMaxSize.

Set the maximum size of the write queue to maxSize.

public default int

Returns:

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

public HttpClientRequest

Returns:

@return a reference to this, so the API can be used fluently
traceOperation
(String
the operation
op
)

Set the trace operation of this request.

public String

Returns:

the trace operation of this request
traceOperation
()

public HttpVersion

Returns:

the HTTP version for this request
version
()

public Future<Void>

Returns:

a future completed with the result
write
(String
the data chunk
chunk
)

Redeclares io.vertx.core.streams.WriteStream.write.

Write a String to the request body, encoded as UTF-8.

public void
write(String chunk, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.streams.WriteStream.write.

Same as write(String) but with an handler called when the operation completes

public Future<Void>

Returns:

a future completed with the result
write
(String
the data chunk
chunk
,
String
the encoding
enc
)

Write a String to the request body, encoded using the encoding enc.

public void
write(String chunk, String enc, Handler<AsyncResult<Void>> handler)

Same as write(String, String) but with an handler called when the operation completes

public HttpClientRequest

Returns:

a reference to this, so the API can be used fluently
writeCustomFrame
(int
the 8-bit frame type
type
,
int
the 8-bit frame flags
flags
,
Buffer
the frame payload
payload
)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Write an HTTP/2 frame to the request, allowing to extend the HTTP/2 protocol.

public default HttpClientRequest
writeCustomFrame(HttpFrame
the frame to write
frame
)

Like writeCustomFrame(int, int, Buffer) but with an HttpFrame.

Inherited from io.vertx.core.streams.WriteStream:
drainHandlerexceptionHandlerwriteQueueFull