/** * Determine whether a given request has a content-type header. * * @return Whether a content-type header is defined on the response */ public static boolean hasContentType(final Response response) { return response.getHeaderValue(Headers.CONTENT_TYPE).isPresent(); }
/** * Get the content-type header of this response, if it has been set. * * @return The content-type header, or empty if it has not been set. */ @Nonnull default Optional<String> getContentType() { return getHeaderValue(CONTENT_TYPE); }
/** * Find the content-type that most specifically matches the content-type defined on the given response. * <p> * e.g. If the response has {@code Content-Type=text/plain} and the list of types is <code>[text/*, */*, text/plain]</code> * (all of which could match), the most specific match {@code text/plain} will be returned. * <p> * If there are no matches, will return empty. * * @param response The response to find a matching content type for * @param apiContentTypes The list of content types to search * * @return The most specific content type that matches the given request, or empty if none match. */ public static Optional<String> findMostSpecificMatch(final Response response, final Set<String> apiContentTypes) { return findMostSpecificMatch(response.getHeaderValue(Headers.CONTENT_TYPE).orElse("*/*"), apiContentTypes); }