Skip to content

Commit

Permalink
Add proxy, timeout and option to disable to verify SSL in CURL command
Browse files Browse the repository at this point in the history
  • Loading branch information
venceitor committed Jul 27, 2019
1 parent c1338ae commit f240ca4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
composer.lock
/.idea
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
{
"name": "Nikita Nefedov",
"email": "[email protected]"
},
{
"name": "Victor Leon",
"email": "[email protected]"
}
],
"extra": {
Expand Down
28 changes: 25 additions & 3 deletions src/Formatter/CurlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected function extractBodyArgument(RequestInterface $request)

if ($contents) {
// clean input of null bytes
$contents = str_replace(chr(0), '', $contents);
$contents = str_replace(chr(0), '', $contents);
$this->addOption('d', $this->escapeShellArgument($contents));
}

Expand Down Expand Up @@ -199,6 +199,28 @@ protected function extractHeadersArgument(RequestInterface $request, array $opti
}
}

/**
* @param RequestInterface $request
* @param array $options
*/
protected function extractCommonArguments(RequestInterface $request, array $options)
{
$proxy = isset($options['proxy']) ? $options['proxy'] : '';
if(!empty($proxy)) {
$this->addOption('x', $this->escapeShellArgument($proxy));
}

$timeout = isset($options['timeout']) ? $options['timeout'] : '';
if(!empty($timeout)) {
$this->addOption('-connect-timeout', $timeout);
}

$verifySsl = isset($options['verify']) ? $options['verify'] : true;
if(!$verifySsl) {
$this->addOption('k');
}
}

protected function addOptionsToCommand()
{
ksort($this->options);
Expand Down Expand Up @@ -227,6 +249,7 @@ protected function extractArguments(RequestInterface $request, array $options)
$this->extractCookiesArgument($request, $options);
$this->extractHeadersArgument($request, $options);
$this->extractUrlArgument($request);
$this->extractCommonArguments($request, $options);
}

/**
Expand All @@ -240,7 +263,6 @@ protected function extractUrlArgument(RequestInterface $request)
protected function escapeShellArgument($argument)
{
$process = new Process([$argument]);
$escaped = $process->getCommandLine();
return $escaped;
return $process->getCommandLine();
}
}

0 comments on commit f240ca4

Please sign in to comment.