Record Class Host

java.lang.Object
java.lang.Record
org.htmlunit.csp.value.Host
Record Components:
scheme - the scheme part (e.g. "https"), or null if not specified
host - the host part, lowercased (e.g. "example.com" or "*.cdn.example.com")
port - the port number, Constants.EMPTY_PORT if not specified, or Constants.WILDCARD_PORT if :*
path - the path part (e.g. "/scripts/"), or null if not specified

public record Host(String scheme, String host, int port, String path) extends Record
Represents a CSP host-source value, e.g. https://example.com:443/path.

A host-source consists of an optional scheme, a required host name (which may use a leading wildcard like *.example.com), an optional port (which may be a wildcard *), and an optional path. The host portion is always lowercased during parsing per the CSP specification.

Author:
Salvation Team
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Host(String scheme, String host, int port, String path)
    Creates an instance of a Host record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Returns the value of the host record component.
    static Optional<Host>
    Parses a host-source from its CSP string representation.
    Returns the value of the path record component.
    int
    Returns the value of the port record component.
    Returns the value of the scheme record component.
    Returns the CSP string representation of this host-source.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Host

      public Host(String scheme, String host, int port, String path)
      Creates an instance of a Host record class.
      Parameters:
      scheme - the value for the scheme record component
      host - the value for the host record component
      port - the value for the port record component
      path - the value for the path record component
  • Method Details

    • parseHost

      public static Optional<Host> parseHost(String value)
      Parses a host-source from its CSP string representation.

      The input is matched against the host-source grammar. The scheme, if present, is lowercased. The host is always lowercased. The port may be a number, the wildcard *, or absent. The path, if present, is preserved as-is.

      Parameters:
      value - the CSP host-source token (e.g. "https://example.com:443/path")
      Returns:
      an Optional containing the parsed Host, or empty if the value does not match the host-source grammar
    • toString

      public String toString()
      Returns the CSP string representation of this host-source.

      The scheme is included only if it was explicitly specified. The port is omitted if it is the default port for the scheme or was not specified. The path is included only if it was explicitly specified.

      Specified by:
      toString in class Record
      Returns:
      the host-source string (e.g. "https://example.com/path")
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • scheme

      public String scheme()
      Returns the value of the scheme record component.
      Returns:
      the value of the scheme record component
    • host

      public String host()
      Returns the value of the host record component.
      Returns:
      the value of the host record component
    • port

      public int port()
      Returns the value of the port record component.
      Returns:
      the value of the port record component
    • path

      public String path()
      Returns the value of the path record component.
      Returns:
      the value of the path record component