Package io.muserver.handlers
Class ResourceType
- java.lang.Object
-
- io.muserver.handlers.ResourceType
-
public class ResourceType extends java.lang.Object
Used by the
ResourceHandler
to specify a mapping between file name extensions and mime types, and whether they should be gzipped or not.A number of common mappings are provided by default. To specify your custom settings, use
ResourceHandlerBuilder.withExtensionToResourceType(Map)
-
-
Field Summary
Fields Modifier and Type Field Description static ResourceType
APPLICATION_EPUB_ZIP
application/epub-zip
static ResourceType
APPLICATION_GZIP
application/gzip
static ResourceType
APPLICATION_JAVA_ARCHIVE
application/java-archive
static ResourceType
APPLICATION_JAVASCRIPT
application/javascript
static ResourceType
APPLICATION_JSON
application/json
static ResourceType
APPLICATION_MSWORD
application/msword
static ResourceType
APPLICATION_OCTET_STREAM
application/octet-stream
static ResourceType
APPLICATION_OGG
application/ogg
static ResourceType
APPLICATION_PDF
application/pdf
static ResourceType
APPLICATION_RTF
application/rtf
static ResourceType
APPLICATION_TYPESCRIPT
application/typescript
static ResourceType
APPLICATION_VND_AMAZON_EBOOK
application/vnd-amazon-ebook
static ResourceType
APPLICATION_VND_APPLE_INSTALLER_XML
application/vnd-apple-installer-xml
static ResourceType
APPLICATION_VND_MOZILLA_XUL_XML
application/vnd-mozilla-xul-xml
static ResourceType
APPLICATION_VND_MS_EXCEL
application/vnd-ms-excel
static ResourceType
APPLICATION_VND_MS_FONTOBJECT
application/vnd-ms-fontobject
static ResourceType
APPLICATION_VND_MS_POWERPOINT
application/vnd-ms-powerpoint
static ResourceType
APPLICATION_VND_OASIS_OPENDOCUMENT_PRESENTATION
application/vnd-oasis-opendocument-presentation
static ResourceType
APPLICATION_VND_OASIS_OPENDOCUMENT_SPREADSHEET
application/vnd-oasis-opendocument-spreadsheet
static ResourceType
APPLICATION_VND_OASIS_OPENDOCUMENT_TEXT
application/vnd-oasis-opendocument-text
static ResourceType
APPLICATION_VND_VISIO
application/vnd-visio
static ResourceType
APPLICATION_X_7Z_COMPRESSED
application/x-7z-compressed
static ResourceType
APPLICATION_X_ABIWORD
application/x-abiword
static ResourceType
APPLICATION_X_BZIP
application/x-bzip
static ResourceType
APPLICATION_X_BZIP2
application/x-bzip2
static ResourceType
APPLICATION_X_CSH
application/x-csh
static ResourceType
APPLICATION_X_RAR_COMPRESSED
application/x-rar-compressed
static ResourceType
APPLICATION_X_SH
application/x-sh
static ResourceType
APPLICATION_X_SHOCKWAVE_FLASH
application/x-shockwave-flash
static ResourceType
APPLICATION_X_TAR
application/x-tar
static ResourceType
APPLICATION_XHTML_XML
application/xhtml-xml
static ResourceType
APPLICATION_XML
application/xml
static ResourceType
APPLICATION_ZIP
application/zip
static ResourceType
AUDIO_AAC
audio/aac
static ResourceType
AUDIO_MIDI
audio/midi
static ResourceType
AUDIO_OGG
audio/ogg
static ResourceType
AUDIO_WEBM
audio/webm
static ResourceType
AUDIO_X_WAV
audio/x-wav
static ResourceType
DEFAULT
The resource type used when no others match.static java.util.Map<java.lang.String,ResourceType>
DEFAULT_EXTENSION_MAPPINGS
The mapping of file extensions (such as "jpg") to resource types (such asIMAGE_JPEG
that mu-server uses by default when serving static content.java.util.List<java.lang.String>
extensions
Deprecated.useextensions()
insteadstatic ResourceType
FONT_OTF
font/otf
static ResourceType
FONT_TTF
font/ttf
static ResourceType
FONT_WOFF
font/woff
static ResourceType
FONT_WOFF2
font/woff2
boolean
gzip
Deprecated.usegzip()
insteadHeaders
headers
Deprecated.useheaders()
insteadstatic ResourceType
IMAGE_AVIF
image/avif
static ResourceType
IMAGE_GIF
image/gif
static ResourceType
IMAGE_JPEG
image/jpeg
static ResourceType
IMAGE_PNG
image/png
static ResourceType
IMAGE_SVG_XML
image/svg-xml
static ResourceType
IMAGE_TIFF
image/tiff
static ResourceType
IMAGE_WEBP
image/webp
static ResourceType
IMAGE_X_ICON
image/x-icon
java.lang.CharSequence
mimeType
Deprecated.usemimeType()
insteadstatic ResourceType
TEXT_CALENDAR
text/calendar;charset=utf-8
static ResourceType
TEXT_CSS
text/css
static ResourceType
TEXT_CSV
text/csv;charset=utf-8
static ResourceType
TEXT_HTML
text/html;charset=utf-8
static ResourceType
TEXT_JAVASCRIPT
Deprecated.useAPPLICATION_JAVASCRIPT
insteadstatic ResourceType
TEXT_MARKDOWN
text/markdown;charset=utf-8
static ResourceType
TEXT_PLAIN
text/plain;charset=utf-8
static ResourceType
VIDEO_3GPP
video/3gpp
static ResourceType
VIDEO_3GPP2
video/3gpp2
static ResourceType
VIDEO_MPEG
video/mpeg
static ResourceType
VIDEO_OGG
video/ogg
static ResourceType
VIDEO_WEBM
video/webm
static ResourceType
VIDEO_X_MATROSKA
video/x-matroska
static ResourceType
VIDEO_X_MSVIDEO
video/x-msvideo
static ResourceType
WEB_APP_MANIFEST
web/app-manifest
-
Constructor Summary
Constructors Constructor Description ResourceType(java.lang.CharSequence mimeType, Headers headers, boolean gzip, java.util.List<java.lang.String> extensions)
Creates a new resource type.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<java.lang.String>
extensions()
static java.util.HashMap<java.lang.String,ResourceType>
getDefaultMapping()
Can be used as a base to customise mime types viaResourceHandlerBuilder.withExtensionToResourceType(Map)
static java.util.List<ResourceType>
getResourceTypes()
boolean
gzip()
static java.util.Set<java.lang.String>
gzippableMimeTypes(java.util.Collection<ResourceType> resourceTypes)
Given a list of resources, returns the ones that are gzippableHeaders
headers()
java.lang.CharSequence
mimeType()
static Headers
noCache()
static Headers
shortCache()
java.lang.String
toString()
-
-
-
Field Detail
-
DEFAULT_EXTENSION_MAPPINGS
public static final java.util.Map<java.lang.String,ResourceType> DEFAULT_EXTENSION_MAPPINGS
The mapping of file extensions (such as "jpg") to resource types (such asIMAGE_JPEG
that mu-server uses by default when serving static content.
-
mimeType
@Deprecated public final java.lang.CharSequence mimeType
Deprecated.usemimeType()
instead
-
extensions
@Deprecated public final java.util.List<java.lang.String> extensions
Deprecated.useextensions()
instead
-
gzip
@Deprecated public final boolean gzip
Deprecated.usegzip()
instead
-
DEFAULT
public static final ResourceType DEFAULT
The resource type used when no others match. In this case,ContentTypes.APPLICATION_OCTET_STREAM
is used.
-
AUDIO_AAC
public static final ResourceType AUDIO_AAC
audio/aac
-
APPLICATION_X_ABIWORD
public static final ResourceType APPLICATION_X_ABIWORD
application/x-abiword
-
VIDEO_X_MSVIDEO
public static final ResourceType VIDEO_X_MSVIDEO
video/x-msvideo
-
APPLICATION_VND_AMAZON_EBOOK
public static final ResourceType APPLICATION_VND_AMAZON_EBOOK
application/vnd-amazon-ebook
-
APPLICATION_OCTET_STREAM
public static final ResourceType APPLICATION_OCTET_STREAM
application/octet-stream
-
APPLICATION_X_BZIP
public static final ResourceType APPLICATION_X_BZIP
application/x-bzip
-
APPLICATION_X_BZIP2
public static final ResourceType APPLICATION_X_BZIP2
application/x-bzip2
-
APPLICATION_X_CSH
public static final ResourceType APPLICATION_X_CSH
application/x-csh
-
TEXT_CSS
public static final ResourceType TEXT_CSS
text/css
-
TEXT_PLAIN
public static final ResourceType TEXT_PLAIN
text/plain;charset=utf-8
-
TEXT_MARKDOWN
public static final ResourceType TEXT_MARKDOWN
text/markdown;charset=utf-8
-
TEXT_CSV
public static final ResourceType TEXT_CSV
text/csv;charset=utf-8
-
APPLICATION_MSWORD
public static final ResourceType APPLICATION_MSWORD
application/msword
-
APPLICATION_VND_MS_FONTOBJECT
public static final ResourceType APPLICATION_VND_MS_FONTOBJECT
application/vnd-ms-fontobject
-
APPLICATION_EPUB_ZIP
public static final ResourceType APPLICATION_EPUB_ZIP
application/epub-zip
-
APPLICATION_GZIP
public static final ResourceType APPLICATION_GZIP
application/gzip
-
IMAGE_GIF
public static final ResourceType IMAGE_GIF
image/gif
-
TEXT_HTML
public static final ResourceType TEXT_HTML
text/html;charset=utf-8
-
IMAGE_X_ICON
public static final ResourceType IMAGE_X_ICON
image/x-icon
-
TEXT_CALENDAR
public static final ResourceType TEXT_CALENDAR
text/calendar;charset=utf-8
-
APPLICATION_JAVA_ARCHIVE
public static final ResourceType APPLICATION_JAVA_ARCHIVE
application/java-archive
-
IMAGE_JPEG
public static final ResourceType IMAGE_JPEG
image/jpeg
-
TEXT_JAVASCRIPT
@Deprecated public static final ResourceType TEXT_JAVASCRIPT
Deprecated.useAPPLICATION_JAVASCRIPT
instead
-
APPLICATION_JAVASCRIPT
public static final ResourceType APPLICATION_JAVASCRIPT
application/javascript
-
APPLICATION_JSON
public static final ResourceType APPLICATION_JSON
application/json
-
WEB_APP_MANIFEST
public static final ResourceType WEB_APP_MANIFEST
web/app-manifest
-
AUDIO_MIDI
public static final ResourceType AUDIO_MIDI
audio/midi
-
VIDEO_MPEG
public static final ResourceType VIDEO_MPEG
video/mpeg
-
APPLICATION_VND_APPLE_INSTALLER_XML
public static final ResourceType APPLICATION_VND_APPLE_INSTALLER_XML
application/vnd-apple-installer-xml
-
APPLICATION_VND_OASIS_OPENDOCUMENT_PRESENTATION
public static final ResourceType APPLICATION_VND_OASIS_OPENDOCUMENT_PRESENTATION
application/vnd-oasis-opendocument-presentation
-
APPLICATION_VND_OASIS_OPENDOCUMENT_SPREADSHEET
public static final ResourceType APPLICATION_VND_OASIS_OPENDOCUMENT_SPREADSHEET
application/vnd-oasis-opendocument-spreadsheet
-
APPLICATION_VND_OASIS_OPENDOCUMENT_TEXT
public static final ResourceType APPLICATION_VND_OASIS_OPENDOCUMENT_TEXT
application/vnd-oasis-opendocument-text
-
AUDIO_OGG
public static final ResourceType AUDIO_OGG
audio/ogg
-
VIDEO_X_MATROSKA
public static final ResourceType VIDEO_X_MATROSKA
video/x-matroska
-
VIDEO_OGG
public static final ResourceType VIDEO_OGG
video/ogg
-
APPLICATION_OGG
public static final ResourceType APPLICATION_OGG
application/ogg
-
FONT_OTF
public static final ResourceType FONT_OTF
font/otf
-
IMAGE_PNG
public static final ResourceType IMAGE_PNG
image/png
-
APPLICATION_PDF
public static final ResourceType APPLICATION_PDF
application/pdf
-
APPLICATION_VND_MS_POWERPOINT
public static final ResourceType APPLICATION_VND_MS_POWERPOINT
application/vnd-ms-powerpoint
-
APPLICATION_X_RAR_COMPRESSED
public static final ResourceType APPLICATION_X_RAR_COMPRESSED
application/x-rar-compressed
-
APPLICATION_RTF
public static final ResourceType APPLICATION_RTF
application/rtf
-
APPLICATION_X_SH
public static final ResourceType APPLICATION_X_SH
application/x-sh
-
IMAGE_SVG_XML
public static final ResourceType IMAGE_SVG_XML
image/svg-xml
-
APPLICATION_X_SHOCKWAVE_FLASH
public static final ResourceType APPLICATION_X_SHOCKWAVE_FLASH
application/x-shockwave-flash
-
APPLICATION_X_TAR
public static final ResourceType APPLICATION_X_TAR
application/x-tar
-
IMAGE_TIFF
public static final ResourceType IMAGE_TIFF
image/tiff
-
APPLICATION_TYPESCRIPT
public static final ResourceType APPLICATION_TYPESCRIPT
application/typescript
-
FONT_TTF
public static final ResourceType FONT_TTF
font/ttf
-
APPLICATION_VND_VISIO
public static final ResourceType APPLICATION_VND_VISIO
application/vnd-visio
-
AUDIO_X_WAV
public static final ResourceType AUDIO_X_WAV
audio/x-wav
-
AUDIO_WEBM
public static final ResourceType AUDIO_WEBM
audio/webm
-
VIDEO_WEBM
public static final ResourceType VIDEO_WEBM
video/webm
-
IMAGE_AVIF
public static final ResourceType IMAGE_AVIF
image/avif
-
IMAGE_WEBP
public static final ResourceType IMAGE_WEBP
image/webp
-
FONT_WOFF
public static final ResourceType FONT_WOFF
font/woff
-
FONT_WOFF2
public static final ResourceType FONT_WOFF2
font/woff2
-
APPLICATION_XHTML_XML
public static final ResourceType APPLICATION_XHTML_XML
application/xhtml-xml
-
APPLICATION_VND_MS_EXCEL
public static final ResourceType APPLICATION_VND_MS_EXCEL
application/vnd-ms-excel
-
APPLICATION_XML
public static final ResourceType APPLICATION_XML
application/xml
-
APPLICATION_VND_MOZILLA_XUL_XML
public static final ResourceType APPLICATION_VND_MOZILLA_XUL_XML
application/vnd-mozilla-xul-xml
-
APPLICATION_ZIP
public static final ResourceType APPLICATION_ZIP
application/zip
-
VIDEO_3GPP
public static final ResourceType VIDEO_3GPP
video/3gpp
-
VIDEO_3GPP2
public static final ResourceType VIDEO_3GPP2
video/3gpp2
-
APPLICATION_X_7Z_COMPRESSED
public static final ResourceType APPLICATION_X_7Z_COMPRESSED
application/x-7z-compressed
-
-
Constructor Detail
-
ResourceType
public ResourceType(java.lang.CharSequence mimeType, Headers headers, boolean gzip, java.util.List<java.lang.String> extensions)
Creates a new resource type. This is only required if you want to support resource types not included inDEFAULT_EXTENSION_MAPPINGS
- Parameters:
mimeType
- The mime typeheaders
- The headers to respond withgzip
- Whether or not to gzip when servingextensions
- The file extensions for this resource
-
-
Method Detail
-
mimeType
public java.lang.CharSequence mimeType()
- Returns:
- The mime type of this resource, such as
image/jpeg
-
headers
public Headers headers()
- Returns:
- The response headers that mu-server will send when serving this resource type
-
extensions
public java.util.List<java.lang.String> extensions()
- Returns:
- The file name extensions that this resource type is associated with, for example
jpg
andjpeg
-
gzip
public boolean gzip()
- Returns:
- True if by default mu-server gzips this resource type when serving it. (In general text-based resources are gzipped; others aren't.)
-
shortCache
public static Headers shortCache()
- Returns:
- Creates and returns a Headers object with a single cache-control header set for 5 minutes.
-
noCache
public static Headers noCache()
- Returns:
- Creates and returns a Headers object with a single cache-control header set with no-cache.
-
getDefaultMapping
public static java.util.HashMap<java.lang.String,ResourceType> getDefaultMapping()
Can be used as a base to customise mime types viaResourceHandlerBuilder.withExtensionToResourceType(Map)
- Returns:
- Returns the built-in mapping of file extension to resource type that can be added to in order to customise resource types.
-
gzippableMimeTypes
public static java.util.Set<java.lang.String> gzippableMimeTypes(java.util.Collection<ResourceType> resourceTypes)
Given a list of resources, returns the ones that are gzippable- Parameters:
resourceTypes
- Types to check- Returns:
- The types that have
gzip()
returningtrue
-
getResourceTypes
public static java.util.List<ResourceType> getResourceTypes()
- Returns:
- All the resource types defined by mu-server
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-