Skip to content

Instantly share code, notes, and snippets.

@richdougherty
Created February 7, 2014 22:05
Show Gist options
  • Save richdougherty/8872948 to your computer and use it in GitHub Desktop.
Save richdougherty/8872948 to your computer and use it in GitHub Desktop.
Removing leading slashes before routing requests
import play.api._
import play.api.mvc._
object Global extends GlobalSettings {
case class RewrittenRequestHeader(val path: String, delegate: RequestHeader) extends RequestHeader {
def id = delegate.id
def tags = delegate.tags
def uri = delegate.uri
def method = delegate.method
def version = delegate.version
def queryString = delegate.queryString
def remoteAddress = delegate.remoteAddress
def headers = delegate.headers
}
override def onRouteRequest(header: RequestHeader): Option[Handler] = {
val rewritten = if (header.path.startsWith("//")) {
val newPath = header.path.substring(1)
RewrittenRequestHeader(newPath, header)
} else {
header
}
super.onRouteRequest(rewritten)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment