Class ParsedMediaType

java.lang.Object
org.elasticsearch.xcontent.ParsedMediaType

public class ParsedMediaType extends Object
A raw result of parsing media types from Accept or Content-Type headers. It follow parsing and validates as per rules defined in https://tools.ietf.org/html/rfc7231#section-3.1.1.1 Can be resolved to MediaType
See Also:
  • Method Details

    • mediaTypeWithoutParameters

      public String mediaTypeWithoutParameters()
      The parsed mime type without the associated parameters. Will always return lowercase.
    • getParameters

      public Map<String,String> getParameters()
    • parseMediaType

      public static ParsedMediaType parseMediaType(String headerValue)
      Parses a header value into it's parts. follows https://tools.ietf.org/html/rfc7231#section-3.1.1.1 but allows only single media type. Media ranges will be ignored (treated as not provided) Note: parsing can return null, but it will throw exceptions once https://github.com/elastic/elasticsearch/issues/63080 is done TODO Do not rely on nulls
      Returns:
      a ParsedMediaType if the header could be parsed.
      Throws:
      IllegalArgumentException - if the header is malformed
    • parseMediaType

      public static ParsedMediaType parseMediaType(XContentType requestContentType, Map<String,String> parameters)
    • toMediaType

      public <T extends MediaType> T toMediaType(MediaTypeRegistry<T> mediaTypeRegistry)
      Resolves this instance to a MediaType instance defined in given MediaTypeRegistry. Performs validation against parameters.
      Parameters:
      mediaTypeRegistry - a registry where a mapping between a raw media type to an instance MediaType is defined
      Returns:
      a MediaType instance or null if no media type could be found or if a known parameter do not passes validation
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • responseContentTypeHeader

      public String responseContentTypeHeader()
    • responseContentTypeHeader

      public String responseContentTypeHeader(Map<String,String> params)