io.vertx.core.http

## Interface HttpServerRequest

- All Superinterfaces:
    ReadStream<Buffer>, StreamBase

      public interface HttpServerRequest
      extends 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 via `response()`.

  It implements `ReadStream` so it can be used with `Pipe` to pipe data with flow control.

  Author:
    Tim Fox

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `absoluteURI()`
    `Future<Buffer>` | `body()` Convenience method for receiving the entire request body in one piece.
    `default HttpServerRequest` | `body(Handler<AsyncResult<Buffer>> handler)` Same as `body()` but with an `handler` called when the operation completes
    `default HttpServerRequest` | `bodyHandler(Handler<Buffer> bodyHandler)` Convenience method for receiving the entire request body in one piece.
    `long` | `bytesRead()`
    `HttpConnection` | `connection()`
    `default int` | `cookieCount()`
    `Map<String,Cookie>` | `cookieMap()`
    `HttpServerRequest` | `customFrameHandler(Handler<HttpFrame> handler)` Set a custom frame handler.
    `Future<Void>` | `end()` Returns a future signaling when the request has been fully received successfully or failed.
    `default void` | `end(Handler<AsyncResult<Void>> handler)` Same as `end()` but with an `handler` called when the operation completes
    `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.
    `default 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
    `default String` | `getHeader(CharSequence headerName)` Return the first header value with the specified name
    `default String` | `getHeader(String headerName)` Return the first header value with the specified name
    `default 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()`
    `default boolean` | `isSSL()`
    `default SocketAddress` | `localAddress()`
    `HttpMethod` | `method()`
    `NetSocket` | `netSocket()` Get a net socket for the underlying connection of this request.
    `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()`
    `default SocketAddress` | `remoteAddress()`
    `HttpServerResponse` | `response()`
    `HttpServerRequest` | `resume()` Resume reading, and sets the buffer in `flowing` mode.
    `default HttpServerRequest` | `routed(String route)` Marks this request as being routed to the given route.
    `String` | `scheme()`
    `HttpServerRequest` | `setExpectMultipart(boolean expect)` Call this with true if you are expecting a multi-part body to be submitted in the request.
    `default SSLSession` | `sslSession()`
    `default StreamPriority` | `streamPriority()`
    `HttpServerRequest` | `streamPriorityHandler(Handler<StreamPriority> handler)` Set an handler for stream priority changes
    `ServerWebSocket` | `upgrade()` Upgrade the connection to a WebSocket connection.
    `HttpServerRequest` | `uploadHandler(Handler<HttpServerFileUpload> uploadHandler)` Set an upload handler.
    `String` | `uri()`
    `HttpVersion` | `version()`

    - ### Methods inherited from interface io.vertx.core.streams.ReadStream

      `pipe, pipeTo, pipeTo`

- - ### Method Detail

    - #### exceptionHandler

          HttpServerRequest exceptionHandler(Handler<Throwable> handler)

      Description copied from interface: `ReadStream`
      Set an exception handler on the read stream.
      Specified by:
        `exceptionHandler` in interface `ReadStream<Buffer>`
      Specified by:
        `exceptionHandler` in interface `StreamBase`
      Parameters:
        `handler` - the exception handler
      Returns:
        a reference to this, so the API can be used fluently

    - #### handler

          HttpServerRequest handler(Handler<Buffer> handler)

      Description copied from interface: `ReadStream`
      Set a data handler. As data is read, the handler will be called with the data.
      Specified by:
        `handler` in interface `ReadStream<Buffer>`
      Returns:
        a reference to this, so the API can be used fluently

    - #### 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

    - #### host

          String host()

      Returns:
        the request host. For HTTP2 it returns the :authority pseudo header otherwise it returns the Host header

    - #### 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

    - #### params

          MultiMap params()

      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

    - #### 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`

    - #### peerCertificateChain

          X509Certificate[] peerCertificateChain()
                                          throws SSLPeerUnverifiedException

      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. Use `sslSession()` to access that method.
      Returns:
        an ordered array of the peer certificates. Returns null if connection is not SSL.
      Throws:
        `SSLPeerUnverifiedException` - SSL peer's identity has not been verified.
      See Also:
        `SSLSession.getPeerCertificateChain()`, `sslSession()`

    - #### absoluteURI

          String absoluteURI()

      Returns:
        the absolute URI corresponding to the 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

          default HttpServerRequest body(Handler<AsyncResult<Buffer>> handler)

      Same as `body()` but with an `handler` called when the operation completes

    - #### 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

          default void end(Handler<AsyncResult<Void>> handler)

      Same as `end()` but with an `handler` called when the operation completes

    - #### 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

    - #### netSocket

          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.

      Returns:
        the net socket
      Throws:
        `IllegalStateException` - when the socket can't be created

    - #### 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

    - #### upgrade

          ServerWebSocket upgrade()

      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.

      Returns:
        the WebSocket
      Throws:
        `IllegalStateException` - if the current request cannot be upgraded, when it happens an appropriate response is sent

    - #### 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

    - #### connection

          HttpConnection connection()

      Returns:
        the `HttpConnection` associated with this request

    - #### 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

          default Cookie getCookie(String name)

      Get the cookie with the specified name.
      Parameters:
        `name` - the cookie name
      Returns:
        the cookie

    - #### cookieCount

          default int cookieCount()

      Returns:
        the number of cookieMap.

    - #### cookieMap

          Map<String,Cookie> cookieMap()

      Returns:
        a map of all the cookies.

    - #### 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.

Copyright © 2020 Eclipse. All rights reserved.