Skip to content

Commit

Permalink
Fix query parameters avoiding duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-bisa authored and Andrea Bisacchi committed Mar 11, 2024
1 parent 0279c1c commit 5a9f0d1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ object ApiGatewayProxyHandler {

private[http4s] def decodeEvent[F[_]: Concurrent](
event: ApiGatewayProxyEvent): F[Request[F]] = {
val queryString: String = List(
getQueryStringParameters(event.queryStringParameters),
getMultiValueQueryStringParameters(event.multiValueQueryStringParameters)
).filter(_.nonEmpty).mkString("&")

val queryString: String = getMultiValueQueryStringParameters(
event.multiValueQueryStringParameters)
val uriString: String = event.path + (if (queryString.nonEmpty) s"?$queryString" else "")

for {
Expand Down Expand Up @@ -97,12 +94,6 @@ object ApiGatewayProxyHandler {
)
}

private def getQueryStringParameters(
queryStringParameters: Option[Map[String, String]]): String =
queryStringParameters.fold("") { params =>
params.map { case (key, value) => s"$key=$value" }.mkString("&")
}

private def getMultiValueQueryStringParameters(
multiValueQueryStringParameters: Option[Map[String, List[String]]]): String =
multiValueQueryStringParameters.fold("") { params =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ApiGatewayProxyHandlerSuite extends CatsEffectSuite {
event <- event.as[ApiGatewayProxyEvent].liftTo[IO]
request <- ApiGatewayProxyHandler.decodeEvent[IO](event)
_ <- IO(assertEquals(request.method, Method.POST))
_ <- IO(assertEquals(request.uri, uri"/path/to/resource?foo=bar&foo=bar"))
_ <- IO(assertEquals(request.uri, uri"/path/to/resource?foo=bar"))
_ <- IO(assertEquals(request.headers, expectedHeaders))
responseBody <- request.bodyText.compile.string
_ <- IO(assertEquals(responseBody, expectedBody))
Expand Down

0 comments on commit 5a9f0d1

Please sign in to comment.