Record Class SecFetch

java.lang.Object
java.lang.Record
io.micronaut.http.SecFetch
Record Components:
site - The relationship between the request initiator and requested resource, or null if Sec-Fetch-Site was absent or carried an unrecognised value
mode - The request mode, or null if Sec-Fetch-Mode was absent or carried an unrecognised value
dest - The request destination, or null if Sec-Fetch-Dest was absent or carried a value not listed by Destination. The Fetch specification keeps adding destinations, so a newer client can legitimately send one this version does not know
user - Whether the request was initiated by user activation. Only Sec-Fetch-User: ?1 yields true; an absent header, the structured field boolean ?0, and any unrecognised value all yield false

public record SecFetch(@Nullable Site site, @Nullable Mode mode, @Nullable Destination dest, boolean user) extends Record
The Fetch Metadata request headers.

Each component is populated independently: a header that is absent, or that carries a value this version does not recognise, yields a null component while the headers that did parse remain readable. An unrecognised Sec-Fetch-Dest therefore does not hide the site and mode, which is what a resource isolation policy needs in order to fail closed on the part it could not classify rather than on the whole request.

Since:
5.1.12
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    SecFetch(@Nullable Site site, @Nullable Mode mode, @Nullable Destination dest, boolean user)
    Creates an instance of a SecFetch record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable Destination
    Returns the value of the dest record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    @Nullable Mode
    Returns the value of the mode record component.
    static @Nullable SecFetch
    of(HttpHeaders headers)
    Creates Fetch Metadata from the given headers.
    static @Nullable SecFetch
    of(HttpRequest<?> request)
    Creates Fetch Metadata from the request headers.
    @Nullable Site
    Returns the value of the site record component.
    final String
    Returns a string representation of this record class.
    boolean
    Returns the value of the user record component.

    Methods inherited from class Object

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

    • SecFetch

      public SecFetch(@Nullable Site site, @Nullable Mode mode, @Nullable Destination dest, boolean user)
      Creates an instance of a SecFetch record class.
      Parameters:
      site - the value for the site record component
      mode - the value for the mode record component
      dest - the value for the dest record component
      user - the value for the user record component
  • Method Details

    • of

      public static @Nullable SecFetch of(HttpRequest<?> request)
      Creates Fetch Metadata from the request headers.
      Parameters:
      request - The HTTP request
      Returns:
      The Fetch Metadata, or null if the request carries none of the Fetch Metadata headers. See of(HttpHeaders) for what a null return does and does not tell a caller
      Since:
      5.1.12
    • of

      public static @Nullable SecFetch of(HttpHeaders headers)
      Creates Fetch Metadata from the given headers.

      The result is best effort. Headers that parse are reported; those that are absent or carry an unrecognised value become null components. Headers that could not be classified never suppress the ones that could, so a request whose Sec-Fetch-Dest is unknown still reports its site and mode.

      Parameters:
      headers - The HTTP headers
      Returns:
      The Fetch Metadata, or null if none of Sec-Fetch-Site, Sec-Fetch-Mode, Sec-Fetch-Dest and Sec-Fetch-User is present.

      A null return means only that the client sent no Fetch Metadata at all — an older browser, or a non-browser client — and carries no assurance that the request is safe. Likewise a null component means "not classified", not "harmless". Resource isolation policies should decide deliberately what to do with unclassified requests rather than treating null as an implicit allow

      Since:
      5.1.12
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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 the compare method from their corresponding wrapper classes.
      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.
    • site

      public @Nullable Site site()
      Returns the value of the site record component.
      Returns:
      the value of the site record component
    • mode

      public @Nullable Mode mode()
      Returns the value of the mode record component.
      Returns:
      the value of the mode record component
    • dest

      public @Nullable Destination dest()
      Returns the value of the dest record component.
      Returns:
      the value of the dest record component
    • user

      public boolean user()
      Returns the value of the user record component.
      Returns:
      the value of the user record component