From 5412c81ab1c06da777dce2e772da0da463c7a3a8 Mon Sep 17 00:00:00 2001 From: Rudy Zeinoun Date: Wed, 11 Oct 2023 11:00:38 +0200 Subject: [PATCH 1/3] Missing headers and body in HTTP Request with Psr17 When switching to Psr17, the createRequest function only takes $method and $url. The headers and body have to be sent in separately after. This causes all POST requests to fail with permission error since the token is the first missing parameter that is checked. --- src/Client.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index f4c2e27dc..5855f0ab2 100644 --- a/src/Client.php +++ b/src/Client.php @@ -188,8 +188,12 @@ public function sendRequest(Request $request) list($url, $method, $headers, $body) = $this->prepareRequestMessage($request); + $psr7Request = Psr17FactoryDiscovery::findRequestFactory()->createRequest($method, $url); + foreach($headers as $k=>$v) $psr7Request = $psr7Request->withHeader($k, $v); + $psr7Request = $psr7Request->withBody(Psr17FactoryDiscovery::findStreamFactory()->createStream($body)); + $psr7Response = $this->httpClient->sendRequest( - Psr17FactoryDiscovery::findRequestFactory()->createRequest($method, $url, $headers, $body) + $psr7Request ); static::$requestCount++; From 1d415dcec0817b8339ec9b8ef546685a8b5c38cc Mon Sep 17 00:00:00 2001 From: Rudy Zeinoun Date: Wed, 11 Oct 2023 11:07:40 +0200 Subject: [PATCH 2/3] StyleCI fixes --- src/Client.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 5855f0ab2..a23fd56e0 100644 --- a/src/Client.php +++ b/src/Client.php @@ -189,7 +189,9 @@ public function sendRequest(Request $request) list($url, $method, $headers, $body) = $this->prepareRequestMessage($request); $psr7Request = Psr17FactoryDiscovery::findRequestFactory()->createRequest($method, $url); - foreach($headers as $k=>$v) $psr7Request = $psr7Request->withHeader($k, $v); + foreach($headers as $k => $v) { + $psr7Request = $psr7Request->withHeader($k, $v); + } $psr7Request = $psr7Request->withBody(Psr17FactoryDiscovery::findStreamFactory()->createStream($body)); $psr7Response = $this->httpClient->sendRequest( From 1357a8943eff4b3fb05ff4d3c8d2379ebb4ee2f7 Mon Sep 17 00:00:00 2001 From: Rudy Zeinoun Date: Wed, 11 Oct 2023 11:08:24 +0200 Subject: [PATCH 3/3] Update Client.php --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index a23fd56e0..1d1891989 100644 --- a/src/Client.php +++ b/src/Client.php @@ -189,7 +189,7 @@ public function sendRequest(Request $request) list($url, $method, $headers, $body) = $this->prepareRequestMessage($request); $psr7Request = Psr17FactoryDiscovery::findRequestFactory()->createRequest($method, $url); - foreach($headers as $k => $v) { + foreach ($headers as $k => $v) { $psr7Request = $psr7Request->withHeader($k, $v); } $psr7Request = $psr7Request->withBody(Psr17FactoryDiscovery::findStreamFactory()->createStream($body));