From f240ca43fdbd7b792cc7fec4a258d49f9fb44956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20Le=C3=B3n=20Canto?= Date: Sat, 27 Jul 2019 15:33:17 +0200 Subject: [PATCH] Add proxy, timeout and option to disable to verify SSL in CURL command --- .gitignore | 1 + composer.json | 4 ++++ src/Formatter/CurlFormatter.php | 28 +++++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 3a9875b..4e48a05 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /vendor/ composer.lock +/.idea diff --git a/composer.json b/composer.json index 1802db1..e4dd027 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,10 @@ { "name": "Nikita Nefedov", "email": "inefedor@gmail.com" + }, + { + "name": "Victor Leon", + "email": "victorleoncanto@gmail.com" } ], "extra": { diff --git a/src/Formatter/CurlFormatter.php b/src/Formatter/CurlFormatter.php index d30313d..f84117c 100644 --- a/src/Formatter/CurlFormatter.php +++ b/src/Formatter/CurlFormatter.php @@ -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)); } @@ -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); @@ -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); } /** @@ -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(); } }