diff --git a/src/http-client/src/Request.php b/src/http-client/src/Request.php index 0c5339df2..8bc3f0de8 100644 --- a/src/http-client/src/Request.php +++ b/src/http-client/src/Request.php @@ -214,6 +214,17 @@ public function withQuery(array $query = []): Request return $this; } + public function withoutQuery(array $keys = []): Request + { + $query = $this->query(); + foreach ($keys as $key) { + unset($query[$key]); + } + $this->request = $this->request->withUri($this->request->getUri()->withQuery(http_build_query($query))); + + return $this; + } + /** * Get the underlying PSR compliant request instance. */ diff --git a/tests/ApiClient/ApiRequestTest.php b/tests/ApiClient/ApiRequestTest.php index 45d32877b..c1ed00038 100644 --- a/tests/ApiClient/ApiRequestTest.php +++ b/tests/ApiClient/ApiRequestTest.php @@ -183,4 +183,12 @@ public function testWithQuery(): void $this->assertSame('param1=value1¶m2=value2', $request->toPsrRequest()->getUri()->getQuery()); } + + public function testWithoutQuery(): void + { + $request = $this->request->withQuery(['param1' => 'value1', 'param2' => 'value2']); + $request->withoutQuery(['param1']); + + $this->assertSame('param2=value2', $request->toPsrRequest()->getUri()->getQuery()); + } }