Search in sources :

Example 36 with MediaType

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);
        }
    }
}
Also used : MediaType(io.helidon.common.http.MediaType)

Example 37 with MediaType

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;
}
Also used : MediaType(io.helidon.common.http.MediaType)

Aggregations

MediaType (io.helidon.common.http.MediaType)37 Charset (java.nio.charset.Charset)6 Map (java.util.Map)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 GenericType (io.helidon.common.GenericType)5 DataChunk (io.helidon.common.http.DataChunk)5 StandardCharsets (java.nio.charset.StandardCharsets)5 Multi (io.helidon.common.reactive.Multi)4 MessageBodyStreamWriter (io.helidon.media.common.MessageBodyStreamWriter)4 MessageBodyWriterContext (io.helidon.media.common.MessageBodyWriterContext)4 Objects (java.util.Objects)4 Flow (java.util.concurrent.Flow)4 Http (io.helidon.common.http.Http)3 JsonStructureToChunks (io.helidon.media.jsonp.JsonpBodyWriter.JsonStructureToChunks)3 List (java.util.List)3 Single (io.helidon.common.reactive.Single)2 RoutingChecker (io.helidon.webserver.RoutingTest.RoutingChecker)2 RoutingTest.mockResponse (io.helidon.webserver.RoutingTest.mockResponse)2 JsonString (jakarta.json.JsonString)2 Jsonb (jakarta.json.bind.Jsonb)2