Class HttpUtil


  • public class HttpUtil
    extends java.lang.Object
    Contains utility methods for netty HttpRequest and related objects.
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getHostAndPortFromRequest​(io.netty.handler.codec.http.HttpRequest httpRequest)
      Gets the host and port from the specified request.
      static java.lang.String getHostAndPortFromUri​(java.lang.String uriString)
      Retrieves the host and port from the specified URI.
      static java.lang.String getHostFromRequest​(io.netty.handler.codec.http.HttpRequest httpRequest)
      Identify the host of an HTTP request.
      static boolean startsWithHttpOrHttps​(java.lang.String uri)
      Returns true if the string starts with http:// or https://.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HttpUtil

        public HttpUtil()
    • Method Detail

      • getHostFromRequest

        public static java.lang.String getHostFromRequest​(io.netty.handler.codec.http.HttpRequest httpRequest)
        Identify the host of an HTTP request. This method uses the URI of the request if possible, otherwise it attempts to find the host in the request headers.
        Parameters:
        httpRequest - HTTP request to parse the host from
        Returns:
        the host the request is connecting to, or null if no host can be found
      • getHostAndPortFromRequest

        public static java.lang.String getHostAndPortFromRequest​(io.netty.handler.codec.http.HttpRequest httpRequest)
        Gets the host and port from the specified request. Returns the host and port from the request URI if available, otherwise retrieves the host and port from the Host header.
        Parameters:
        httpRequest - HTTP request
        Returns:
        host and port of the request
      • startsWithHttpOrHttps

        public static boolean startsWithHttpOrHttps​(java.lang.String uri)
        Returns true if the string starts with http:// or https://.
        Parameters:
        uri - string to evaluate
        Returns:
        true if the string starts with http:// or https://
      • getHostAndPortFromUri

        public static java.lang.String getHostAndPortFromUri​(java.lang.String uriString)
                                                      throws java.net.URISyntaxException
        Retrieves the host and port from the specified URI.
        Parameters:
        uriString - URI to retrieve the host and port from
        Returns:
        the host and port from the URI as a String
        Throws:
        java.net.URISyntaxException - if the specified URI is invalid or cannot be parsed