Interface Authority

All Superinterfaces:
Normalisable<Authority>, org.wiremock.stringparser.ParsedString
All Known Subinterfaces:
HostAndPort

public interface Authority extends Normalisable<Authority>, org.wiremock.stringparser.ParsedString
Represents the authority component of a URI as defined in RFC 3986 Section 3.2.

The authority component consists of optional user information, a host, and an optional port. It typically takes the form [userinfo@]host[:port].

Implementations must be immutable and thread-safe.

See Also:
  • Method Details

    • getUserInfo

      @Nullable UserInfo getUserInfo()
      Returns the user info component, or null if there is no user info.
      Returns:
      the user info, or null if absent
    • getHost

      Host getHost()
      Returns the host component.
      Returns:
      the host, never null
    • getPort

      @Nullable Port getPort()
      Returns the port component, or null if there is no port.
      Returns:
      the port, or null if absent
    • getMaybePort

      @Nullable Optional<Port> getMaybePort()
      Returns an optional representation of the port to distinguish between no port and empty port.

      An Authority can legitimately be any of:

      • example.com - no port (returns null)
      • example.com: - empty port (returns Optional.empty())
      • example.com:80 - with port (returns Optional.of(port))
      Returns:
      null for no port, Optional.empty() for empty port, or Optional.of(port) for a port value
    • getHostAndPort

      HostAndPort getHostAndPort()
      Returns the host and port as a HostAndPort.
      Returns:
      the host and port
    • withPort

      Authority withPort(@Nullable Port port)
      Returns a new authority with the specified port.
      Parameters:
      port - the port to set, or null to remove it
      Returns:
      a new authority with the updated port
    • withoutPort

      default Authority withoutPort()
      Returns a new authority with the port removed.
      Returns:
      a new authority without a port
    • normalise

      Authority normalise(Scheme canonicalScheme)
      Returns a normalised form of this authority using scheme-specific normalization rules.

      The scheme is used to determine if the port should be removed when it matches the default port for that scheme.

      Parameters:
      canonicalScheme - the canonical scheme to use for normalization
      Returns:
      a normalised authority
    • isNormalForm

      default boolean isNormalForm()
      Specified by:
      isNormalForm in interface Normalisable<Authority>
    • isNormalForm

      default boolean isNormalForm(Scheme canonicalScheme)
      Tests if this value is already normalised
      Parameters:
      canonicalScheme - the scheme to be in normal form against
      Returns:
      true if in normal form for this scheme
    • parse

      static Authority parse(String authorityStr) throws IllegalAuthority
      Parses a string into an authority.
      Parameters:
      authorityStr - the string to parse
      Returns:
      the parsed authority
      Throws:
      IllegalAuthority - if the string is not a valid authority
    • of

      static Authority of(Host host)
      Creates an authority from a host.
      Parameters:
      host - the host
      Returns:
      the authority
    • of

      static Authority of(Host host, @Nullable Port port)
      Creates an authority from a host and port.
      Parameters:
      host - the host
      port - the port, or null
      Returns:
      the authority
    • of

      static Authority of(@Nullable UserInfo userInfo, Host host)
      Creates an authority from user info and host.
      Parameters:
      userInfo - the user info, or null
      host - the host
      Returns:
      the authority
    • of

      static Authority of(@Nullable UserInfo userInfo, Host host, @Nullable Port port)
      Creates an authority from user info, host, and port.
      Parameters:
      userInfo - the user info, or null
      host - the host
      port - the port, or null
      Returns:
      the authority
    • equals

      static boolean equals(Authority one, Object o)
    • hashCode

      static int hashCode(Authority authority)