Skip to content

Commit

Permalink
use request.uri.query().toMultiMap from akka-http (#9105) (#9130)
Browse files Browse the repository at this point in the history
We keep the try/catch as `query()` can fail to parse the query

(cherry picked from commit 953620f)
  • Loading branch information
mergify[bot] authored and octonato committed Mar 28, 2019
1 parent 07e73a4 commit 015f864
Showing 1 changed file with 1 addition and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,13 @@ private[server] class AkkaModelConversion(

override lazy val queryMap: Map[String, Seq[String]] = {
try {
toMultiMap(request.uri.query())
request.uri.query().toMultiMap
} catch {
case NonFatal(e) =>
logger.warn("Failed to parse query string; returning empty map.", e)
Map[String, Seq[String]]()
}
}

// This method converts to a `Map`, preserving the order of the query parameters.
// It can be removed and replaced with `query().toMultiMap` once this Akka HTTP
// fix is available upstream:
// https://github.com/akka/akka-http/pull/1270
private def toMultiMap(query: Uri.Query): Map[String, Seq[String]] = {
@tailrec
def append(map: Map[String, Seq[String]], q: Query): Map[String, Seq[String]] = {
if (q.isEmpty) {
map
} else {
append(map.updated(q.key, map.getOrElse(q.key, Vector.empty[String]) :+ q.value), q.tail)
}
}
append(Map.empty, query)
}
},
request.protocol.value,
headers,
Expand Down

0 comments on commit 015f864

Please sign in to comment.