From f44cf64491f5f556eac15a3c299c968f347f2058 Mon Sep 17 00:00:00 2001 From: David Sheynkman Date: Thu, 12 Dec 2024 15:55:11 +0200 Subject: [PATCH 1/3] Optimized Uri.withQuery --- .../main/scala/org/apache/pekko/http/scaladsl/model/Uri.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/Uri.scala b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/Uri.scala index d93e6860d0..72e4e7f9d0 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/Uri.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/Uri.scala @@ -129,7 +129,8 @@ sealed abstract case class Uri(scheme: String, authority: Authority, path: Path, /** * Returns a copy of this Uri with the given query. */ - def withQuery(query: Query): Uri = copy(rawQueryString = if (query.isEmpty) None else Some(query.toString)) + def withQuery(query: Query): Uri = + createUnsafe(scheme, authority, path, if (query.isEmpty) None else Some(query.toString), fragment) /** * Returns a copy of this Uri with the given query string. From c893fb56b5d55be6bb41f3c7e4b9945855c91ca7 Mon Sep 17 00:00:00 2001 From: David Sheynkman Date: Sun, 15 Dec 2024 11:52:10 +0200 Subject: [PATCH 2/3] Improved UriSpec percent encoding tests --- .../org/apache/pekko/http/scaladsl/model/UriSpec.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/http-core/src/test/scala/org/apache/pekko/http/scaladsl/model/UriSpec.scala b/http-core/src/test/scala/org/apache/pekko/http/scaladsl/model/UriSpec.scala index 557f837aba..bfa495f35f 100644 --- a/http-core/src/test/scala/org/apache/pekko/http/scaladsl/model/UriSpec.scala +++ b/http-core/src/test/scala/org/apache/pekko/http/scaladsl/model/UriSpec.scala @@ -818,6 +818,12 @@ class UriSpec extends AnyWordSpec with Matchers { uri.withRawQueryString("param1=val%22ue1") shouldEqual Uri("http://host/path?param1=val%22ue1#fragment") uri.withRawQueryString("param1=val\"ue1") shouldEqual Uri("http://host/path?param1=val%22ue1#fragment") + uri.withQuery(Query("param1=val\"ue1")) shouldEqual Uri("http://host/path?param1=val%22ue1#fragment") + uri.withQuery(Query(("param1", "val\"ue1"))) shouldEqual Uri("http://host/path?param1=val%22ue1#fragment") + uri.withQuery(Query(Some("param1=val\"ue1"))) shouldEqual Uri("http://host/path?param1=val%22ue1#fragment") + val query = Query.newBuilder.addOne("param1" -> "val\"ue1").result() + uri.withQuery(query) shouldEqual Uri("http://host/path?param1=val%22ue1#fragment") + uri.withFragment("otherFragment") shouldEqual Uri("http://host/path?query#otherFragment") } From 3383c260ef2c9fca78e9f24781768cc62cbbf807 Mon Sep 17 00:00:00 2001 From: David Sheynkman Date: Sun, 15 Dec 2024 15:36:55 +0200 Subject: [PATCH 3/3] Fix UriSpec test for Scala 2.12 --- .../scala/org/apache/pekko/http/scaladsl/model/UriSpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http-core/src/test/scala/org/apache/pekko/http/scaladsl/model/UriSpec.scala b/http-core/src/test/scala/org/apache/pekko/http/scaladsl/model/UriSpec.scala index bfa495f35f..b98965d30f 100644 --- a/http-core/src/test/scala/org/apache/pekko/http/scaladsl/model/UriSpec.scala +++ b/http-core/src/test/scala/org/apache/pekko/http/scaladsl/model/UriSpec.scala @@ -821,7 +821,7 @@ class UriSpec extends AnyWordSpec with Matchers { uri.withQuery(Query("param1=val\"ue1")) shouldEqual Uri("http://host/path?param1=val%22ue1#fragment") uri.withQuery(Query(("param1", "val\"ue1"))) shouldEqual Uri("http://host/path?param1=val%22ue1#fragment") uri.withQuery(Query(Some("param1=val\"ue1"))) shouldEqual Uri("http://host/path?param1=val%22ue1#fragment") - val query = Query.newBuilder.addOne("param1" -> "val\"ue1").result() + val query = Query.newBuilder.+=("param1" -> "val\"ue1").result() uri.withQuery(query) shouldEqual Uri("http://host/path?param1=val%22ue1#fragment") uri.withFragment("otherFragment") shouldEqual Uri("http://host/path?query#otherFragment")