class HttpClientRequest extends WriteStream[Buffer] with ReadStream[HttpClientResponse]
Represents a client-side HTTP request.
Instances are created by an io.vertx.scala.core.http.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 io.vertx.scala.core.http.HttpClientRequest#end methods should be called.
Nothing is actually sent until the request has been internally assigned an HTTP connection.
The io.vertx.scala.core.http.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 io.vertx.scala.core.http.HttpClientRequest#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.scala.core.streams.WriteStream so it can be used with io.vertx.scala.core.streams.Pump to pump data with flow control.
An example of using this class is as follows:
- Alphabetic
- By Inheritance
- HttpClientRequest
- ReadStream
- WriteStream
- StreamBase
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new HttpClientRequest(_asJava: AnyRef)
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
absoluteURI(): String
- returns
the absolute URI corresponding to the the HTTP request
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
asJava: AnyRef
- Definition Classes
- HttpClientRequest → ReadStream → WriteStream → StreamBase
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
connection(): HttpConnection
- returns
the HttpConnection associated with this request
-
def
connectionHandler(handler: Handler[HttpConnection]): HttpClientRequest
Set a connection handler called when an HTTP connection has been established.
Set a connection handler called when an HTTP connection has been established. * @param handler the handler
- returns
a reference to this, so the API can be used fluently
-
def
continueHandler(handler: Handler[Unit]): HttpClientRequest
If you send an HTTP request with the header
Expect
set to the value100-continue
and the server responds with an interim HTTP response with a status code of100
and a continue handler has been set using this method, then thehandler
will be called.If you send an HTTP request with the header
Expect
set to the value100-continue
and the server responds with an interim HTTP response with a status code of100
and a continue handler has been set using this method, then thehandler
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 io.vertx.scala.core.http.HttpClientRequest#sendHead method to force the request header to be written before the request has ended. * @return a reference to this, so the API can be used fluently
-
def
drainHandler(handler: Handler[Unit]): HttpClientRequest
Set a drain handler on the stream.
Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue is ready to accept buffers again. See io.vertx.scala.core.streams.Pump 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
. * @param handler the handler- returns
a reference to this, so the API can be used fluently
- Definition Classes
- HttpClientRequest → WriteStream
-
def
end(): Unit
Ends the request.
Ends the request. If no data has been written to the request body, and io.vertx.scala.core.http.HttpClientRequest#sendHead has not been called then the actual request won't get written until this method gets called.
Once the request has ended, it cannot be used any more,
- Definition Classes
- HttpClientRequest → WriteStream
-
def
end(chunk: Buffer): Unit
Same as io.vertx.scala.core.http.HttpClientRequest#end but writes some data to the request body before ending.
Same as io.vertx.scala.core.http.HttpClientRequest#end but writes some data to the request body before ending. If the request is not chunked and no other data has been written then the
Content-Length
header will be automatically set- Definition Classes
- HttpClientRequest → WriteStream
-
def
end(chunk: String, enc: String): Unit
Same as io.vertx.scala.core.http.HttpClientRequest#end but writes a String with the specified encoding
-
def
end(chunk: String): Unit
Same as io.vertx.scala.core.http.HttpClientRequest#end but writes a String in UTF-8 encoding
-
def
endHandler(endHandler: Handler[Unit]): HttpClientRequest
- Definition Classes
- HttpClientRequest → ReadStream
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
exceptionHandler(handler: Handler[Throwable]): HttpClientRequest
Set an exception handler on the read stream.
Set an exception handler on the read stream. * @param handler the exception handler
- returns
a reference to this, so the API can be used fluently
- Definition Classes
- HttpClientRequest → ReadStream → WriteStream → StreamBase
-
def
fetch(amount: Long): HttpClientRequest
- Definition Classes
- HttpClientRequest → ReadStream
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
getHost(): String
- returns
the request host. For HTTP/2 it returns the
:authority
pseudo header otherwise it returns theHost
header
-
def
getRawMethod(): String
- returns
the raw value of the method this request sends
-
def
getStreamPriority(): StreamPriority
- returns
the priority of the associated HTTP/2 stream for HTTP/2 otherwise
null
see StreamPriority
-
def
handler(handler: Handler[HttpClientResponse]): HttpClientRequest
- Definition Classes
- HttpClientRequest → ReadStream
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
headers(): MultiMap
- returns
The HTTP headers
-
def
isChunked(): Boolean
- returns
Is the request chunked?
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
method(): HttpMethod
The HTTP method for the request.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
path(): String
- returns
The path part of the uri. For example /somepath/somemorepath/someresource.foo
-
def
pause(): HttpClientRequest
- Definition Classes
- HttpClientRequest → ReadStream
-
def
pushHandler(handler: Handler[HttpClientRequest]): HttpClientRequest
Set a push handler for this request.
Set a push handler for this request.
The handler is called when the client receives a push promise from the server. The handler can be called multiple times, for each push promise.
The handler is called with a read-only io.vertx.scala.core.http.HttpClientRequest, the following methods can be called:
- io.vertx.scala.core.http.HttpClientRequest#method
- io.vertx.scala.core.http.HttpClientRequest#uri
- io.vertx.scala.core.http.HttpClientRequest#headers
- io.vertx.scala.core.http.HttpClientRequest#getHost
In addition the handler should call the io.vertx.scala.core.http.HttpClientRequest#handler method to set an handler to process the response.
- handler
the handler
- returns
a reference to this, so the API can be used fluently
-
def
putHeader(name: String, value: String): HttpClientRequest
Put an HTTP header * @param name The header name
Put an HTTP header * @param name The header name
- value
The header value
- returns
a reference to this, so the API can be used fluently
-
def
query(): String
- returns
the query part of the uri. For example someparam=32&someotherparam=x
-
def
reset(code: Long): Boolean
Reset this request:
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.
- code
the error code
- returns
true when reset has been performed
- for HTTP/2, this performs send an HTTP/2 reset frame with the specified error
-
def
reset(): Boolean
Reset this stream with the error code
0
. -
def
resume(): HttpClientRequest
- Definition Classes
- HttpClientRequest → ReadStream
-
def
sendHead(completionHandler: Handler[HttpVersion]): HttpClientRequest
Like io.vertx.scala.core.http.HttpClientRequest#sendHead but with an handler after headers have been sent.
Like io.vertx.scala.core.http.HttpClientRequest#sendHead but with an handler after headers have been sent. The handler will be called with the io.vertx.core.http.HttpVersion if it can be determined or null otherwise.
-
def
sendHead(): HttpClientRequest
Forces the head of the request to be written before io.vertx.scala.core.http.HttpClientRequest#end is called on the request or any data is written to it.
Forces the head of the request to be written before io.vertx.scala.core.http.HttpClientRequest#end 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. * @return a reference to this, so the API can be used fluently
-
def
setChunked(chunked: Boolean): HttpClientRequest
If chunked is true then the request will be set into HTTP chunked mode * @param chunked true if chunked encoding
If chunked is true then the request will be set into HTTP chunked mode * @param chunked true if chunked encoding
- returns
a reference to this, so the API can be used fluently
- def setFollowRedirects(followRedirects: Boolean): HttpClientRequest
-
def
setHost(host: String): HttpClientRequest
Set the request host.
Set the request host.
For HTTP/2 it sets the pseudo header otherwise it sets the header
-
def
setRawMethod(method: String): HttpClientRequest
Set the value the method to send when the method is used.
Set the value the method to send when the method is used. * @param method the raw method
- returns
a reference to this, so the API can be used fluently
-
def
setStreamPriority(streamPriority: StreamPriority): HttpClientRequest
Sets the priority of the associated stream.
Sets the priority of the associated stream.
This is not implemented for HTTP/1.x. * @param streamPriority the priority of this request's stream see StreamPriority
-
def
setTimeout(timeoutMs: Long): HttpClientRequest
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.
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.
Calling this method more than once has the effect of canceling any existing timeout and starting the timeout from scratch. * @param timeoutMs The quantity of time in milliseconds.
- returns
a reference to this, so the API can be used fluently
-
def
setWriteQueueMaxSize(maxSize: Int): HttpClientRequest
Set the maximum size of the write queue to
maxSize
.Set the maximum size of the write queue to
maxSize
. You will still be able to write to the stream even if there is more thanmaxSize
items in the write queue. This is used as an indicator by classes such asPump
to provide flow control.The value is defined by the implementation of the stream, e.g in bytes for a io.vertx.scala.core.net.NetSocket, the number of io.vertx.scala.core.eventbus.Message for a io.vertx.scala.core.eventbus.MessageProducer, etc... * @param maxSize the max size of the write stream
- returns
a reference to this, so the API can be used fluently
- Definition Classes
- HttpClientRequest → WriteStream
-
def
streamId(): 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
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
uri(): String
- returns
The URI of the request.
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
write(chunk: String, enc: String): HttpClientRequest
Write a String to the request body, encoded using the encoding
enc
.Write a String to the request body, encoded using the encoding
enc
. * @return @return a reference to this, so the API can be used fluently -
def
write(chunk: String): HttpClientRequest
Write a String to the request body, encoded as UTF-8.
Write a String to the request body, encoded as UTF-8. * @return @return a reference to this, so the API can be used fluently
-
def
write(data: Buffer): HttpClientRequest
- returns
a reference to this, so the API can be used fluently
- Definition Classes
- HttpClientRequest → WriteStream
-
def
writeCustomFrame(frame: HttpFrame): HttpClientRequest
Like io.vertx.scala.core.http.HttpClientRequest#writeCustomFrame but with an io.vertx.scala.core.http.HttpFrame.
Like io.vertx.scala.core.http.HttpClientRequest#writeCustomFrame but with an io.vertx.scala.core.http.HttpFrame. * @param frame the frame to write
-
def
writeCustomFrame(type: Int, flags: Int, payload: Buffer): HttpClientRequest
Write an HTTP/2 frame to the request, allowing to extend the HTTP/2 protocol.
Write an HTTP/2 frame to the request, allowing to extend the HTTP/2 protocol.
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 io.vertx.scala.core.http.HttpClientRequest#sendHead should be used for this purpose. * @param 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
-
def
writeQueueFull(): Boolean
This will return
true
if there are more bytes in the write queue than the value set using io.vertx.scala.core.http.HttpClientRequest#setWriteQueueMaxSize * @return true if write queue is fullThis will return
true
if there are more bytes in the write queue than the value set using io.vertx.scala.core.http.HttpClientRequest#setWriteQueueMaxSize * @return true if write queue is full- Definition Classes
- HttpClientRequest → WriteStream