new HttpServerRequest()
Represents a server-side HTTP request.
Instances are created for each request and passed to the user via a handler.
- Source:
Methods
absoluteURI() → {string}
- Source:
Returns:
the absolute URI corresponding to the the HTTP request
-
Type
-
string
body(handler) → {HttpServerRequest}
Same as HttpServerRequest#body but with an handler called when the operation completes
Parameters:
| Name |
Type |
Description |
handler |
function
|
|
- Source:
Returns:
-
Type
-
HttpServerRequest
bodyHandler(bodyHandler) → {HttpServerRequest}
Convenience method for receiving the entire request body in one piece.
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.
Parameters:
| Name |
Type |
Description |
bodyHandler |
function
|
This handler will be called after all the body has been received |
- Source:
Returns:
-
Type
-
HttpServerRequest
bytesRead() → {number}
- Source:
Returns:
the total number of bytes read for the body of the request.
-
Type
-
number
connection() → {HttpConnection}
- Source:
Returns:
the HttpConnection associated with this request
-
Type
-
HttpConnection
customFrameHandler(handler) → {HttpServerRequest}
Set a custom frame handler. The handler will get notified when the http stream receives an custom HTTP/2
frame. HTTP/2 permits extension of the protocol.
Parameters:
| Name |
Type |
Description |
handler |
function
|
|
- Source:
Returns:
a reference to this, so the API can be used fluently
-
Type
-
HttpServerRequest
endHandler(endHandler) → {HttpServerRequest}
Parameters:
| Name |
Type |
Description |
endHandler |
function
|
|
- Source:
Returns:
-
Type
-
HttpServerRequest
exceptionHandler(handler) → {HttpServerRequest}
Parameters:
| Name |
Type |
Description |
handler |
function
|
|
- Source:
Returns:
-
Type
-
HttpServerRequest
fetch(amount) → {HttpServerRequest}
Parameters:
| Name |
Type |
Description |
amount |
number
|
|
- Source:
Returns:
-
Type
-
HttpServerRequest
Returns a map of all form attributes in the request.
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.
HttpServerRequest#setExpectMultipart must be called first before trying to get the form attributes.
- Source:
Returns:
the form attributes
-
Type
-
MultiMap
Return the first form attribute value with the specified name
Parameters:
| Name |
Type |
Description |
attributeName |
string
|
the attribute name |
- Source:
Returns:
the attribute value
-
Type
-
string
Return the first header value with the specified name
Parameters:
| Name |
Type |
Description |
headerName |
string
|
the header name |
- Source:
Returns:
the header value
-
Type
-
string
getParam(paramName) → {string}
Return the first param value with the specified name
Parameters:
| Name |
Type |
Description |
paramName |
string
|
the param name |
- Source:
Returns:
the param value
-
Type
-
string
handler(handler) → {HttpServerRequest}
Parameters:
| Name |
Type |
Description |
handler |
function
|
|
- Source:
Returns:
-
Type
-
HttpServerRequest
- Source:
Returns:
the headers in the request.
-
Type
-
MultiMap
host() → {string}
- Source:
Returns:
the request host. For HTTP2 it returns the pseudo header otherwise it returns the header
-
Type
-
string
isEnded() → {boolean}
Has the request ended? I.e. has the entire request, including the body been read?
- Source:
Returns:
true if ended
-
Type
-
boolean
isExpectMultipart() → {boolean}
- Source:
Returns:
true if we are expecting a multi-part body for this request. See HttpServerRequest#setExpectMultipart.
-
Type
-
boolean
isSSL() → {boolean}
- Source:
Returns:
true if this NetSocket is encrypted via SSL/TLS
-
Type
-
boolean
localAddress() → {SocketAddress}
- Source:
Returns:
the local (server side) address of the server that handles the request
-
Type
-
SocketAddress
method() → {Object}
- Source:
Returns:
the HTTP method for the request.
-
Type
-
Object
netSocket() → {NetSocket}
Get a net socket for the underlying connection of this request.
This method must be called before the server response is ended.
With
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.
- Source:
Returns:
the net socket
-
Type
-
NetSocket
params() → {MultiMap}
- Source:
Returns:
the query parameters in the request
-
Type
-
MultiMap
path() → {string}
- Source:
Returns:
The path part of the uri. For example /somepath/somemorepath/someresource.foo
-
Type
-
string
pause() → {HttpServerRequest}
- Source:
Returns:
-
Type
-
HttpServerRequest
pipe() → {Pipe}
Pause this stream and return a to transfer the elements of this stream to a destination .
The stream will be resumed when the pipe will be wired to a
WriteStream.
- Source:
Returns:
a pipe
-
Type
-
Pipe
pipeTo(dst, handler)
Pipe this
ReadStream to the
WriteStream.
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.
Parameters:
| Name |
Type |
Description |
dst |
WriteStream
|
the destination write stream |
handler |
function
|
|
- Source:
query() → {string}
- Source:
Returns:
the query part of the uri. For example someparam=32&someotherparam=x
-
Type
-
string
rawMethod() → {string}
- Source:
Returns:
the HTTP method as sent by the client
-
Type
-
string
remoteAddress() → {SocketAddress}
- Source:
Returns:
the remote (client side) address of the request
-
Type
-
SocketAddress
response() → {HttpServerResponse}
- Source:
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.
-
Type
-
HttpServerResponse
resume() → {HttpServerRequest}
- Source:
Returns:
-
Type
-
HttpServerRequest
scheme() → {string}
- Source:
Returns:
the scheme of the request
-
Type
-
string
setExpectMultipart(expect) → {HttpServerRequest}
Call this with true if you are expecting a multi-part body to be submitted in the request.
This must be called before the body of the request has been received
Parameters:
| Name |
Type |
Description |
expect |
boolean
|
true - if you are expecting a multi-part body |
- Source:
Returns:
a reference to this, so the API can be used fluently
-
Type
-
HttpServerRequest
streamPriority() → {Object}
- Source:
Returns:
the priority of the associated HTTP/2 stream for HTTP/2 otherwise null
-
Type
-
Object
streamPriorityHandler(handler) → {HttpServerRequest}
Set an handler for stream priority changes
This is not implemented for HTTP/1.x.
Parameters:
| Name |
Type |
Description |
handler |
function
|
the handler to be called when stream priority changes |
- Source:
Returns:
-
Type
-
HttpServerRequest
upgrade() → {ServerWebSocket}
Upgrade the connection to a WebSocket connection.
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.
- Source:
Returns:
the WebSocket
-
Type
-
ServerWebSocket
uploadHandler(uploadHandler) → {HttpServerRequest}
Set an upload handler. The handler will get notified once a new file upload was received to allow you to deal
with the file upload.
Parameters:
| Name |
Type |
Description |
uploadHandler |
function
|
|
- Source:
Returns:
a reference to this, so the API can be used fluently
-
Type
-
HttpServerRequest
uri() → {string}
- Source:
Returns:
the URI of the request. This is usually a relative URI
-
Type
-
string
version() → {Object}
- Source:
Returns:
the HTTP version of the request
-
Type
-
Object