ably / ably-php

PHP client library SDK for Ably realtime messaging service
https://ably.com/download
Apache License 2.0
49 stars 10 forks source link

Fix setting X-Ably-* and Accept headers #133

Closed lmars closed 2 years ago

lmars commented 2 years ago

The CURLOPT_HTTPHEADER value should be an array of <key>: <val> strings representing the headers to set.

See https://www.php.net/manual/en/function.curl-setopt.php

Tested manually by running the following program:

require_once __DIR__ . '/vendor/autoload.php';
$settings = array(
  'key'  => '8YPQbA.H2SX3g:************',
  'logLevel' => 4,
);
$app = new \Ably\AblyRest($settings);
$channel = $app->channel('test');
$channel->publish('test', array('handle' => 'x', 'message' => 'y') );

And observing the headers being set correctly in the verbose logs:

2022-02-22 22:12:15     cURL command:   2022-02-22 22:12:15     curl -X POST -X POST --data "{\"data\":\"{\\"handle\\":\\"x\\",\\"message\\":\\"y\\"}\",\"encoding\":\"json\",\"name\":\"test\"}" -H "Authorization: Basic ****************" -H "Accept: application/json" -H "X-Ably-Version: 1.1" -H "X-Ably-Lib: php-1.1.4" -H "Content-Type: application/json" https://rest.ably.io/channels/test/messages

I also confirmed the request was successfully tracked in our internal metrics database.