Skip to content

Commit ba9b6f5

Browse files
authored
Added proxy setter (#3)
* Added proxy setter * Added proxy setter
1 parent a60ef29 commit ba9b6f5

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Webhook.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,35 @@
1010
class Webhook
1111
{
1212
private string $url;
13+
private string $proxy;
1314

1415
public function __construct(string $url)
1516
{
1617
$this->url = $url;
1718
}
1819

20+
public function setProxy(?string $proxy): self
21+
{
22+
$this->proxy = $proxy;
23+
24+
return $this;
25+
}
26+
1927
/**
2028
* @throws DiscordInvalidResponseException
2129
* @throws DiscordSerializeException
22-
* @throws JsonException
2330
*/
2431
public function send(Message $message): int
2532
{
26-
$sent = false;
33+
$data = $message->toArray();
2734
$options = [
2835
CURLOPT_CUSTOMREQUEST => 'POST',
2936
CURLOPT_RETURNTRANSFER => true,
3037
];
3138

32-
$data = $message->toArray();
39+
if (!empty($this->proxy)) {
40+
$options[CURLOPT_PROXY] = $this->proxy;
41+
}
3342

3443
try {
3544
if (isset($data['file'])) {
@@ -54,6 +63,8 @@ public function send(Message $message): int
5463
$ch = curl_init($this->url);
5564
curl_setopt_array($ch, $options);
5665

66+
$sent = false;
67+
5768
while (!$sent) {
5869
$response = curl_exec($ch);
5970
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

0 commit comments

Comments
 (0)