java.lang.Object
org.cybergarage.http.HTTP

public class HTTPextends Object
Utility class providing HTTP protocol constants and helper methods.

This class contains commonly used HTTP protocol constants including:

  • HTTP methods (GET, POST, HEAD, etc.)
  • HTTP headers (Content-Type, Host, etc.)
  • HTTP status codes and versions
  • UPnP-specific constants

Also provides utility methods for URL manipulation and validation.

  • Field Details

  • Constructor Details

    • HTTP

      public HTTP()
      Constructor. The header names, status codes and URL helpers below are all static, so an instance holds nothing.
  • Method Details

    • isAbsoluteURL

      public static final boolean isAbsoluteURL(String urlStr)
      Checks if a string represents an absolute URL.
      Parameters:
      urlStr - string to check
      Returns:
      true if the string is a valid absolute URL, false otherwise
    • getHost

      public static final String getHost(String urlStr)
      Extracts the host name from a URL string.
      Parameters:
      urlStr - URL string to extract host from
      Returns:
      host name, or empty string if URL is invalid
    • getPort

      public static final int getPort(String urlStr)
      Extracts the port number from a URL string. Returns default HTTP port (80) if no port is specified.
      Parameters:
      urlStr - URL string to extract port from
      Returns:
      port number, or default port (80) if URL is invalid or no port specified
    • getRequestHostURL

      public static final String getRequestHostURL(String host, int port)
      Creates a request host URL from host and port.
      Parameters:
      host - host name or IP address
      port - the port to append, used as given with no default substituted
      Returns:
      URL string in format "http://host:port"
    • toRelativeURL

      public static final String toRelativeURL(String urlStr, boolean withParam)
      Converts a URL to a relative URL path.
      Parameters:
      urlStr - URL string to convert
      withParam - whether to include query parameters in result
      Returns:
      relative URL path, optionally with query parameters
    • toRelativeURL

      public static final String toRelativeURL(String urlStr)
      Converts a URL to a relative URL path with query parameters.
      Parameters:
      urlStr - URL string to convert
      Returns:
      relative URL path with query parameters
    • getAbsoluteURL

      public static final String getAbsoluteURL(String baseURLStr, String relURlStr)
      Creates an absolute URL by combining base URL with relative URL.
      Parameters:
      baseURLStr - base URL string
      relURlStr - relative URL to combine with base
      Returns:
      absolute URL string, or empty string if combination fails
    • setChunkSize

      public static final void setChunkSize(int size)
      Sets the default chunk size for HTTP operations.
      Parameters:
      size - chunk size in bytes
    • getChunkSize

      public static final int getChunkSize()
      Gets the current default chunk size for HTTP operations.
      Returns:
      chunk size in bytes