Skip to content

Instantly share code, notes, and snippets.

@LeifW
Created July 6, 2011 20:55
Show Gist options
  • Select an option

  • Save LeifW/1068304 to your computer and use it in GitHub Desktop.

Select an option

Save LeifW/1068304 to your computer and use it in GitHub Desktop.
Content negotiation
header("Accept").flatMap(
_.split(',').
map(
_.trim.split(';') match {
case Array(t) => 1F -> t
case Array(t, q) => q.split('=')(1).toFloat -> t
}
).
sortWith(_._1 > _._1).
map( _._2 ).
collectFirst {
case "text/html" =>
contentType = "text/html"
serve("/index.html")
case "application/xhtml+xml" =>
contentType = "application/xhtml+xml"
serve("/index.xhtml")
case "application/rdf+xml" =>
contentType = "application/rdf+xml"
serve("/index.rdf")
}
) getOrElse serve("/index.html")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment