diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a9962cf..f56c25e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,7 +11,7 @@ on: env: extensions: 'json' cache-version: '1' - composer-version: 'v1' + composer-version: 'v2' composer-install: 'composer update --no-interaction --no-progress --no-suggest --prefer-dist --prefer-stable' jobs: @@ -21,13 +21,13 @@ jobs: strategy: matrix: - php-version: [ '8.1', '8.2' ] + php-version: [ '8.1', '8.2', '8.3', '8.4' ] operating-system: [ 'ubuntu-latest' ] fail-fast: false steps: - name: 'Checkout' - uses: 'actions/checkout@v2' + uses: 'actions/checkout@v4' - name: 'Setup PHP cache environment' id: 'extcache' @@ -38,7 +38,7 @@ jobs: key: '${{ env.cache-version }}' - name: 'Cache PHP extensions' - uses: 'actions/cache@v2' + uses: 'actions/cache@v4' with: path: '${{ steps.extcache.outputs.dir }}' key: '${{ steps.extcache.outputs.key }}' @@ -56,10 +56,10 @@ jobs: - name: 'Get Composer cache directory' id: 'composercache' - run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"' + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: 'Cache PHP dependencies' - uses: "actions/cache@v2" + uses: "actions/cache@v4" with: path: '${{ steps.composercache.outputs.dir }}' key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}" @@ -80,13 +80,13 @@ jobs: strategy: matrix: - php-version: [ '8.1', '8.2' ] + php-version: [ '8.1', '8.2', '8.3', '8.4' ] operating-system: [ 'ubuntu-latest' ] fail-fast: false steps: - name: 'Checkout' - uses: 'actions/checkout@v2' + uses: 'actions/checkout@v4' - name: 'Setup PHP cache environment' id: 'extcache' @@ -97,7 +97,7 @@ jobs: key: '${{ env.cache-version }}' - name: 'Cache PHP extensions' - uses: 'actions/cache@v2' + uses: 'actions/cache@v4' with: path: '${{ steps.extcache.outputs.dir }}' key: '${{ steps.extcache.outputs.key }}' @@ -115,10 +115,10 @@ jobs: - name: 'Get Composer cache directory' id: 'composercache' - run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"' + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: 'Cache PHP dependencies' - uses: 'actions/cache@v2' + uses: 'actions/cache@v4' with: path: '${{ steps.composercache.outputs.dir }}' key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}" @@ -136,15 +136,14 @@ jobs: strategy: matrix: - php-version: [ '8.1', '8.2' ] + php-version: [ '8.1', '8.2', '8.3', '8.4' ] operating-system: [ 'ubuntu-latest' ] composer-args: [ '' ] - fail-fast: false steps: - name: 'Checkout' - uses: 'actions/checkout@v2' + uses: 'actions/checkout@v4' - name: 'Setup PHP cache environment' id: 'extcache' @@ -155,7 +154,7 @@ jobs: key: '${{ env.cache-version }}' - name: 'Cache PHP extensions' - uses: 'actions/cache@v2' + uses: 'actions/cache@v4' with: path: '${{ steps.extcache.outputs.dir }}' key: '${{ steps.extcache.outputs.key }}' @@ -173,10 +172,10 @@ jobs: - name: 'Get Composer cache directory' id: 'composercache' - run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"' + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: 'Cache PHP dependencies' - uses: 'actions/cache@v2' + uses: 'actions/cache@v4' with: path: '${{ steps.composercache.outputs.dir }}' key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}" @@ -194,7 +193,7 @@ jobs: strategy: matrix: - php-version: [ '8.1', '8.2' ] + php-version: [ '8.1', '8.2', '8.3', '8.4' ] operating-system: [ 'ubuntu-latest' ] fail-fast: false @@ -202,7 +201,7 @@ jobs: steps: - name: 'Checkout' - uses: 'actions/checkout@v2' + uses: 'actions/checkout@v4' - name: 'Setup PHP cache environment' id: 'extcache' @@ -213,7 +212,7 @@ jobs: key: '${{ env.cache-version }}' - name: 'Cache PHP extensions' - uses: 'actions/cache@v2' + uses: 'actions/cache@v4' with: path: '${{ steps.extcache.outputs.dir }}' key: '${{ steps.extcache.outputs.key }}' @@ -231,10 +230,10 @@ jobs: - name: 'Get Composer cache directory' id: 'composercache' - run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"' + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: 'Cache PHP dependencies' - uses: 'actions/cache@v2' + uses: 'actions/cache@v4' with: path: '${{ steps.composercache.outputs.dir }}' key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}" @@ -246,7 +245,7 @@ jobs: - name: 'Tests' run: vendor/bin/tester tests -C --coverage coverage.xml --coverage-src src - - uses: codecov/codecov-action@v1 + - uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} fail_ci_if_error: true diff --git a/docs/en/index.md b/docs/en/index.md index c1e6776..e40a9ca 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -125,6 +125,20 @@ $httpRequest = HttpRequest::from('https://www.example.com/', HttpMethod::GET, [ ]); ``` +Option `verify` can be set by boolean value or by specifying path to accepted certificate file. + +```php +$httpRequest = HttpRequest::from('https://www.example.com/', HttpMethod::GET, [ + 'verify' => false, +]); +``` + +```php +$httpRequest = HttpRequest::from('https://www.example.com/', HttpMethod::GET, [ + 'verify' => 'path/to/some/accepted/certificate.crt', +]); +``` + ## Redirects diff --git a/src/Fapi/HttpClient/GuzzleHttpClient.php b/src/Fapi/HttpClient/GuzzleHttpClient.php old mode 100644 new mode 100755 index 62f1dde..f44f897 --- a/src/Fapi/HttpClient/GuzzleHttpClient.php +++ b/src/Fapi/HttpClient/GuzzleHttpClient.php @@ -104,8 +104,14 @@ private function processOptions(RequestInterface $request): array $options['connect_timeout'] = (int) ($headerLine !== '' ? $headerLine : 5); } - if ($request->hasHeader('verify') && !(bool) $request->getHeaderLine('verify')) { - $options['verify'] = false; + if ($request->hasHeader('verify')) { + $headerLine = $request->getHeaderLine('verify'); + + $options['verify'] = match ($headerLine) { + 'false', '' => false, + 'true', '1' => true, + default => $headerLine, + }; } if ($request->hasHeader('cert')) { diff --git a/src/Fapi/HttpClient/HttpRequest.php b/src/Fapi/HttpClient/HttpRequest.php old mode 100644 new mode 100755 index 810116c..663fd5f --- a/src/Fapi/HttpClient/HttpRequest.php +++ b/src/Fapi/HttpClient/HttpRequest.php @@ -108,7 +108,11 @@ private static function preProcessHeaders(array $options, StreamInterface|string if (isset($options['verify'])) { $value = $options['verify']; self::validateVerify($value); - $data['verify'] = (bool) $value; + if (is_bool($value)) { + $value = $value ? 'true' : 'false'; + } + + $data['verify'] = $value; } if (isset($options['cert'])) { @@ -211,8 +215,10 @@ private static function validateConnectTimeoutOption(mixed $connectTimeout): voi private static function validateVerify(mixed $verify): void { - if (!is_bool($verify)) { - throw new InvalidArgumentException('Option verify must be an bool.'); + if (!(is_bool($verify) || (is_string($verify) && file_exists($verify)))) { + throw new InvalidArgumentException( + 'Option verify must be an bool or a string path to file, ' . $verify . ' given.', + ); } }