Skip to content

Commit 0c9d4ae

Browse files
committed
guzzleConfig setting
Resolves #31
1 parent c3febdf commit 0c9d4ae

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Webhooks have a new “Debounce Key Format” setting, which can be used to debouncing similar webhook requests. ([#27](https://github.com/craftcms/webhooks/issues/27))
88
- Webhook URLs can now be set to environment variables or Twig code. ([#18](https://github.com/craftcms/webhooks/issues/18))
99
- Webhooks can now send PUT requests. ([#21](https://github.com/craftcms/webhooks/issues/21))
10+
- Added a new `guzzleConfig` plugin setting, which can be set from `config/webhooks.php` to customize the Guzzle config for webhook requests. ([#31](https://github.com/craftcms/webhooks/issues/31))
1011

1112
### Fixed
1213
- Fixed a bug where webhooks would lose their custom payload template when enabled or disabled from the Manage Webhooks page. ([#22](https://github.com/craftcms/webhooks/issues/22))

src/Plugin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ public function sendRequest(int $requestId): bool
376376

377377
$startTime = microtime(true);
378378
try {
379-
$response = Craft::createGuzzleClient()->request($data['method'], $data['url'], $options);
379+
$response = Craft::createGuzzleClient($this->getSettings()->guzzleConfig)
380+
->request($data['method'], $data['url'], $options);
380381
$success = true;
381382
} catch (RequestException $e) {
382383
$response = $e->getResponse();

src/Settings.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ class Settings extends Model
2424
*/
2525
public $retryDelay = 60;
2626

27+
/**
28+
* @var array Custom config options that should be applied when creating Guzzle clients.
29+
* @since 2.3.0
30+
*/
31+
public $guzzleConfig = [];
32+
2733
/**
2834
* @inheritdoc
2935
*/
@@ -47,4 +53,25 @@ protected function defineRules(): array
4753
[['retryDelay'], 'number', 'integerOnly' => true, 'min' => 0],
4854
];
4955
}
56+
57+
/**
58+
* @inheritdoc
59+
*/
60+
public function fields()
61+
{
62+
$fields = parent::fields();
63+
// guzzleConfig can't be set from the UI so no point in storing it in the project config
64+
unset($fields['guzzleConfig']);
65+
return $fields;
66+
}
67+
68+
/**
69+
* @inheritdoc
70+
*/
71+
public function extraFields()
72+
{
73+
return [
74+
'guzzleConfig',
75+
];
76+
}
5077
}

0 commit comments

Comments
 (0)