Skip to content

Commit 918cec7

Browse files
authored
Add support for insecure request (#34)
1 parent 945538f commit 918cec7

File tree

7 files changed

+22
-1
lines changed

7 files changed

+22
-1
lines changed

src/Console/Commands/CurlCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class CurlCommand extends Command
99
{
10-
protected $signature = 'shift:curl {--X|request=} {--G|get} {--H|header=*} {--d|data=*} {--data-urlencode=*} {--data-raw=*} {--F|form=*} {--digest} {--basic} {--connect-timeout=} {--max-timeout=} {--retry=} {--s|curl-silent} {--u|user=} {--L|location} {--compressed} {--insecure} {url}';
10+
protected $signature = 'shift:curl {--X|request=} {--G|get} {--H|header=*} {--d|data=*} {--data-urlencode=*} {--data-raw=*} {--F|form=*} {--digest} {--basic} {--connect-timeout=} {--max-timeout=} {--retry=} {--s|curl-silent} {--u|user=} {--L|location} {--compressed} {--k|insecure} {url}';
1111

1212
protected $description = 'Convert a UNIX curl request to an HTTP Client request';
1313

src/Models/Request.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class Request
2727

2828
private ?int $connectTimeout = null;
2929

30+
private bool $insecure = false;
31+
3032
private function __construct($url, $method)
3133
{
3234
$this->url = $url;
@@ -106,6 +108,10 @@ public static function create(array $data): self
106108
$request->connectTimeout = $data['connectTimeout'];
107109
}
108110

111+
if ($data['insecure']) {
112+
$request->insecure = true;
113+
}
114+
109115
return $request;
110116
}
111117

@@ -174,6 +180,11 @@ public function connectTimeout(): int
174180
return $this->connectTimeout;
175181
}
176182

183+
public function isInsecure(): bool
184+
{
185+
return $this->insecure;
186+
}
187+
177188
private static function convertDataType(string $value)
178189
{
179190
return preg_match('/^[1-9]\d*$/', $value) ? intval($value) : $value;

src/Support/HttpCall.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ private static function generateOptions(Request $request): string
9393
$options[] = 'connectTimeout(' . $request->connectTimeout() . ')';
9494
}
9595

96+
if ($request->isInsecure()) {
97+
$options[] = 'withoutVerifying()';
98+
}
99+
96100
if (empty($options)) {
97101
return '';
98102
}

tests/Feature/Console/Commands/CurlCommandTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public static function curlCommandFixtures(): array
6161
'Missing URL scheme' => ['missing-url-scheme'],
6262
'GET request with compressed flag' => ['with-compressed-option'],
6363
'GET request with insecure flag' => ['with-insecure-option'],
64+
'GET request with short k flag' => ['with-insecure-k-option'],
6465
'Request with raw data' => ['with-raw-data'],
6566
'POST request with mixed data' => ['raw-data-mixed'],
6667
];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
curl -H 'Accept: application/json' https://example.com -k
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Http::acceptJson()
2+
->withoutVerifying()
3+
->get('https://example.com');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Http::acceptJson()
2+
->withoutVerifying()
23
->get('https://example.com');

0 commit comments

Comments
 (0)