Interface HttpEvent

All Superinterfaces:
Event<io.netty.handler.codec.http.HttpRequest>, HttpProtocolRequest

public interface HttpEvent extends Event<io.netty.handler.codec.http.HttpRequest>, HttpProtocolRequest
Author:
Tim Boudreau
  • Method Details

    • method

      com.mastfrog.acteur.util.HttpMethod method()
      Get the HTTP method for this request
      Returns:
      A method name
      Since:
      2.0.0
    • header

      String header(CharSequence nm)
      Get a single HTTP header
      Parameters:
      nm - The header name
      Returns:
      The header
      Since:
      2.0.0
    • urlParameter

      String urlParameter(String param)
      Get a single request parameter
      Parameters:
      param - The parameter name
      Returns:
      A parameter or null
      Since:
      2.0.0
    • path

      Path path()
      Get the logical path of this request. The web application may be "mounted" on some path (i.e. it is being proxied as part of a larger site). This method will give you the path, sans the base portion of it. So, if a request URL might be for http://example.com/myapp/foo/bar, path() might return foo/bar.
      Returns:
      Since:
      2.0.0
    • header

      <T> T header(HeaderValueType<T> value)
      Get a header as an appropriate Java object, or null if it is not present.
      Type Parameters:
      T - The return type
      Parameters:
      value - A header definition/parser/encoder
      Returns:
      An object or null if the header is missing or invalid
      See Also:
      • a standard HTTP header types
    • headers

      <T> List<T> headers(HeaderValueType<T> headerType)
      Get all headers matching a type.
      Type Parameters:
      T - The type
      Parameters:
      headerType - The header
      Returns:
      A list of headers
      Since:
      2.0.0
    • headersAsMap

      Map<CharSequence,CharSequence> headersAsMap()
      Get all headers (pruning duplicate names) as a case-insensitive map of CharSequence to header value.
      Returns:
      A map.
      Since:
      2.0.0
    • urlParametersAsMap

      Map<String,String> urlParametersAsMap()
      Gets the HTTP parameters as a flat map, ignoring duplicated keys. To be technically correct, the same request parameter may be repeated any number of times, so a Map <String, List<String>> would losslessly represent parameters. In practice, this is usually a bit pedantic and annoying, so this provides a convenient way to flatten it into a map.
      Returns:
      A map
      Since:
      2.0.0
    • urlParametersAs

      <T> T urlParametersAs(Class<T> type)
      Very primitive Java dynamic proxy magic: You write a Java interface with methods that each return a primitive type, and whose name corresponds to a URL parameter you expect to get.

      Calling this method will generate a dynamic proxy object of the interface type you pass, which implements these methods to return objects, doing the necessary conversions.

      Be aware that conversion can result in NumberFormatExceptions, etc.

      Type Parameters:
      T -
      Parameters:
      type -
      Returns:
      Since:
      2.0.0
    • intUrlParameter

      @Deprecated Optional<Integer> intUrlParameter(String name)
      Deprecated.
      Uses obsolete com.google.common.base.Optional
      Get a URL query string parameter as an integer.
      Parameters:
      name - The parameter name
      Returns:
      A parameter which may not be present
      Since:
      2.0.0
    • longUrlParameter

      @Deprecated Optional<Long> longUrlParameter(String name)
      Deprecated.
      Uses obsolete com.google.common.base.Optional
      Get a URL query string parameter as a long.
      Parameters:
      name - The parameter name
      Returns:
      A long which may not be present
      Since:
      2.0.0
    • stringContent

      String stringContent() throws IOException
      Get the request body as a string, in the encoding specified by the request's content-type header, or UTF-8 if none.
      Returns:
      A string
      Throws:
      IOException - If something goes wrong decoding the body
      Since:
      2.0.0
    • requestsConnectionStayOpen

      boolean requestsConnectionStayOpen()
      Determine if this request's connection header requests leaving the connection open. This method is used by the framework to decide what to do at the end of sending a response. It can also be used with the settings value "neverKeepAlive" to disable any keep-alive behavior within the application. In particular, unlike Netty's utility methods, this method defaults to false if no Connection header is present.
      Returns:
      True if the connection should be kept alive after the conclusion of responding to this request.
      Since:
      2.0.0
    • isSsl

      boolean isSsl()
      Determine if this event was over an encrypted connection.
      Returns:
      True if it was encrypted
      Since:
      2.0.0
    • getRequestURL

      String getRequestURL(boolean preferHeaders)
      Returns a best-effort at reconstructing the inbound URL, following the following algorithm:
      • If the application has external url generation configured via PathFactory, prefer the output of that
      • If not, try to honor non-standard but common headers such as X-Forwarded-Proto, X-URI-Scheme, Forwarded, X-Forwarded-Host
      Applications which respond to multiple virtual host names may need a custom implementation of PathFactory bound to do this correctly.
      Parameters:
      preferHeaders - If true, and if adequate information has been found in this request's headers, do not use PathFactory's configuration to override the result
      Returns:
      A URL string
      Since:
      2.2.2
    • isPreContent

      default boolean isPreContent()
    • decodedUrlParameter

      default String decodedUrlParameter(String name)
    • urlParameter

      default String urlParameter(String name, boolean decode)
    • getMethod

      @Deprecated default com.mastfrog.acteur.util.HttpMethod getMethod()
      Deprecated.
      use method()
      Get the HTTP method for this request
      Returns:
      A method name
    • getHeader

      @Deprecated default String getHeader(CharSequence nm)
      Deprecated.
      use header()
      Get a single HTTP header
      Parameters:
      nm - The header name
      Returns:
      The header
    • getParameter

      @Deprecated default String getParameter(String param)
      Deprecated.
      Use urlParameter()
      Get a single request parameter
      Parameters:
      param - The parameter name
      Returns:
      A parameter or null
    • getPath

      @Deprecated default Path getPath()
      Deprecated.
      use path()
      Get the logical path of this request. The web application may be "mounted" on some path (i.e. it is being proxied as part of a larger site). This method will give you the path, sans the base portion of it. So, if a request URL might be for http://example.com/myapp/foo/bar, getPath() might return foo/bar.
      Returns:
      A url path
    • getHeader

      @Deprecated default <T> T getHeader(HeaderValueType<T> value)
      Deprecated.
      use header()
      Get a header as an appropriate Java object, or null if it is not present.
      Parameters:
      value - A header definition/parser/encoder
      Returns:
      An object or null if the header is missing or invalid
      See Also:
      • a standard HTTP header types
    • getHeaders

      @Deprecated default <T> List<T> getHeaders(HeaderValueType<T> headerType)
      Deprecated.
      use headers()
      Get all headers matching a type.
      Type Parameters:
      T - The type
      Parameters:
      headerType - The header
      Returns:
      A list of headers
    • getHeadersAsMap

      @Deprecated default Map<CharSequence,CharSequence> getHeadersAsMap()
      Deprecated.
      use headersAsMap()
      Get all headers (pruning duplicate names) as a case-insensitive map of CharSequence to header value.
      Returns:
      A map.
    • getParametersAsMap

      @Deprecated default Map<String,String> getParametersAsMap()
      Deprecated.
      use urlParametersAsMap()
      Gets the HTTP parameters as a flat map, ignoring duplicated keys. To be technically correct, the same request parameter may be repeated any number of times, so a Map <String, List<String>> would losslessly represent parameters. In practice, this is usually a bit pedantic and annoying, so this provides a convenient way to flatten it into a map.
      Returns:
      A map
    • getParametersAs

      @Deprecated default <T> T getParametersAs(Class<T> type)
      Deprecated.
      use urlParametersAs
      Very primitive Java dynamic proxy magic: You write a Java interface with methods that each return a primitive type, and whose name corresponds to a URL parameter you expect to get.

      Calling this method will generate a dynamic proxy object of the interface type you pass, which implements these methods to return objects, doing the necessary conversions.

      Be aware that conversion can result in NumberFormatExceptions, etc.

      Type Parameters:
      T -
      Parameters:
      type -
      Returns:
    • getIntParameter

      @Deprecated default Optional<Integer> getIntParameter(String name)
      Deprecated.
      Use intUrlParameter()
      Get a URL query string parameter as an integer.
      Parameters:
      name - The parameter name
      Returns:
      A parameter which may not be present
    • getLongParameter

      @Deprecated default Optional<Long> getLongParameter(String name)
      Deprecated.
      Use longUrlParameter()
      Get a URL query string parameter as a long.
      Parameters:
      name - The parameter name
      Returns:
      A long which may not be present
    • getContentAsString

      @Deprecated default String getContentAsString() throws IOException
      Deprecated.
      use stringContent()
      Get the request body as a string, in the content-type header's encoding, or UTF-8 if none.
      Returns:
      A string, or null if no body
      Throws:
      IOException - If decoding fails
    • isKeepAlive

      @Deprecated default boolean isKeepAlive()
      Deprecated.
      use requestsConnectionStayOpen()
      Determine if this request's connection header requests leaving the connection open. This method is used by the framework to decide what to do at the end of sending a response. It can also be used with the settings value "neverKeepAlive" to disable any keep-alive behavior within the application. In particular, unlike Netty's utility methods, this method defaults to false if no Connection header is present.
      Returns:
      True if the connection should be kept alive after the conclusion of responding to this request.