@Override public List<MediaType> acceptPatches() { List<MediaType> result = all(Http.Header.ACCEPT_PATCH).stream() .flatMap(h -> Utils.tokenize(',', "\"", false, h).stream()) .map(String::trim) .map(MediaType::parse) .collect(Collectors.toList()); return Collections.unmodifiableList(result); }
@Override public List<MediaType> acceptedTypes() { List<MediaType> result = this.acceptedtypesCache; if (result == null) { List<String> acceptValues = all(Http.Header.ACCEPT); result = acceptValues.size() == 1 && HUC_ACCEPT_DEFAULT.equals(acceptValues.get(0)) ? HUC_ACCEPT_DEFAULT_TYPES : acceptValues.stream() .flatMap(h -> Utils.tokenize(',', "\"", false, h).stream()) .map(String::trim) .map(MediaType::parse) .collect(Collectors.toList()); result = Collections.unmodifiableList(result); this.acceptedtypesCache = result; } return result; }
/** * Returns an unmodifiable {@link List} of all comma separated header value parts - <b>Such segmentation is NOT valid for * all header semantics, however it is very common</b>. Refer to actual header semantics standard/description before use. * <p> * Result is composed from all header fields with requested {@code headerName} where each header value is tokenized by * a comma character. Tokenization respects value quoting by <i>double-quote</i> character. * <p> * Always returns a List, which may be empty if the parameter is not present. * * @param headerName the header name * @return a {@code List} of values with zero or greater size, never {@code null} * @throws NullPointerException if {@code headerName} is {@code null} * @see #all(String) * @see #value(String) */ default List<String> values(String headerName) { return all(headerName).stream() .flatMap(val -> Utils.tokenize(',', "\"", true, val).stream()) .collect(Collectors.toList()); } }