Package net.shibboleth.shared.net

# Class MediaTypeSupport

java.lang.Object
net.shibboleth.shared.net.MediaTypeSupport

public final class MediaTypeSupport extends Object
Support methods for Guava `MediaType`.

## Field Summary

Fields
Modifier and Type
Field
Description
`private static final Function<MediaType,MediaType>`
`STRIP_PARAMS`
Function to strip MediaType parameters.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`private`
`MediaTypeSupport()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`static boolean`
`validateContentType(String contentType, Set<MediaType> validTypes, boolean noContentTypeIsValid, boolean isOneOfStrategy)`
Validate the specified Content-Type.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### STRIP_PARAMS

@Nonnull private static final Function<MediaType,MediaType> STRIP_PARAMS
Function to strip MediaType parameters.

## Constructor Details

### MediaTypeSupport

private MediaTypeSupport()
Constructor.

## Method Details

### validateContentType

public static boolean validateContentType(@Nullable String contentType, @Nonnull Set<MediaType> validTypes, boolean noContentTypeIsValid, boolean isOneOfStrategy)
Validate the specified Content-Type.

Two strategies are supported for evaluating a content type:

1. If isOneOfStrategy is true, then the `MediaType` parsed from the content type value is compared to each of the specified valid types via `MediaType.is(MediaType)`. If any pass, the type is considered valid. This allows use of MediaType's support for wildcard and parameter evaluation.
2. If isOneOfStrategy is false, then the `MediaType` parsed from the value is stripped of its parameters, as is each of the valid types. Then a simple evaluation is done that the specified content type is equal to one of the passed types. In this case, only literal types and subtypes should be passed as valid types; wildcards should not be used.

Parameters:
  `contentType` - the contentType to be validated
  `validTypes` - the set of valid media types
  `noContentTypeIsValid` - flag whether the case of a missing/empty Content-Type header is considered valid
  `isOneOfStrategy` - flag for the strategy used in the validation (see above for details)
Returns:
  true if the content type is valid, false if not