-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RDF MimeTypes, HttpSig, jsld examples
- Loading branch information
Showing
12 changed files
with
1,155 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
package run.cosy.http | ||
|
||
import akka.http.scaladsl.model.MediaTypes._ | ||
import akka.http.scaladsl.model.{HttpCharsets, MediaType, MediaTypes} | ||
|
||
/** | ||
* Sadly Akka's MediaType registry is not extensible, and the file extension names are often oddly chosen | ||
* Todo: extend this so that servers can configure the extensions | ||
**/ | ||
object FileExtensions { | ||
val akkaMimeTypes = Seq(`application/atom+xml`, | ||
`application/base64`, | ||
`application/cbor`, | ||
`application/gnutar`, | ||
`application/java-archive`, | ||
`application/javascript`, | ||
`application/json`, | ||
`application/json-patch+json`, | ||
`application/merge-patch+json`, | ||
`application/problem+json`, | ||
`application/grpc+proto`, | ||
`application/lha`, | ||
`application/lzx`, | ||
`application/msword`, | ||
`application/octet-stream`, | ||
`application/pdf`, | ||
`application/postscript`, | ||
`application/rss+xml`, | ||
`application/soap+xml`, | ||
`application/vnd.api+json`, | ||
`application/vnd.google-earth.kml+xml`, | ||
`application/vnd.google-earth.kmz`, | ||
`application/vnd.ms-excel`, | ||
`application/vnd.ms-excel.addin.macroEnabled.12`, | ||
`application/vnd.ms-excel.sheet.binary.macroEnabled.12`, | ||
`application/vnd.ms-excel.sheet.macroEnabled.12`, | ||
`application/vnd.ms-excel.template.macroEnabled.12`, | ||
`application/vnd.ms-fontobject`, | ||
`application/vnd.ms-powerpoint`, | ||
`application/vnd.ms-powerpoint.addin.macroEnabled.12`, | ||
`application/vnd.ms-powerpoint.presentation.macroEnabled.12`, | ||
`application/vnd.ms-powerpoint.slideshow.macroEnabled.12`, | ||
`application/vnd.ms-word.document.macroEnabled.12`, | ||
`application/vnd.ms-word.template.macroEnabled.12`, | ||
`application/vnd.oasis.opendocument.chart`, | ||
`application/vnd.oasis.opendocument.database`, | ||
`application/vnd.oasis.opendocument.formula`, | ||
`application/vnd.oasis.opendocument.graphics`, | ||
`application/vnd.oasis.opendocument.image`, | ||
`application/vnd.oasis.opendocument.presentation`, | ||
`application/vnd.oasis.opendocument.spreadsheet`, | ||
`application/vnd.oasis.opendocument.text`, | ||
`application/vnd.oasis.opendocument.text-master`, | ||
`application/vnd.oasis.opendocument.text-web`, | ||
`application/vnd.openxmlformats-officedocument.presentationml.presentation`, | ||
`application/vnd.openxmlformats-officedocument.presentationml.slide`, | ||
`application/vnd.openxmlformats-officedocument.presentationml.slideshow`, | ||
`application/vnd.openxmlformats-officedocument.presentationml.template`, | ||
`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`, | ||
`application/vnd.openxmlformats-officedocument.spreadsheetml.template`, | ||
`application/vnd.openxmlformats-officedocument.wordprocessingml.document`, | ||
`application/vnd.openxmlformats-officedocument.wordprocessingml.template`, | ||
`application/x-7z-compressed`, | ||
`application/x-ace-compressed`, | ||
`application/x-apple-diskimage`, | ||
`application/x-arc-compressed`, | ||
`application/x-bzip`, | ||
`application/x-bzip2`, | ||
`application/x-chrome-extension`, | ||
`application/x-compress`, | ||
`application/x-compressed`, | ||
`application/x-debian-package`, | ||
`application/x-dvi`, | ||
`application/x-font-truetype`, | ||
`application/x-font-opentype`, | ||
`application/x-gtar`, | ||
`application/x-gzip`, | ||
`application/x-latex`, | ||
`application/x-rar-compressed`, | ||
`application/x-redhat-package-manager`, | ||
`application/x-shockwave-flash`, | ||
`application/x-tar`, | ||
`application/x-tex`, | ||
`application/x-texinfo`, | ||
`application/x-vrml`, | ||
`application/x-www-form-urlencoded`, | ||
`application/x-x509-ca-cert`, | ||
`application/x-xpinstall`, | ||
`application/xhtml+xml`, | ||
`application/xml-dtd`, | ||
`application/xml`, | ||
`application/problem+xml`, | ||
`application/zip`, | ||
`audio/aiff`, | ||
`audio/basic`, | ||
`audio/midi`, | ||
`audio/mod`, | ||
`audio/mpeg`, | ||
`audio/ogg`, | ||
`audio/voc`, | ||
`audio/vorbis`, | ||
`audio/voxware`, | ||
`audio/wav`, | ||
`audio/x-realaudio`, | ||
`audio/x-psid`, | ||
`audio/xm`, | ||
`audio/webm`, | ||
`font/woff`, | ||
`font/woff2`, | ||
`image/gif`, | ||
`image/jpeg`, | ||
`image/pict`, | ||
`image/png`, | ||
`image/svg+xml`, | ||
`image/svgz`, | ||
`image/tiff`, | ||
`image/x-icon`, | ||
`image/x-ms-bmp`, | ||
`image/x-pcx`, | ||
`image/x-pict`, | ||
`image/x-quicktime`, | ||
`image/x-rgb`, | ||
`image/x-xbitmap`, | ||
`image/x-xpixmap`, | ||
`image/webp`, | ||
`message/http`, | ||
`message/delivery-status`, | ||
`message/rfc822`, | ||
`multipart/mixed`, | ||
`multipart/alternative`, | ||
`multipart/related`, | ||
`multipart/form-data`, | ||
`multipart/signed`, | ||
`multipart/encrypted`, | ||
`multipart/byteranges`, | ||
`text/asp`, | ||
`text/cache-manifest`, | ||
`text/calendar`, | ||
`text/css`, | ||
`text/csv`, | ||
`text/event-stream`, | ||
`text/html`, | ||
`text/markdown`, | ||
`text/mcf`, | ||
`text/plain`, | ||
`text/richtext`, | ||
`text/tab-separated-values`, | ||
`text/uri-list`, | ||
`text/vnd.wap.wml`, | ||
`text/vnd.wap.wmlscript`, | ||
`text/x-asm`, | ||
`text/x-c`, | ||
`text/x-component`, | ||
`text/x-h`, | ||
`text/x-java-source`, | ||
`text/x-pascal`, | ||
`text/x-script`, | ||
`text/x-scriptcsh`, | ||
`text/x-scriptelisp`, | ||
`text/x-scriptksh`, | ||
`text/x-scriptlisp`, | ||
`text/x-scriptperl`, | ||
`text/x-scriptperl-module`, | ||
`text/x-scriptphyton`, | ||
`text/x-scriptrexx`, | ||
`text/x-scriptscheme`, | ||
`text/x-scriptsh`, | ||
`text/x-scripttcl`, | ||
`text/x-scripttcsh`, | ||
`text/x-scriptzsh`, | ||
`text/x-server-parsed-html`, | ||
`text/x-setext`, | ||
`text/x-sgml`, | ||
`text/x-speech`, | ||
`text/x-uuencode`, | ||
`text/x-vcalendar`, | ||
`text/x-vcard`, | ||
`text/xml`, | ||
`video/avs-video`, | ||
`video/divx`, | ||
`video/gl`, | ||
`video/mp4`, | ||
`video/mpeg`, | ||
`video/ogg`, | ||
`video/quicktime`, | ||
`video/x-dv`, | ||
`video/x-flv`, | ||
`video/x-motion-jpeg`, | ||
`video/x-ms-asf`, | ||
`video/x-msvideo`, | ||
`video/x-sgi-movie`, | ||
`video/webm` | ||
) | ||
|
||
|
||
private[this] var extensionMap = Map.empty[String, MediaType] | ||
|
||
for {m <- akkaMimeTypes ++ RDFMediaTypes.all} registerFileExtensions(m) | ||
|
||
private def registerFileExtensions[T <: MediaType](mediaType: T): T = | ||
mediaType.fileExtensions.foreach { ext => | ||
val lcExt = ext.toLowerCase | ||
require(!extensionMap.contains(lcExt), | ||
s"Extension '$ext' clash: media-types '${extensionMap(lcExt)}' and '$mediaType'") | ||
extensionMap = extensionMap.updated(lcExt, mediaType) | ||
} | ||
mediaType | ||
|
||
def forExtensionOption(ext: String): Option[MediaType] = extensionMap.get(ext.toLowerCase) | ||
def forExtension(ext: String): MediaType = extensionMap.getOrElse(ext.toLowerCase, `application/octet-stream`) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.