Class HostSourceDirective

java.lang.Object
org.htmlunit.csp.Directive
org.htmlunit.csp.directive.HostSourceDirective
Direct Known Subclasses:
FrameAncestorsDirective, SourceExpressionDirective

public abstract class HostSourceDirective extends Directive
Abstract base class for directives whose values are host-source lists.

A host-source list can contain the keywords 'none', 'self', and *, as well as scheme-sources (https:) and host-sources (example.com, *.example.com:443/path). This class is extended by SourceExpressionDirective (which adds nonces, hashes, and other source expressions) and by FrameAncestorsDirective.

Author:
Salvation Team
See Also:
  • Constructor Details

    • HostSourceDirective

      protected HostSourceDirective(List<String> values)
      Constructs a host-source directive from the given raw values.
      Parameters:
      values - the raw string values for this directive
  • Method Details

    • getNone

      public String getNone()
      Returns the original 'none' token if the directive was set to 'none', or null if the directive is not 'none'.
      Returns:
      the 'none' token string, or null
    • addValue

      protected void addValue(String value)
      Description copied from class: Directive
      Appends a value to this directive's value list.

      The value must be a non-empty ASCII string that does not contain whitespace, commas, or semicolons.

      Overrides:
      addValue in class Directive
      Parameters:
      value - the value to add
    • removeValueIgnoreCase

      protected void removeValueIgnoreCase(String value)
      Description copied from class: Directive
      Removes all occurrences of a value from this directive (case-insensitive comparison).
      Overrides:
      removeValueIgnoreCase in class Directive
      Parameters:
      value - the value to remove (compared case-insensitively)
    • star

      public boolean star()
      Returns whether the wildcard (*) is present in this source list.

      When * is present, any URL with a network scheme (ftp, http, https) is matched, as well as URLs whose scheme matches the origin's scheme.

      Returns:
      true if the wildcard source is present
    • self

      public boolean self()
      Returns whether the 'self' keyword is present in this source list.

      When 'self' is present, URLs that share the same origin as the protected resource are matched.

      Returns:
      true if 'self' is present
    • getSchemes

      public List<Scheme> getSchemes()
      Returns an unmodifiable list of scheme-sources (e.g. https:, data:) present in this directive.
      Returns:
      the list of parsed Scheme values
    • getHosts

      public List<Host> getHosts()
      Returns an unmodifiable list of host-sources (e.g. example.com, *.cdn.example.com:443/path) present in this directive.
      Returns:
      the list of parsed Host values