public interface HttpServerRequest extends ReadStream<Buffer>
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 via
response()
.
It implements ReadStream
so it can be used with
Pump
to pump data with flow control.
Modifier and Type | Method and Description |
---|---|
String |
absoluteURI() |
default HttpServerRequest |
bodyHandler(Handler<Buffer> bodyHandler)
Convenience method for receiving the entire request body in one piece.
|
long |
bytesRead() |
HttpConnection |
connection() |
int |
cookieCount() |
Map<String,Cookie> |
cookieMap() |
HttpServerRequest |
customFrameHandler(Handler<HttpFrame> handler)
Set a custom frame handler.
|
HttpServerRequest |
endHandler(Handler<Void> endHandler)
Set an end handler.
|
HttpServerRequest |
exceptionHandler(Handler<Throwable> handler)
Set an exception handler on the read stream.
|
HttpServerRequest |
fetch(long amount)
Fetch the specified
amount of elements. |
MultiMap |
formAttributes()
Returns a map of all form attributes in the request.
|
Cookie |
getCookie(String name)
Get the cookie with the specified name.
|
String |
getFormAttribute(String attributeName)
Return the first form attribute value with the specified name
|
String |
getHeader(CharSequence headerName)
Return the first header value with the specified name
|
String |
getHeader(String headerName)
Return the first header value with the specified name
|
String |
getParam(String paramName)
Return the first param value with the specified name
|
HttpServerRequest |
handler(Handler<Buffer> handler)
Set a data handler.
|
MultiMap |
headers() |
String |
host() |
boolean |
isEnded()
Has the request ended? I.e.
|
boolean |
isExpectMultipart() |
boolean |
isSSL() |
SocketAddress |
localAddress() |
HttpMethod |
method() |
NetSocket |
netSocket()
Deprecated.
|
MultiMap |
params() |
String |
path() |
HttpServerRequest |
pause()
Pause the
ReadStream , it sets the buffer in fetch mode and clears the actual demand. |
X509Certificate[] |
peerCertificateChain()
Note: Java SE 5+ recommends to use javax.net.ssl.SSLSession#getPeerCertificates() instead of
of javax.net.ssl.SSLSession#getPeerCertificateChain() which this method is based on.
|
String |
query() |
String |
rawMethod() |
SocketAddress |
remoteAddress() |
HttpServerResponse |
response() |
HttpServerRequest |
resume()
Resume reading, and sets the buffer in
flowing mode. |
String |
scheme() |
HttpServerRequest |
setExpectMultipart(boolean expect)
Call this with true if you are expecting a multi-part body to be submitted in the request.
|
SSLSession |
sslSession() |
default int |
streamId() |
default StreamPriority |
streamPriority() |
HttpServerRequest |
streamPriorityHandler(Handler<StreamPriority> handler)
Set an handler for stream priority changes
|
default void |
toNetSocket(Handler<AsyncResult<NetSocket>> handler)
Establish a TCP tunnel with the client.
|
default void |
toWebSocket(Handler<AsyncResult<ServerWebSocket>> handler)
Upgrade the connection of the current request to a WebSocket.
|
ServerWebSocket |
upgrade()
|
HttpServerRequest |
uploadHandler(Handler<HttpServerFileUpload> uploadHandler)
Set an upload handler.
|
String |
uri() |
HttpVersion |
version() |
pipe, pipeTo, pipeTo
HttpServerRequest exceptionHandler(Handler<Throwable> handler)
ReadStream
exceptionHandler
in interface ReadStream<Buffer>
exceptionHandler
in interface StreamBase
handler
- the exception handlerHttpServerRequest handler(Handler<Buffer> handler)
ReadStream
handler
in interface ReadStream<Buffer>
HttpServerRequest pause()
ReadStream
ReadStream
, it sets the buffer in fetch
mode and clears the actual demand.
While it's paused, no data will be sent to the data handler
.
pause
in interface ReadStream<Buffer>
HttpServerRequest resume()
ReadStream
flowing
mode.
If the ReadStream
has been paused, reading will recommence on it.resume
in interface ReadStream<Buffer>
HttpServerRequest fetch(long amount)
ReadStream
amount
of elements. If the ReadStream
has been paused, reading will
recommence with the specified amount
of items, otherwise the specified amount
will
be added to the current stream demand.fetch
in interface ReadStream<Buffer>
HttpServerRequest endHandler(Handler<Void> endHandler)
ReadStream
endHandler
in interface ReadStream<Buffer>
HttpVersion version()
HttpMethod method()
String rawMethod()
boolean isSSL()
NetSocket
is encrypted via SSL/TLSString scheme()
String uri()
String path()
String query()
String host()
long bytesRead()
HttpServerResponse response()
HttpServerResponse
instance attached to it. This is used
to send the response back to the client.MultiMap headers()
String getHeader(String headerName)
headerName
- the header nameString getHeader(CharSequence headerName)
headerName
- the header nameMultiMap params()
String getParam(String paramName)
paramName
- the param nameSocketAddress remoteAddress()
null
(e.g a server bound on a domain socket)SocketAddress localAddress()
null
(e.g a server bound on a domain socket)SSLSession sslSession()
SSLSession
X509Certificate[] peerCertificateChain() throws SSLPeerUnverifiedException
sslSession()
to
access that method.SSLPeerUnverifiedException
- SSL peer's identity has not been verified.SSLSession.getPeerCertificateChain()
,
sslSession()
String absoluteURI()
default HttpServerRequest bodyHandler(Handler<Buffer> bodyHandler)
This saves the user having to manually setting a data and end handler and append the chunks of the body until the whole body received. Don't use this if your request body is large - you could potentially run out of RAM.
bodyHandler
- This handler will be called after all the body has been received@Deprecated NetSocket netSocket()
toNetSocket(io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.core.net.NetSocket>>)
CONNECT
requests, a 200
response is sent with no content-length
header set
before returning the socket.
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); }); } ... });For other HTTP/1 requests once you have called this method, you must handle writing to the connection yourself using the net socket, the server request instance will no longer be usable as normal. USE THIS WITH CAUTION! Writing to the socket directly if you don't know what you're doing can easily break the HTTP protocol. With HTTP/2, a
200
response is always sent with no content-length
header set before returning the socket
like in the CONNECT
case above.
IllegalStateException
- when the socket can't be createddefault void toNetSocket(Handler<AsyncResult<NetSocket>> handler)
This must be called only for CONNECT
HTTP method and before any response is sent.
Calling this sends a 200
response with no content-length
header set and
then provides the NetSocket
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); }); } ... });
handler
- the completion handlerHttpServerRequest setExpectMultipart(boolean expect)
expect
- true - if you are expecting a multi-part bodyboolean isExpectMultipart()
setExpectMultipart(boolean)
.HttpServerRequest uploadHandler(Handler<HttpServerFileUpload> uploadHandler)
MultiMap formAttributes()
Be aware that the attributes will only be available after the whole body has been received, i.e. after the request end handler has been called.
setExpectMultipart(boolean)
must be called first before trying to get the form attributes.
String getFormAttribute(String attributeName)
attributeName
- the attribute namedefault int streamId()
@Deprecated ServerWebSocket upgrade()
toWebSocket(io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.core.http.ServerWebSocket>>)
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.
IllegalStateException
- if the current request cannot be upgraded, when it happens an appropriate response
is sentdefault void toWebSocket(Handler<AsyncResult<ServerWebSocket>> handler)
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(Handler)
and endHandler(Handler)
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.
handler
- the completion handlerboolean isEnded()
HttpServerRequest customFrameHandler(Handler<HttpFrame> handler)
HttpConnection connection()
HttpConnection
associated with this requestdefault StreamPriority streamPriority()
null
HttpServerRequest streamPriorityHandler(Handler<StreamPriority> handler)
This is not implemented for HTTP/1.x.
handler
- the handler to be called when stream priority changesCookie getCookie(String name)
name
- the cookie nameint cookieCount()
Copyright © 2023 Eclipse. All rights reserved.