Module methanol

Class TaggableRequest

java.lang.Object
java.net.http.HttpRequest
com.github.mizosoft.methanol.TaggableRequest
Direct Known Subclasses:
MutableRequest

public abstract class TaggableRequest extends HttpRequest
An HttpRequest that can carry arbitrary values, referred to as tags. Tags can be used to carry application-specific data throughout interceptors and listeners. Tags are mapped by their type. One type cannot map to more than one tag.

A TaggableRequest also carries the BodyAdapter.Hints to be used when encoding the request body and/or decoding the response body. Hints are like tags but are meant to carry arbitrary values to adapters rather than interceptors or listeners.

  • Method Details

    • tag

      public <T> Optional<T> tag(Class<T> type)
      Returns the tag associated with the given type if present.
    • tag

      public <T> Optional<T> tag(TypeRef<T> typeRef)
      Returns the tag associated with the given type if present.
    • hints

      public abstract BodyAdapter.Hints hints()
      Returns this request's BodyAdapter.Hints.
    • from

      public static TaggableRequest from(HttpRequest request)
      Returns either the given request if it's a TaggableRequest or a new TaggableRequest copy with no tags otherwise.
    • tagOf

      public static <T> Optional<T> tagOf(HttpRequest request, Class<T> type)
      Returns the tag associated with the given type if the given request is a TaggableRequest and it has a tag with the given type, otherwise returns an empty Optional.
    • tagOf

      public static <T> Optional<T> tagOf(HttpRequest request, TypeRef<T> typeRef)
      Returns the tag associated with the given type if the given request is a TaggableRequest and it has a tag with the given type, otherwise returns an empty Optional.