Created
February 7, 2014 22:05
-
-
Save richdougherty/8872948 to your computer and use it in GitHub Desktop.
Removing leading slashes before routing requests
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
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