Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Console/Commands/CurlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class CurlCommand extends Command
{
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}';
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}';

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

Expand Down
11 changes: 11 additions & 0 deletions src/Models/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Request

private ?int $connectTimeout = null;

private bool $insecure = false;

private function __construct($url, $method)
{
$this->url = $url;
Expand Down Expand Up @@ -106,6 +108,10 @@ public static function create(array $data): self
$request->connectTimeout = $data['connectTimeout'];
}

if ($data['insecure']) {
$request->insecure = true;
}

return $request;
}

Expand Down Expand Up @@ -174,6 +180,11 @@ public function connectTimeout(): int
return $this->connectTimeout;
}

public function isInsecure(): bool
{
return $this->insecure;
}

private static function convertDataType(string $value)
{
return preg_match('/^[1-9]\d*$/', $value) ? intval($value) : $value;
Expand Down
4 changes: 4 additions & 0 deletions src/Support/HttpCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ private static function generateOptions(Request $request): string
$options[] = 'connectTimeout(' . $request->connectTimeout() . ')';
}

if ($request->isInsecure()) {
$options[] = 'withoutVerifying()';
}

if (empty($options)) {
return '';
}
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/Console/Commands/CurlCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static function curlCommandFixtures(): array
'Missing URL scheme' => ['missing-url-scheme'],
'GET request with compressed flag' => ['with-compressed-option'],
'GET request with insecure flag' => ['with-insecure-option'],
'GET request with short k flag' => ['with-insecure-k-option'],
'Request with raw data' => ['with-raw-data'],
'POST request with mixed data' => ['raw-data-mixed'],
];
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/with-insecure-k-option.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl -H 'Accept: application/json' https://example.com -k
3 changes: 3 additions & 0 deletions tests/fixtures/with-insecure-k-option.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Http::acceptJson()
->withoutVerifying()
->get('https://example.com');
1 change: 1 addition & 0 deletions tests/fixtures/with-insecure-option.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Http::acceptJson()
->withoutVerifying()
->get('https://example.com');