public class HttpClientRequest extends Future<HttpClientResponse> implements WriteStream<Buffer>
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, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) 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, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) 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
Pump to pump data with flow control.
An example of using this class is as follows:
NOTE: This class has been automatically generated from the
original non RX-ified interface using Vert.x codegen.| Modifier and Type | Field and Description |
|---|---|
static io.vertx.lang.rx.TypeArg<HttpClientRequest> |
__TYPE_ARG |
__typeArg_0| Constructor and Description |
|---|
HttpClientRequest(HttpClientRequest delegate) |
| Modifier and Type | Method and Description |
|---|---|
String |
absoluteURI() |
<U> Future<U> |
compose(java.util.function.Function<HttpClientResponse,Future<U>> mapper)
Compose this future with a
mapper function. |
HttpConnection |
connection() |
HttpClientRequest |
connectionHandler(Handler<HttpConnection> handler)
Set a connection handler called when an HTTP connection has been established.
|
HttpClientRequest |
continueHandler(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. |
HttpClientRequest |
drainHandler(Handler<Void> handler)
Set a drain handler on the stream.
|
void |
end()
Same as
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
void |
end(Buffer chunk)
Same as
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
void |
end(Buffer chunk,
Handler<AsyncResult<Void>> handler)
Same as
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
void |
end(Handler<AsyncResult<Void>> handler)
Same as
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
void |
end(String chunk)
Same as
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
void |
end(String chunk,
Handler<AsyncResult<Void>> handler)
Same as
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
void |
end(String chunk,
String enc)
Same as
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
void |
end(String chunk,
String enc,
Handler<AsyncResult<Void>> handler)
Same as
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
boolean |
equals(Object o) |
HttpClientRequest |
exceptionHandler(Handler<Throwable> handler)
Set an exception handler on the write stream.
|
HttpClientRequest |
getDelegate() |
Handler<AsyncResult<HttpClientResponse>> |
getHandler() |
String |
getHost() |
String |
getRawMethod() |
StreamPriority |
getStreamPriority() |
int |
hashCode() |
MultiMap |
headers() |
boolean |
isChunked() |
<U> Future<U> |
map(java.util.function.Function<HttpClientResponse,U> mapper)
Apply a
mapper function on this future. |
HttpMethod |
method()
The HTTP method for the request.
|
static HttpClientRequest |
newInstance(HttpClientRequest arg) |
Future<HttpClientResponse> |
otherwise(java.util.function.Function<Throwable,HttpClientResponse> mapper)
Apply a
mapper function on this future. |
Future<HttpClientResponse> |
otherwise(HttpClientResponse value)
Map the failure of a future to a specific
value. |
Future<HttpClientResponse> |
otherwiseEmpty()
Map the failure of a future to
null. |
String |
path() |
HttpClientRequest |
pushHandler(Handler<HttpClientRequest> handler)
Set a push handler for this request.
The handler is called when the client receives a push promise from the server.
|
HttpClientRequest |
putHeader(CharSequence name,
CharSequence value)
Like
putHeader(java.lang.String, java.lang.String) but using CharSequence |
HttpClientRequest |
putHeader(CharSequence name,
Iterable<CharSequence> values)
Like
putHeader(java.lang.String, java.lang.String) but using CharSequence |
HttpClientRequest |
putHeader(String name,
Iterable<String> values)
Put an HTTP header with multiple values
|
HttpClientRequest |
putHeader(String name,
String value)
Put an HTTP header
|
String |
query() |
Future<HttpClientResponse> |
recover(java.util.function.Function<Throwable,Future<HttpClientResponse>> mapper)
Handles a failure of this Future by returning the result of another Future.
|
boolean |
reset()
Reset this stream with the error code
0. |
boolean |
reset(long 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
When the request has not yet been sent, the request will be aborted and false is returned as indicator. |
HttpClientResponse |
result()
The result of the operation.
|
Completable |
rxEnd()
Same as
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
Completable |
rxEnd(Buffer chunk)
Same as
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
Completable |
rxEnd(String chunk)
Same as
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
Completable |
rxEnd(String chunk,
String enc)
Same as
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
Single<HttpClientResponse> |
rxSetHandler()
Set a handler for the result.
|
Completable |
rxWrite(Buffer data)
Same as but with an
handler called when the operation completes |
Completable |
rxWrite(String chunk)
Same as
write(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
Completable |
rxWrite(String chunk,
String enc)
Same as
write(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
HttpClientRequest |
sendHead()
Forces the head of the request to be written before
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) is called on the request or any data is
written to it. |
HttpClientRequest |
sendHead(Handler<HttpVersion> completionHandler)
Like
sendHead() but with an handler after headers have been sent. |
HttpClientRequest |
setChunked(boolean chunked)
If chunked is true then the request will be set into HTTP chunked mode
|
HttpClientRequest |
setFollowRedirects(boolean followRedirects)
Set the request to follow HTTP redirects up to
HttpClientOptions. |
HttpClientRequest |
setHandler()
Set a handler for the result.
|
HttpClientRequest |
setHandler(Handler<AsyncResult<HttpClientResponse>> handler)
Set a handler for the result.
|
HttpClientRequest |
setHost(String host)
Set the request host.
For HTTP/2 it sets the pseudo header otherwise it sets the header
|
HttpClientRequest |
setMaxRedirects(int maxRedirects)
Set the max number of HTTP redirects this request will follow.
|
HttpClientRequest |
setRawMethod(String method)
Set the value the method to send when the method is used.
|
HttpClientRequest |
setStreamPriority(StreamPriority streamPriority)
Sets the priority of the associated stream.
|
HttpClientRequest |
setTimeout(long timeoutMs)
Set's the amount of time after which if the request does not return any data within the timeout period an
TimeoutException will be passed to the exception handler (if provided) and
the request will be closed. |
HttpClientRequest |
setWriteQueueMaxSize(int maxSize)
Set the maximum size of the write queue to
maxSize. |
int |
streamId() |
io.vertx.reactivex.WriteStreamObserver<Buffer> |
toObserver() |
String |
toString() |
io.vertx.reactivex.WriteStreamSubscriber<Buffer> |
toSubscriber() |
String |
uri() |
void |
write(Buffer data)
Same as but with an
handler called when the operation completes |
void |
write(Buffer data,
Handler<AsyncResult<Void>> handler)
Same as but with an
handler called when the operation completes |
void |
write(String chunk)
Same as
write(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
void |
write(String chunk,
Handler<AsyncResult<Void>> handler)
Same as
write(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
void |
write(String chunk,
String enc)
Same as
write(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
void |
write(String chunk,
String enc,
Handler<AsyncResult<Void>> handler)
Same as
write(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completes |
HttpClientRequest |
writeCustomFrame(HttpFrame frame)
Like
writeCustomFrame(int, int, io.vertx.reactivex.core.buffer.Buffer) but with an HttpFrame. |
HttpClientRequest |
writeCustomFrame(int type,
int flags,
Buffer payload)
Write an HTTP/2 frame to the request, allowing to extend the HTTP/2 protocol.
|
boolean |
writeQueueFull()
This will return
true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize(int) |
cause, failed, failedFuture, failedFuture, future, isComplete, map, mapEmpty, newInstance, newInstance, succeeded, succeededFuture, succeededFutureclone, finalize, getClass, notify, notifyAll, wait, wait, waitnewInstance, newInstancenewInstancepublic static final io.vertx.lang.rx.TypeArg<HttpClientRequest> __TYPE_ARG
public HttpClientRequest(HttpClientRequest delegate)
public String toString()
toString in class Future<HttpClientResponse>public boolean equals(Object o)
equals in class Future<HttpClientResponse>public int hashCode()
hashCode in class Future<HttpClientResponse>public HttpClientRequest getDelegate()
getDelegate in interface StreamBasegetDelegate in interface WriteStream<Buffer>getDelegate in class Future<HttpClientResponse>public io.vertx.reactivex.WriteStreamObserver<Buffer> toObserver()
public io.vertx.reactivex.WriteStreamSubscriber<Buffer> toSubscriber()
public void write(Buffer data, Handler<AsyncResult<Void>> handler)
handler called when the operation completeswrite in interface WriteStream<Buffer>data - handler - public void write(Buffer data)
handler called when the operation completeswrite in interface WriteStream<Buffer>data - public Completable rxWrite(Buffer data)
handler called when the operation completesrxWrite in interface WriteStream<Buffer>data - public boolean writeQueueFull()
true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize(int)writeQueueFull in interface WriteStream<Buffer>public Handler<AsyncResult<HttpClientResponse>> getHandler()
getHandler in class Future<HttpClientResponse>public HttpClientResponse result()
result in class Future<HttpClientResponse>public <U> Future<U> compose(java.util.function.Function<HttpClientResponse,Future<U>> mapper)
mapper function.
When this future (the one on which compose is called) succeeds, the mapper will be called with
the completed value and this mapper returns another future object. This returned future completion will complete
the future returned by this method call.
If the mapper throws an exception, the returned future will be failed with this exception.
When this future fails, the failure will be propagated to the returned future and the mapper
will not be called.
compose in class Future<HttpClientResponse>mapper - the mapper functionpublic <U> Future<U> map(java.util.function.Function<HttpClientResponse,U> mapper)
mapper function on this future.
When this future succeeds, the mapper will be called with the completed value and this mapper
returns a value. This value will complete the future returned by this method call.
If the mapper throws an exception, the returned future will be failed with this exception.
When this future fails, the failure will be propagated to the returned future and the mapper
will not be called.
map in class Future<HttpClientResponse>mapper - the mapper functionpublic Future<HttpClientResponse> recover(java.util.function.Function<Throwable,Future<HttpClientResponse>> mapper)
recover in class Future<HttpClientResponse>mapper - A function which takes the exception of a failure and returns a new future.public Future<HttpClientResponse> otherwise(java.util.function.Function<Throwable,HttpClientResponse> mapper)
mapper function on this future.
When this future fails, the mapper will be called with the completed value and this mapper
returns a value. This value will complete the future returned by this method call.
If the mapper throws an exception, the returned future will be failed with this exception.
When this future succeeds, the result will be propagated to the returned future and the mapper
will not be called.
otherwise in class Future<HttpClientResponse>mapper - the mapper functionpublic Future<HttpClientResponse> otherwise(HttpClientResponse value)
value.
When this future fails, this value will complete the future returned by this method call.
When this future succeeds, the result will be propagated to the returned future.
otherwise in class Future<HttpClientResponse>value - the value that eventually completes the mapped futurepublic Future<HttpClientResponse> otherwiseEmpty()
null.
This is a convenience for future.otherwise((T) null).
When this future fails, the null value will complete the future returned by this method call.
When this future succeeds, the result will be propagated to the returned future.
otherwiseEmpty in class Future<HttpClientResponse>public HttpClientRequest exceptionHandler(Handler<Throwable> handler)
WriteStreamexceptionHandler in interface StreamBaseexceptionHandler in interface WriteStream<Buffer>handler - the exception handlerpublic HttpClientRequest setWriteQueueMaxSize(int maxSize)
WriteStreammaxSize. You will still be able to write to the stream even
if there is more than maxSize items in the write queue. This is used as an indicator by classes such as
Pump to provide flow control.
The value is defined by the implementation of the stream, e.g in bytes for a
NetSocket, the number of Message for a
MessageProducer, etc...setWriteQueueMaxSize in interface WriteStream<Buffer>maxSize - the max size of the write streampublic HttpClientRequest drainHandler(Handler<Void> handler)
WriteStreamPump for an example of this being used.
The stream implementation defines when the drain handler, for example it could be when the queue size has been
reduced to maxSize / 2.drainHandler in interface WriteStream<Buffer>handler - the handlerpublic HttpClientRequest setFollowRedirects(boolean followRedirects)
HttpClientOptions.followRedirects - true to follow HTTP redirectspublic HttpClientRequest setMaxRedirects(int maxRedirects)
0 which means
no redirects.maxRedirects - the number of HTTP redirect to followpublic HttpClientRequest setChunked(boolean chunked)
chunked - true if chunked encodingpublic boolean isChunked()
public HttpMethod method()
public String getRawMethod()
public HttpClientRequest setRawMethod(String method)
method - the raw methodpublic String absoluteURI()
public String uri()
public String path()
public String query()
public HttpClientRequest setHost(String host)
host - public String getHost()
public MultiMap headers()
public HttpClientRequest putHeader(String name, String value)
name - The header namevalue - The header valuepublic void write(String chunk, Handler<AsyncResult<Void>> handler)
write(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completeschunk - handler - public void write(String chunk)
write(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completeschunk - public Completable rxWrite(String chunk)
write(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completeschunk - public void write(String chunk, String enc, Handler<AsyncResult<Void>> handler)
write(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completeschunk - enc - handler - public void write(String chunk, String enc)
write(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completeschunk - enc - public Completable rxWrite(String chunk, String enc)
write(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completeschunk - enc - public HttpClientRequest continueHandler(Handler<Void> handler)
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.
You can then continue to write data to the request body and later end it. This is normally used in conjunction with
the sendHead() method to force the request header to be written before the request has ended.
handler - public HttpClientRequest sendHead()
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) is called on the request or any data is
written to it.
This is normally used to implement HTTP 100-continue handling, see for more information.
public HttpClientRequest sendHead(Handler<HttpVersion> completionHandler)
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.completionHandler - public void end(String chunk, Handler<AsyncResult<Void>> handler)
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completeschunk - handler - public void end(String chunk)
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completeschunk - public Completable rxEnd(String chunk)
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completeschunk - public void end(String chunk, String enc, Handler<AsyncResult<Void>> handler)
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completeschunk - enc - handler - public void end(String chunk, String enc)
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completeschunk - enc - public Completable rxEnd(String chunk, String enc)
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completeschunk - enc - public void end(Buffer chunk, Handler<AsyncResult<Void>> handler)
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completesend in interface WriteStream<Buffer>chunk - handler - public void end(Buffer chunk)
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completesend in interface WriteStream<Buffer>chunk - public Completable rxEnd(Buffer chunk)
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completesrxEnd in interface WriteStream<Buffer>chunk - public void end(Handler<AsyncResult<Void>> handler)
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completesend in interface WriteStream<Buffer>handler - public void end()
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completesend in interface WriteStream<Buffer>public Completable rxEnd()
end(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>) but with an handler called when the operation completesrxEnd in interface WriteStream<Buffer>public HttpClientRequest setTimeout(long timeoutMs)
TimeoutException will be passed to the exception handler (if provided) and
the request will be closed.
Calling this method more than once has the effect of canceling any existing timeout and starting the timeout from scratch.
timeoutMs - The quantity of time in milliseconds.public HttpClientRequest pushHandler(Handler<HttpClientRequest> handler)
HttpClientRequest, the following methods can be called:
In addition the handler should call the setHandler(io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpClientResponse>>) method to set an handler to
process the response.handler - the handlerpublic boolean reset()
0.public boolean reset(long code)
codecode - the error codepublic HttpConnection connection()
HttpConnection associated with this requestpublic HttpClientRequest connectionHandler(Handler<HttpConnection> handler)
handler - the handlerpublic HttpClientRequest writeCustomFrame(int type, int flags, Buffer payload)
The frame is sent immediatly and is not subject to flow control.
This method must be called after the request headers have been sent and only for the protocol HTTP/2.
The sendHead() should be used for this purpose.
type - the 8-bit frame typeflags - the 8-bit frame flagspayload - the frame payloadpublic int streamId()
public HttpClientRequest writeCustomFrame(HttpFrame frame)
writeCustomFrame(int, int, io.vertx.reactivex.core.buffer.Buffer) but with an HttpFrame.frame - the frame to writepublic HttpClientRequest setStreamPriority(StreamPriority streamPriority)
streamPriority - the priority of this request's streampublic StreamPriority getStreamPriority()
nullpublic HttpClientRequest setHandler(Handler<AsyncResult<HttpClientResponse>> handler)
FutureIf the future has already been completed it will be called immediately. Otherwise it will be called when the future is completed.
setHandler in class Future<HttpClientResponse>handler - the Handler that will be called with the resultpublic HttpClientRequest setHandler()
FutureIf the future has already been completed it will be called immediately. Otherwise it will be called when the future is completed.
setHandler in class Future<HttpClientResponse>public Single<HttpClientResponse> rxSetHandler()
FutureIf the future has already been completed it will be called immediately. Otherwise it will be called when the future is completed.
rxSetHandler in class Future<HttpClientResponse>public HttpClientRequest putHeader(CharSequence name, CharSequence value)
putHeader(java.lang.String, java.lang.String) but using CharSequencename - value - public HttpClientRequest putHeader(String name, Iterable<String> values)
name - The header namevalues - The header valuespublic HttpClientRequest putHeader(CharSequence name, Iterable<CharSequence> values)
putHeader(java.lang.String, java.lang.String) but using CharSequencename - values - public static HttpClientRequest newInstance(HttpClientRequest arg)
Copyright © 2019 Eclipse. All rights reserved.