Package io.muserver.handlers
Class ResourceType
- java.lang.Object
-
- io.muserver.handlers.ResourceType
-
public class ResourceType extends java.lang.ObjectUsed by the
ResourceHandlerto 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 ResourceTypeAPPLICATION_EPUB_ZIPapplication/epub-zipstatic ResourceTypeAPPLICATION_GZIPapplication/gzipstatic ResourceTypeAPPLICATION_JAVA_ARCHIVEapplication/java-archivestatic ResourceTypeAPPLICATION_JAVASCRIPTapplication/javascriptstatic ResourceTypeAPPLICATION_JSONapplication/jsonstatic ResourceTypeAPPLICATION_MSWORDapplication/mswordstatic ResourceTypeAPPLICATION_OCTET_STREAMapplication/octet-streamstatic ResourceTypeAPPLICATION_OGGapplication/oggstatic ResourceTypeAPPLICATION_PDFapplication/pdfstatic ResourceTypeAPPLICATION_RTFapplication/rtfstatic ResourceTypeAPPLICATION_TYPESCRIPTapplication/typescriptstatic ResourceTypeAPPLICATION_VND_AMAZON_EBOOKapplication/vnd-amazon-ebookstatic ResourceTypeAPPLICATION_VND_APPLE_INSTALLER_XMLapplication/vnd-apple-installer-xmlstatic ResourceTypeAPPLICATION_VND_MOZILLA_XUL_XMLapplication/vnd-mozilla-xul-xmlstatic ResourceTypeAPPLICATION_VND_MS_EXCELapplication/vnd-ms-excelstatic ResourceTypeAPPLICATION_VND_MS_FONTOBJECTapplication/vnd-ms-fontobjectstatic ResourceTypeAPPLICATION_VND_MS_POWERPOINTapplication/vnd-ms-powerpointstatic ResourceTypeAPPLICATION_VND_OASIS_OPENDOCUMENT_PRESENTATIONapplication/vnd-oasis-opendocument-presentationstatic ResourceTypeAPPLICATION_VND_OASIS_OPENDOCUMENT_SPREADSHEETapplication/vnd-oasis-opendocument-spreadsheetstatic ResourceTypeAPPLICATION_VND_OASIS_OPENDOCUMENT_TEXTapplication/vnd-oasis-opendocument-textstatic ResourceTypeAPPLICATION_VND_VISIOapplication/vnd-visiostatic ResourceTypeAPPLICATION_X_7Z_COMPRESSEDapplication/x-7z-compressedstatic ResourceTypeAPPLICATION_X_ABIWORDapplication/x-abiwordstatic ResourceTypeAPPLICATION_X_BZIPapplication/x-bzipstatic ResourceTypeAPPLICATION_X_BZIP2application/x-bzip2static ResourceTypeAPPLICATION_X_CSHapplication/x-cshstatic ResourceTypeAPPLICATION_X_RAR_COMPRESSEDapplication/x-rar-compressedstatic ResourceTypeAPPLICATION_X_SHapplication/x-shstatic ResourceTypeAPPLICATION_X_SHOCKWAVE_FLASHapplication/x-shockwave-flashstatic ResourceTypeAPPLICATION_X_TARapplication/x-tarstatic ResourceTypeAPPLICATION_XHTML_XMLapplication/xhtml-xmlstatic ResourceTypeAPPLICATION_XMLapplication/xmlstatic ResourceTypeAPPLICATION_ZIPapplication/zipstatic ResourceTypeAUDIO_AACaudio/aacstatic ResourceTypeAUDIO_MIDIaudio/midistatic ResourceTypeAUDIO_OGGaudio/oggstatic ResourceTypeAUDIO_WEBMaudio/webmstatic ResourceTypeAUDIO_X_WAVaudio/x-wavstatic ResourceTypeDEFAULTThe resource type used when no others match.static java.util.Map<java.lang.String,ResourceType>DEFAULT_EXTENSION_MAPPINGSThe mapping of file extensions (such as "jpg") to resource types (such asIMAGE_JPEGthat mu-server uses by default when serving static content.static ResourceTypeFONT_OTFfont/otfstatic ResourceTypeFONT_TTFfont/ttfstatic ResourceTypeFONT_WOFFfont/woffstatic ResourceTypeFONT_WOFF2font/woff2static ResourceTypeIMAGE_AVIFimage/avifstatic ResourceTypeIMAGE_GIFimage/gifstatic ResourceTypeIMAGE_JPEGimage/jpegstatic ResourceTypeIMAGE_PNGimage/pngstatic ResourceTypeIMAGE_SVG_XMLimage/svg-xmlstatic ResourceTypeIMAGE_TIFFimage/tiffstatic ResourceTypeIMAGE_WEBPimage/webpstatic ResourceTypeIMAGE_X_ICONimage/x-iconstatic ResourceTypeTEXT_CALENDARtext/calendar;charset=utf-8static ResourceTypeTEXT_CSStext/cssstatic ResourceTypeTEXT_CSVtext/csv;charset=utf-8static ResourceTypeTEXT_HTMLtext/html;charset=utf-8static ResourceTypeTEXT_MARKDOWNtext/markdown;charset=utf-8static ResourceTypeTEXT_PLAINtext/plain;charset=utf-8static ResourceTypeVIDEO_3GPPvideo/3gppstatic ResourceTypeVIDEO_3GPP2video/3gpp2static ResourceTypeVIDEO_MP4video/mp4static ResourceTypeVIDEO_MPEGvideo/mpegstatic ResourceTypeVIDEO_OGGvideo/oggstatic ResourceTypeVIDEO_WEBMvideo/webmstatic ResourceTypeVIDEO_X_MATROSKAvideo/x-matroskastatic ResourceTypeVIDEO_X_MSVIDEOvideo/x-msvideostatic ResourceTypeWEB_APP_MANIFESTweb/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()booleangzip()static java.util.Set<java.lang.String>gzippableMimeTypes(java.util.Collection<ResourceType> resourceTypes)Given a list of resources, returns the ones that are gzippableHeadersheaders()java.lang.CharSequencemimeType()static HeadersnoCache()static HeadersshortCache()java.lang.StringtoString()
-
-
-
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_JPEGthat mu-server uses by default when serving static content.
-
DEFAULT
public static final ResourceType DEFAULT
The resource type used when no others match. In this case,ContentTypes.APPLICATION_OCTET_STREAMis 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
-
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_MP4
public static final ResourceType VIDEO_MP4
video/mp4
-
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
jpgandjpeg
-
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:
toStringin classjava.lang.Object
-
-