Skip to content

Instantly share code, notes, and snippets.

@gjcourt
Last active December 20, 2015 05:08
Show Gist options
  • Save gjcourt/6075630 to your computer and use it in GitHub Desktop.
Save gjcourt/6075630 to your computer and use it in GitHub Desktop.
/**
* Parse the query string portion of a string containing a URI or URL.
*/
def parseUri(uri: String): Map[String, Seq[String]] = {
var params = collection.mutable.HashMap[String, Seq[String]]()
val parts = uri split "\\?"
if (parts.length > 1) {
val query = parts(1)
for (param <- query split "&") {
val pair = param split "="
val key = URLDecoder.decode(pair(0), "UTF-8")
val value = pair.length match {
case l if l > 1 => URLDecoder.decode(pair(1), "UTF-8")
case _ => ""
}
params += (key -> Seq(value))
}
}
HashMap() ++ params
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment