Skip to content

Instantly share code, notes, and snippets.

@whysoserious
Created November 13, 2014 15:52
Show Gist options
  • Save whysoserious/ff510f2ef6a0c8825481 to your computer and use it in GitHub Desktop.
Save whysoserious/ff510f2ef6a0c8825481 to your computer and use it in GitHub Desktop.
Recognize MIME
import spray.http.MediaType
import spray.http.MediaTypes._
/**
* Recognize MediaType based on file name
* @return MediaType
*/
def mimeType: String => MediaType = {
lazy val ExtensionRegex = """^.*\.(.*)$""".r
lazy val defaultMimeType = `application/octet-stream`
filename: String => {
filename match {
case ExtensionRegex(extension) => forExtension(extension).getOrElse(defaultMimeType)
case _ => defaultMimeType
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment