Created
December 10, 2011 22:01
-
-
Save softprops/1456645 to your computer and use it in GitHub Desktop.
decoding url path elements in unfiltered
This file contains hidden or 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
libraryDependencies += "net.databinder" %% "unfiltered-netty-server" % "0.5.3" |
This file contains hidden or 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
object Decode { | |
import java.net.URLDecoder | |
import java.nio.charset.Charset | |
trait Extract { | |
def charset: Charset | |
def unapply(raw: String) = try { | |
Some(URLDecoder.decode(raw, charset.name())) | |
} catch { | |
case _ => None | |
} | |
} | |
object utf8 extends Extract { | |
val charset = Charset.forName("utf8") | |
} | |
} | |
object Server { | |
import unfiltered.request._ | |
import unfiltered.response._ | |
import unfiltered.netty._ | |
def main(args: Array[String]) { | |
Http(8080).handler(cycle.Planify{ | |
case GET(Path(Seg("resource" :: "name" :: Decode.utf8(query) :: Nil))) => | |
ResponseString("decoded path element %s" format query) | |
}).run | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment