Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(sdk-php): send a numeric default header value as its text
Yudhi Armyndharisfb63f8e6925a
diff --git a/sdk/php/src/Http/HttpExecutor.php b/sdk/php/src/Http/HttpExecutor.phpindex 046065e31..69debe4a5 100644--- a/sdk/php/src/Http/HttpExecutor.php+++ b/sdk/php/src/Http/HttpExecutor.php@@ -78,7 +78,9 @@ class HttpExecutor'OpenWA Client: defaultHeaders has a header name that is not a valid HTTP token');}- if (!is_string($value) || preg_match('/\A[\t\x20-\x7e]*\z/', $value) !== 1) {+ // A number is text to the HTTP stack, which sends its decimal form; the docblock says string.+ $text = is_int($value) || is_float($value) ? (string) $value : $value;+ if (!is_string($text) || preg_match('/\A[\t\x20-\x7e]*\z/', $text) !== 1) {throw new OpenWAException(sprintf('OpenWA Client: defaultHeaders value for "%s" must be text without control or non-ASCII '. 'characters; check for a stray newline',diff --git a/sdk/php/tests/ClientTest.php b/sdk/php/tests/ClientTest.phpindex 08b90c7a9..0a1d7d70a 100644--- a/sdk/php/tests/ClientTest.php+++ b/sdk/php/tests/ClientTest.php@@ -71,6 +71,18 @@ class ClientTest extends TestCase$this->assertSame("a\tb c", $backend->lastCall()['headers']['x-trace'] ?? null);}+ public function testANumericDefaultHeaderValueIsSentAsItsText(): void+ {+ $backend = (new MockBackend())->on(200, []);+ (new \OpenWA\Client([+ 'baseUrl' => 'http://localhost:2785',+ 'apiKey' => 'k',+ 'httpClient' => $backend->httpClient(),+ 'defaultHeaders' => ['X-Tenant-Id' => 42],+ ]))->request('GET', '/api/anything');+ $this->assertSame('42', $backend->lastCall()['headers']['x-tenant-id'] ?? null);+ }+public function testRequiresBaseUrlAndApiKey(): void{$this->expectException(\OpenWA\Exceptions\OpenWAException::class);