Interface HttpServerRequest

    • Field Detail

      • DEFAULT_INVALID_REQUEST_HANDLER

        static final Handler<HttpServerRequest> DEFAULT_INVALID_REQUEST_HANDLER
        The default invalid request handler, it uses the decoderResult() cause and the request information to determine the status code of the response to be sent.
        • When the cause is an instance of io.netty.handler.codec.TooLongFrameException and the error message starts with An HTTP line is larger than the REQUEST_URI_TOO_LONG status is sent
        • Otherwise when the cause is an instance of io.netty.handler.codec.TooLongFrameException and the error message starts with HTTP header is larger than the REQUEST_HEADER_FIELDS_TOO_LARGE status is sent
        • Otherwise then BAD_REQUEST status is sent
    • Method Detail

      • pause

        HttpServerRequest pause()
        Description copied from interface: ReadStream
        Pause the 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.

        Specified by:
        pause in interface ReadStream<Buffer>
        Returns:
        a reference to this, so the API can be used fluently
      • resume

        HttpServerRequest resume()
        Description copied from interface: ReadStream
        Resume reading, and sets the buffer in flowing mode.

        If the ReadStream has been paused, reading will recommence on it.

        Specified by:
        resume in interface ReadStream<Buffer>
        Returns:
        a reference to this, so the API can be used fluently
      • fetch

        HttpServerRequest fetch​(long amount)
        Description copied from interface: ReadStream
        Fetch the specified 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.
        Specified by:
        fetch in interface ReadStream<Buffer>
        Returns:
        a reference to this, so the API can be used fluently
      • endHandler

        HttpServerRequest endHandler​(Handler<Void> endHandler)
        Description copied from interface: ReadStream
        Set an end handler. Once the stream has ended, and there is no more data to be read, this handler will be called.
        Specified by:
        endHandler in interface ReadStream<Buffer>
        Returns:
        a reference to this, so the API can be used fluently
      • version

        HttpVersion version()
        Returns:
        the HTTP version of the request
      • method

        HttpMethod method()
        Returns:
        the HTTP method for the request.
      • isSSL

        default boolean isSSL()
        Returns:
        true if this NetSocket is encrypted via SSL/TLS
      • scheme

        String scheme()
        Returns:
        the scheme of the request
      • uri

        String uri()
        Returns:
        the URI of the request. This is usually a relative URI
      • path

        String path()
        Returns:
        The path part of the uri. For example /somepath/somemorepath/someresource.foo
      • query

        String query()
        Returns:
        the query part of the uri. For example someparam=32&someotherparam=x
      • authority

        HostAndPort authority()
        Returns:
        the request authority. For HTTP/2 the :authority pseudo header is returned, for HTTP/1.x the Host header is returned or null when no such header is present. When the authority string does not carry a port, the HostAndPort.port() returns -1 to indicate the scheme port is prevalent.
      • bytesRead

        long bytesRead()
        Returns:
        the total number of bytes read for the body of the request.
      • response

        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

        MultiMap headers()
        Returns:
        the headers in the request.
      • getHeader

        default String getHeader​(String headerName)
        Return the first header value with the specified name
        Parameters:
        headerName - the header name
        Returns:
        the header value
      • getHeader

        default String getHeader​(CharSequence headerName)
        Return the first header value with the specified name
        Parameters:
        headerName - the header name
        Returns:
        the header value
      • setParamsCharset

        HttpServerRequest setParamsCharset​(String charset)
        Override the charset to use for decoding the query parameter map, when none is set, UTF8 is used.
        Parameters:
        charset - the charset to use for decoding query params
        Returns:
        a reference to this, so the API can be used fluently
      • getParamsCharset

        String getParamsCharset()
        Returns:
        the charset used for decoding query parameters
      • params

        default MultiMap params()
        Returns:
        the query parameters in the request
      • params

        MultiMap params​(boolean semicolonIsNormalChar)
        Parameters:
        semicolonIsNormalChar - whether semicolon is treated as a normal character or a query parameter separator
        Returns:
        the query parameters in the request
      • getParam

        default String getParam​(String paramName)
        Return the first param value with the specified name
        Parameters:
        paramName - the param name
        Returns:
        the param value
      • getParam

        default String getParam​(String paramName,
                                String defaultValue)
        Return the first param value with the specified name or defaultValue when the query param is not present
        Parameters:
        paramName - the param name
        defaultValue - the default value, must be non-null
        Returns:
        the param value or defaultValue when not present
      • remoteAddress

        default SocketAddress remoteAddress()
        Returns:
        the remote address for this connection, possibly null (e.g a server bound on a domain socket). If useProxyProtocol is set to true, the address returned will be of the actual connecting client.
      • localAddress

        default SocketAddress localAddress()
        Returns:
        the local address for this connection, possibly null (e.g a server bound on a domain socket) If useProxyProtocol is set to true, the address returned will be of the proxy.
      • sslSession

        default SSLSession sslSession()
        Returns:
        SSLSession associated with the underlying socket. Returns null if connection is not SSL.
        See Also:
        SSLSession
      • absoluteURI

        String absoluteURI()
        Returns:
        the absolute URI corresponding to the HTTP request
      • bodyHandler

        default HttpServerRequest bodyHandler​(Handler<Buffer> bodyHandler)
        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:
        bodyHandler - This handler will be called after all the body has been received
      • body

        Future<Buffer> body()
        Convenience method for receiving the entire request body in one piece.

        This saves you having to manually set a dataHandler and an endHandler 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.

        Returns:
        a future completed with the body result
      • end

        Future<Void> end()
        Returns a future signaling when the request has been fully received successfully or failed.
        Returns:
        a future completed with the body result
      • setExpectMultipart

        HttpServerRequest setExpectMultipart​(boolean expect)
        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:
        expect - true - if you are expecting a multi-part body
        Returns:
        a reference to this, so the API can be used fluently
      • isExpectMultipart

        boolean isExpectMultipart()
        Returns:
        true if we are expecting a multi-part body for this request. See setExpectMultipart(boolean).
      • uploadHandler

        HttpServerRequest uploadHandler​(Handler<HttpServerFileUpload> uploadHandler)
        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.
        Returns:
        a reference to this, so the API can be used fluently
      • formAttributes

        MultiMap formAttributes()
        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.

        setExpectMultipart(boolean) must be called first before trying to get the form attributes.

        Returns:
        the form attributes
      • getFormAttribute

        String getFormAttribute​(String attributeName)
        Return the first form attribute value with the specified name
        Parameters:
        attributeName - the attribute name
        Returns:
        the attribute value
      • streamId

        default int streamId()
        Returns:
        the id of the stream of this request, -1 when it is not yet determined, i.e the request has not been yet sent or it is not supported HTTP/1.x
      • canUpgradeToWebSocket

        default boolean canUpgradeToWebSocket()
        Returns:
        whether this request can be upgraded to a WebSocket, implying it uses HTTP/1.x and presents the correct characteristics for a proper upgrade.
      • toWebSocket

        Future<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(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.

        Returns:
        a future notified with the upgraded WebSocket
      • isEnded

        boolean isEnded()
        Has the request ended? I.e. has the entire request, including the body been read?
        Returns:
        true if ended
      • customFrameHandler

        HttpServerRequest customFrameHandler​(Handler<HttpFrame> handler)
        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.
        Returns:
        a reference to this, so the API can be used fluently
      • streamPriority

        default StreamPriority streamPriority()
        Returns:
        the priority of the associated HTTP/2 stream for HTTP/2 otherwise null
      • streamPriorityHandler

        HttpServerRequest streamPriorityHandler​(Handler<StreamPriority> handler)
        Set an handler for stream priority changes

        This is not implemented for HTTP/1.x.

        Parameters:
        handler - the handler to be called when stream priority changes
      • getCookie

        Cookie getCookie​(String name)
        Get the cookie with the specified name. NOTE: this will return just the 1st Cookie that matches the given name, to get all cookies for this name see: cookies(String)
        Parameters:
        name - the cookie name
        Returns:
        the cookie or null if not found.
      • getCookie

        Cookie getCookie​(String name,
                         String domain,
                         String path)
        Get the cookie with the specified <name, domain, path>.
        Parameters:
        name - the cookie name
        domain - the cookie domain
        path - the cookie path
        Returns:
        the cookie or null if not found.
      • cookieCount

        default int cookieCount()
        Returns:
        the number of cookies in the cookie jar.
      • cookieMap

        @Deprecated
        default Map<String,​Cookie> cookieMap()
        Deprecated.
        the implementation made a wrong assumption that cookies could be identified only by their name. The RFC states that the tuple of <name, domain, path> is the unique identifier. When more than one cookie has the same name, the map will hold that lost one to be parsed and any previously parsed value will be silently overwritten.
        Returns:
        a map of all the cookies.
      • cookies

        Set<Cookie> cookies​(String name)
        Returns a read only set of parsed cookies that match the given name, or an empty set. Several cookies may share the same name but have different keys. A cookie is unique by its <name, domain, path> tuple. The set entries are references to the request original set. This means that performing property changes in the cookie objects will affect the original object too. NOTE: the returned Set is read-only. This means any attempt to modify (add or remove to the set), will throw UnsupportedOperationException.
        Parameters:
        name - the name to be matches
        Returns:
        the matching cookies or empty set
      • cookies

        Set<Cookie> cookies()
        Returns a modifiable set of parsed cookies from the COOKIE header. Several cookies may share the same name but have different keys. A cookie is unique by its <name, domain, path> tuple. Request cookies are directly linked to response cookies. Any modification to a cookie object in the returned set will mark the cookie to be included in the HTTP response. Removing a cookie from the set, will also mean that it will be removed from the response, regardless if it was modified or not.
        Returns:
        a set with all cookies in the cookie jar.
      • routed

        default HttpServerRequest routed​(String route)
        Marks this request as being routed to the given route. This is purely informational and is being provided to metrics.
        Parameters:
        route - The route this request has been routed to.