Skip to content

Commit de2f722

Browse files
Setting timeout config to Pusher instance (#382)
* Move #381 to a new PR * Bump to version 7.2.4 --------- Co-authored-by: Pusher CI <pusher-ci@pusher.com>
1 parent 416e68d commit de2f722

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

.github/workflows/test.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ name: Tests
33
on:
44
pull_request:
55
push:
6-
branches: [master, main]
7-
6+
branches: [ master, main ]
87
jobs:
98
test:
109
runs-on: ubuntu-20.04

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 7.2.4
4+
5+
* [Fixed] Timeout option is propagated to guzzle client
6+
37
## 7.2.3
48

59
* [Fixed] Include socket_id in batch trigger if included.

src/Pusher.php

+14-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Pusher implements LoggerAwareInterface, PusherInterface
1919
/**
2020
* @var string Version
2121
*/
22-
public static $VERSION = '7.2.3';
22+
public static $VERSION = '7.2.4';
2323

2424
/**
2525
* @var null|PusherCrypto
@@ -64,12 +64,6 @@ public function __construct(string $auth_key, string $secret, string $app_id, ar
6464
{
6565
$this->check_compatibility();
6666

67-
if (!is_null($client)) {
68-
$this->client = $client;
69-
} else {
70-
$this->client = new \GuzzleHttp\Client();
71-
}
72-
7367
$useTLS = true;
7468
if (isset($options['useTLS'])) {
7569
$useTLS = $options['useTLS'] === true;
@@ -119,6 +113,13 @@ public function __construct(string $auth_key, string $secret, string $app_id, ar
119113
);
120114
$this->crypto = new PusherCrypto($parsedKey);
121115
}
116+
117+
118+
if (!is_null($client)) {
119+
$this->client = $client;
120+
} else {
121+
$this->client = new \GuzzleHttp\Client(['timeout' => $this->settings['timeout'],]);
122+
}
122123
}
123124

124125
/**
@@ -724,7 +725,8 @@ public function get(string $path, array $params = [], $associative = false)
724725
'query' => $signature,
725726
'http_errors' => false,
726727
'headers' => $headers,
727-
'base_uri' => $this->channels_url_prefix()
728+
'base_uri' => $this->channels_url_prefix(),
729+
'timeout' => $this->settings['timeout']
728730
]);
729731

730732
$status = $response->getStatusCode();
@@ -776,7 +778,8 @@ public function post(string $path, $body, array $params = [])
776778
'body' => $body,
777779
'http_errors' => false,
778780
'headers' => $headers,
779-
'base_uri' => $this->channels_url_prefix()
781+
'base_uri' => $this->channels_url_prefix(),
782+
'timeout' => $this->settings['timeout']
780783
]);
781784
} catch (ConnectException $e) {
782785
throw new ApiErrorException($e->getMessage());
@@ -826,7 +829,8 @@ public function postAsync(string $path, $body, array $params = []): PromiseInter
826829
'body' => $body,
827830
'http_errors' => false,
828831
'headers' => $headers,
829-
'base_uri' => $this->channels_url_prefix()
832+
'base_uri' => $this->channels_url_prefix(),
833+
'timeout' => $this->settings['timeout'],
830834
])->then(function ($response) {
831835
$status = $response->getStatusCode();
832836

tests/unit/PusherConstructorTest.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public function testUseTLSOptionWillBeOverwrittenByHostAndPortOptionsSetHostAndP
2222
{
2323
$options = [
2424
'useTLS' => true,
25-
'host' => 'test.com',
26-
'port' => '3000',
25+
'host' => 'test.com',
26+
'port' => '3000',
2727
];
2828
$pusher = new Pusher('app_key', 'app_secret', 'app_id', $options);
2929

@@ -60,11 +60,22 @@ public function testClusterOptionIsOverriddenByHostIfItExists(): void
6060
{
6161
$options = [
6262
'cluster' => 'eu',
63-
'host' => 'api.staging.pusher.com',
63+
'host' => 'api.staging.pusher.com',
6464
];
6565
$pusher = new Pusher('app_key', 'app_secret', 'app_id', $options);
6666

6767
$settings = $pusher->getSettings();
6868
self::assertEquals('api.staging.pusher.com', $settings['host']);
6969
}
70+
71+
public function testSetTimeoutOption(): void
72+
{
73+
$options = [
74+
'timeout' => 10,
75+
];
76+
$pusher = new Pusher('app_key', 'app_secret', 'app_id', $options);
77+
78+
$settings = $pusher->getSettings();
79+
self::assertEquals(10, $settings['timeout']);
80+
}
7081
}

0 commit comments

Comments
 (0)