Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(sdk-php): send the request method in capitals

Yudhi Armyndharis5c81a6dac883
diff --git a/sdk/php/src/Http/HttpExecutor.php b/sdk/php/src/Http/HttpExecutor.php
index a34f9d534..21c6bf7a7 100644
--- a/sdk/php/src/Http/HttpExecutor.php
+++ b/sdk/php/src/Http/HttpExecutor.php
@@ -207,6 +207,8 @@ class HttpExecutor
*/
private function send(string $method, string $path, array $query, $body, ?string $idempotencyKey = null): ResponseInterface
{
+ // Guzzle 7 upper-cased the method itself; Guzzle 8 sends it as written, and the gateway refuses "get".
+ $method = strtoupper($method);
if ($idempotencyKey !== null && preg_match('/\A[\x21-\x7E]{1,255}\z/', $idempotencyKey) !== 1) {
throw new \InvalidArgumentException('Idempotency-Key must contain 1-255 visible ASCII characters');
}
diff --git a/sdk/php/tests/ClientTest.php b/sdk/php/tests/ClientTest.php
index 5b220d344..8322f2aab 100644
--- a/sdk/php/tests/ClientTest.php
+++ b/sdk/php/tests/ClientTest.php
@@ -298,6 +298,26 @@ class ClientTest extends TestCase
$this->assertStringContainsString('a=1', $backend->lastCall()['query']);
}
+ public function testRawRequestSendsTheMethodInCapitals(): void
+ {
+ // Guzzle 7 upper-cased the method itself; Guzzle 8 sends it as written, and the gateway refuses "get".
+ $backend = new MockBackend();
+ $client = $backend->makeClient();
+ foreach (['get' => 'GET', 'Post' => 'POST', 'delete' => 'DELETE'] as $written => $sent) {
+ $backend->on(200, []);
+ $client->request($written, '/api/anything');
+ $this->assertSame($sent, $backend->lastCall()['method']);
+ }
+
+ $backend->on(404, ['statusCode' => 404, 'message' => 'missing', 'error' => 'Not Found']);
+ try {
+ $client->request('get', '/api/missing');
+ $this->fail('Expected exception');
+ } catch (OpenWANotFoundException $e) {
+ $this->assertStringContainsString('GET /api/missing', $e->getMessage());
+ }
+ }
+
public function testBaseUrlPathPrefixIsPreserved(): void
{
// A base URL with a path prefix (e.g. behind a reverse proxy at /v1) must