Class HttpServerRequest
- java.lang.Object
-
- io.vertx.mutiny.core.http.HttpServerRequest
-
- All Implemented Interfaces:
ReadStream<Buffer>
,StreamBase
public class HttpServerRequest extends Object implements ReadStream<Buffer>
Represents a server-side HTTP request.Instances are created for each request and passed to the user via a handler.
Each instance of this class is associated with a corresponding
HttpServerResponse
instance viaresponse()
.It implements
ReadStream
so it can be used withPipe
to pipe data with flow control.original
non Mutiny-ified interface using Vert.x codegen.
-
-
Field Summary
Fields Modifier and Type Field Description static TypeArg<HttpServerRequest>
__TYPE_ARG
-
Constructor Summary
Constructors Constructor Description HttpServerRequest(io.vertx.core.http.HttpServerRequest delegate)
HttpServerRequest(Object delegate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
absoluteURI()
io.smallrye.mutiny.Uni<Buffer>
body()
Same asbody()
but with anhandler
called when the operation completesBuffer
bodyAndAwait()
Blocking variant ofbody()
.void
bodyAndForget()
Variant ofbody()
that ignores the result of the operation.HttpServerRequest
bodyHandler(Consumer<Buffer> bodyHandler)
long
bytesRead()
HttpConnection
connection()
int
cookieCount()
Map<String,Cookie>
cookieMap()
HttpServerRequest
customFrameHandler(Consumer<HttpFrame> handler)
io.smallrye.mutiny.Uni<Void>
end()
Same asend()
but with anhandler
called when the operation completesVoid
endAndAwait()
Blocking variant ofend()
.void
endAndForget()
Variant ofend()
that ignores the result of the operation.HttpServerRequest
endHandler(Runnable endHandler)
boolean
equals(Object o)
HttpServerRequest
exceptionHandler(Consumer<Throwable> handler)
HttpServerRequest
fetch(long amount)
MultiMap
formAttributes()
Cookie
getCookie(String name)
io.vertx.core.http.HttpServerRequest
getDelegate()
String
getFormAttribute(String attributeName)
String
getHeader(CharSequence headerName)
String
getHeader(String headerName)
String
getParam(String paramName)
HttpServerRequest
handler(Consumer<Buffer> handler)
int
hashCode()
MultiMap
headers()
String
host()
boolean
isEnded()
boolean
isExpectMultipart()
boolean
isSSL()
SocketAddress
localAddress()
io.vertx.core.http.HttpMethod
method()
static HttpServerRequest
newInstance(io.vertx.core.http.HttpServerRequest arg)
MultiMap
params()
String
path()
HttpServerRequest
pause()
Pipe<Buffer>
pipe()
io.smallrye.mutiny.Uni<Void>
pipeTo(WriteStream<Buffer> dst)
Pipe thisReadStream
to theWriteStream
.Void
pipeToAndAwait(WriteStream<Buffer> dst)
Blocking variant ofio.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream
.) void
pipeToAndForget(WriteStream<Buffer> dst)
Variant ofio.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream
that ignores the result of the operation.) String
query()
SocketAddress
remoteAddress()
HttpServerResponse
response()
HttpServerRequest
resume()
HttpServerRequest
routed(String route)
String
scheme()
HttpServerRequest
setExpectMultipart(boolean expect)
SSLSession
sslSession()
int
streamId()
io.vertx.core.http.StreamPriority
streamPriority()
HttpServerRequest
streamPriorityHandler(Consumer<io.vertx.core.http.StreamPriority> handler)
Iterable<Buffer>
toBlockingIterable()
Stream<Buffer>
toBlockingStream()
io.smallrye.mutiny.Multi<Buffer>
toMulti()
io.smallrye.mutiny.Uni<NetSocket>
toNetSocket()
Establish a TCP tunnel with the client.NetSocket
toNetSocketAndAwait()
Blocking variant oftoNetSocket()
.void
toNetSocketAndForget()
Variant oftoNetSocket()
that ignores the result of the operation.String
toString()
io.smallrye.mutiny.Uni<ServerWebSocket>
toWebSocket()
Upgrade the connection of the current request to a WebSocket.ServerWebSocket
toWebSocketAndAwait()
Blocking variant oftoWebSocket()
.void
toWebSocketAndForget()
Variant oftoWebSocket()
that ignores the result of the operation.HttpServerRequest
uploadHandler(Consumer<HttpServerFileUpload> uploadHandler)
String
uri()
io.vertx.core.http.HttpVersion
version()
-
-
-
Field Detail
-
__TYPE_ARG
public static final TypeArg<HttpServerRequest> __TYPE_ARG
-
-
Constructor Detail
-
HttpServerRequest
public HttpServerRequest(io.vertx.core.http.HttpServerRequest delegate)
-
HttpServerRequest
public HttpServerRequest(Object delegate)
-
-
Method Detail
-
getDelegate
public io.vertx.core.http.HttpServerRequest getDelegate()
- Specified by:
getDelegate
in interfaceReadStream<Buffer>
- Specified by:
getDelegate
in interfaceStreamBase
-
pipe
public Pipe<Buffer> pipe()
- Specified by:
pipe
in interfaceReadStream<Buffer>
- Returns:
- a pipe
-
pipeTo
public io.smallrye.mutiny.Uni<Void> pipeTo(WriteStream<Buffer> dst)
Pipe thisReadStream
to theWriteStream
.Elements emitted by this stream will be written to the write stream until this stream ends or fails.
Once this stream has ended or failed, the write stream will be ended and the
handler
will be called with the result.Unlike the bare Vert.x variant, this method returns a
Uni
. Don't forget to subscribe on it to trigger the operation.- Specified by:
pipeTo
in interfaceReadStream<Buffer>
- Parameters:
dst
- the destination write stream- Returns:
- the
uni
firing the result of the operation when completed, or a failure if the operation failed.
-
pipeToAndAwait
public Void pipeToAndAwait(WriteStream<Buffer> dst)
Blocking variant ofio.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream
.) 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:
pipeToAndAwait
in interfaceReadStream<Buffer>
- Parameters:
dst
- the destination write stream- Returns:
- the Void instance produced by the operation.
-
pipeToAndForget
public void pipeToAndForget(WriteStream<Buffer> dst)
Variant ofio.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream
that ignores the result of the operation.) This method subscribes on the result of
io.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream
, but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from) io.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream
but you don't need to compose it with other operations.) - Specified by:
pipeToAndForget
in interfaceReadStream<Buffer>
- Parameters:
dst
- the destination write stream
-
exceptionHandler
public HttpServerRequest exceptionHandler(Consumer<Throwable> handler)
- Specified by:
exceptionHandler
in interfaceReadStream<Buffer>
- Specified by:
exceptionHandler
in interfaceStreamBase
- Parameters:
handler
- the exception handler- Returns:
-
handler
public HttpServerRequest handler(Consumer<Buffer> handler)
- Specified by:
handler
in interfaceReadStream<Buffer>
- Returns:
-
pause
public HttpServerRequest pause()
- Specified by:
pause
in interfaceReadStream<Buffer>
- Returns:
- a reference to this, so the API can be used fluently
-
resume
public HttpServerRequest resume()
- Specified by:
resume
in interfaceReadStream<Buffer>
- Returns:
- a reference to this, so the API can be used fluently
-
fetch
public HttpServerRequest fetch(long amount)
- Specified by:
fetch
in interfaceReadStream<Buffer>
- Returns:
- a reference to this, so the API can be used fluently
-
endHandler
public HttpServerRequest endHandler(Runnable endHandler)
- Specified by:
endHandler
in interfaceReadStream<Buffer>
- Returns:
-
version
public io.vertx.core.http.HttpVersion version()
- Returns:
- the HTTP version of the request
-
method
public io.vertx.core.http.HttpMethod method()
- Returns:
- the HTTP method for the request.
-
isSSL
public boolean isSSL()
- Returns:
- true if this
NetSocket
is encrypted via SSL/TLS
-
scheme
public String scheme()
- Returns:
- the scheme of the request
-
uri
public String uri()
- Returns:
- the URI of the request. This is usually a relative URI
-
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
-
host
public String host()
- Returns:
- the request host. For HTTP2 it returns the pseudo header otherwise it returns the header
-
bytesRead
public long bytesRead()
- Returns:
- the total number of bytes read for the body of the request.
-
response
public HttpServerResponse response()
- Returns:
- the response. Each instance of this class has an
HttpServerResponse
instance attached to it. This is used to send the response back to the client.
-
headers
public MultiMap headers()
- Returns:
- the headers in the request.
-
getHeader
public String getHeader(String headerName)
- Parameters:
headerName
- the header name- Returns:
- the header value
-
params
public MultiMap params()
- Returns:
- the query parameters in the request
-
getParam
public String getParam(String paramName)
- Parameters:
paramName
- the param name- Returns:
- the param value
-
remoteAddress
public SocketAddress remoteAddress()
- Returns:
- the remote address for this connection, possibly
null
(e.g a server bound on a domain socket). IfuseProxyProtocol
is set totrue
, the address returned will be of the actual connecting client.
-
localAddress
public SocketAddress localAddress()
- Returns:
- the local address for this connection, possibly
null
(e.g a server bound on a domain socket) IfuseProxyProtocol
is set totrue
, the address returned will be of the proxy.
-
absoluteURI
public String absoluteURI()
- Returns:
- the absolute URI corresponding to the HTTP request
-
bodyHandler
public HttpServerRequest bodyHandler(Consumer<Buffer> bodyHandler)
- Parameters:
bodyHandler
- This handler will be called after all the body has been received- Returns:
-
body
public io.smallrye.mutiny.Uni<Buffer> body()
Same asbody()
but with anhandler
called when the operation completesUnlike 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.
-
bodyAndAwait
public Buffer bodyAndAwait()
Blocking variant ofbody()
.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 Buffer instance produced by the operation.
-
bodyAndForget
public void bodyAndForget()
-
end
public io.smallrye.mutiny.Uni<Void> end()
Same asend()
but with anhandler
called when the operation completesUnlike 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.
-
endAndAwait
public Void endAndAwait()
Blocking variant ofend()
.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.
-
endAndForget
public void endAndForget()
-
toNetSocket
public io.smallrye.mutiny.Uni<NetSocket> toNetSocket()
Establish a TCP tunnel with the client.This must be called only for
CONNECT
HTTP method and before any response is sent.Calling this sends a
200
response with nocontent-length
header set and then provides theNetSocket
for handling the created tunnel. Any HTTP header set on the response before calling this method will be sent.server.requestHandler(req -> { if (req.method() == HttpMethod.CONNECT) { // Send a 200 response to accept the connect NetSocket socket = req.netSocket(); socket.handler(buff -> { socket.write(buff); }); } ... });
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.
-
toNetSocketAndAwait
public NetSocket toNetSocketAndAwait()
Blocking variant oftoNetSocket()
.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 NetSocket instance produced by the operation.
-
toNetSocketAndForget
public void toNetSocketAndForget()
Variant oftoNetSocket()
that ignores the result of the operation.This method subscribes on the result of
toNetSocket()
, but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation fromtoNetSocket()
but you don't need to compose it with other operations.
-
setExpectMultipart
public HttpServerRequest setExpectMultipart(boolean expect)
- Parameters:
expect
- true - if you are expecting a multi-part body- Returns:
- a reference to this, so the API can be used fluently
-
isExpectMultipart
public boolean isExpectMultipart()
- Returns:
- true if we are expecting a multi-part body for this request. See
setExpectMultipart(boolean)
.
-
uploadHandler
public HttpServerRequest uploadHandler(Consumer<HttpServerFileUpload> uploadHandler)
- Parameters:
uploadHandler
-- Returns:
-
formAttributes
public MultiMap formAttributes()
- Returns:
- the form attributes
-
getFormAttribute
public String getFormAttribute(String attributeName)
- Parameters:
attributeName
- the attribute name- Returns:
- the attribute value
-
streamId
public int streamId()
- Returns:
- the id of the stream of this request, when it is not yet determined, i.e the request has not been yet sent or it is not supported HTTP/1.x
-
toWebSocket
public io.smallrye.mutiny.Uni<ServerWebSocket> toWebSocket()
Upgrade the connection of the current request to a WebSocket.This is an alternative way of handling WebSockets and can only be used if no WebSocket handler is set on the
HttpServer
, and can only be used during the upgrade request during the WebSocket handshake.Both
handler(java.util.function.Consumer<io.vertx.mutiny.core.buffer.Buffer>)
andendHandler(java.lang.Runnable)
will be set to get the full body of the request that is necessary to perform the WebSocket handshake.If you need to do an asynchronous upgrade, i.e not performed immediately in your request handler, you need to
pause()
the request in order to not lose HTTP events necessary to upgrade the request.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.
-
toWebSocketAndAwait
public ServerWebSocket toWebSocketAndAwait()
Blocking variant oftoWebSocket()
.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 ServerWebSocket instance produced by the operation.
-
toWebSocketAndForget
public void toWebSocketAndForget()
Variant oftoWebSocket()
that ignores the result of the operation.This method subscribes on the result of
toWebSocket()
, but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation fromtoWebSocket()
but you don't need to compose it with other operations.
-
isEnded
public boolean isEnded()
- Returns:
- true if ended
-
customFrameHandler
public HttpServerRequest customFrameHandler(Consumer<HttpFrame> handler)
- Parameters:
handler
-- Returns:
-
connection
public HttpConnection connection()
- Returns:
- the
HttpConnection
associated with this request
-
streamPriority
public io.vertx.core.http.StreamPriority streamPriority()
- Returns:
- the priority of the associated HTTP/2 stream for HTTP/2 otherwise
null
-
streamPriorityHandler
public HttpServerRequest streamPriorityHandler(Consumer<io.vertx.core.http.StreamPriority> handler)
- Parameters:
handler
- the handler to be called when stream priority changes- Returns:
-
getCookie
public Cookie getCookie(String name)
- Parameters:
name
- the cookie name- Returns:
- the cookie
-
cookieCount
public int cookieCount()
- Returns:
- the number of cookieMap.
-
routed
public HttpServerRequest routed(String route)
- Parameters:
route
- The route this request has been routed to.- Returns:
- the instance of HttpServerRequest to chain method calls.
-
getHeader
public String getHeader(CharSequence headerName)
- Parameters:
headerName
- the header name- Returns:
- the header value
-
sslSession
public SSLSession sslSession()
- Returns:
- SSLSession associated with the underlying socket. Returns null if connection is not SSL.
-
toMulti
public io.smallrye.mutiny.Multi<Buffer> toMulti()
- Specified by:
toMulti
in interfaceReadStream<Buffer>
-
newInstance
public static HttpServerRequest newInstance(io.vertx.core.http.HttpServerRequest arg)
-
-