use of io.helidon.common.http.MediaType in project helidon by oracle.
the class ContentTypeSelector method determine.
MediaType determine(String filename, RequestHeaders requestHeaders) {
MediaType mediaType = get(filename);
List<MediaType> accepted = requestHeaders.acceptedTypes();
if (mediaType == null) {
// First from Accepted
if (accepted.isEmpty()) {
// Most general
return MediaType.APPLICATION_OCTET_STREAM;
} else {
return accepted.get(0);
}
} else {
// Must deal type
if (requestHeaders.isAccepted(mediaType)) {
return mediaType;
} else {
throw new HttpException("Not accepted media-type!", Http.Status.NOT_FOUND_404);
}
}
}
use of io.helidon.common.http.MediaType in project helidon by oracle.
the class ContentTypeSelector method get.
private MediaType get(String filename) {
if (filename == null) {
return null;
}
// Get extension
int ind = filename.lastIndexOf('.');
if (ind < 0) {
return null;
}
String extension = filename.substring(ind + 1);
// Get type for the extension
MediaType result = specificContentTypes.get(extension);
if (result == null) {
result = CONTENT_TYPES.get(extension);
}
return result;
}
Aggregations