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
19 changes: 0 additions & 19 deletions .github/php-low.dockerfile

This file was deleted.

11 changes: 8 additions & 3 deletions .github/php.dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
ARG PHP_DOCKER_VERSION
FROM php:${PHP_DOCKER_VERSION}-cli

RUN apt update
# Buster 已归档,将 apt 源指向 archive.debian.org
RUN sed -i 's|deb.debian.org|archive.debian.org|g' /etc/apt/sources.list
RUN sed -i 's|security.debian.org|archive.debian.org|g' /etc/apt/sources.list
RUN sed -i '/buster-updates/d' /etc/apt/sources.list

RUN apt install -y --force-yes unzip ca-certificates
RUN apt update --allow-unauthenticated

RUN apt install --allow-unauthenticated -y --force-yes unzip ca-certificates

RUN docker-php-ext-install pcntl > /dev/null

RUN curl -o /usr/bin/composer https://getcomposer.org/composer-1.phar && chmod +x /usr/bin/composer
RUN curl -o /usr/bin/composer https://getcomposer.org/download/latest-2.2.x/composer.phar && chmod +x /usr/bin/composer
8 changes: 2 additions & 6 deletions .github/prepare-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ __DIR__=$(cd `dirname $0`; pwd)

cd $__DIR__

if [[ `expr $PHP_DOCKER_VERSION \< 7.1` -eq 0 ]]; then
export PHP_DOCKER_FILE="php.dockerfile"
else
export PHP_DOCKER_FILE="php-low.dockerfile"
fi
export PHP_DOCKER_FILE="php.dockerfile"

containerName=$1

docker-compose up -d $containerName \
docker compose up -d $containerName \
&& docker exec $containerName php -v \
&& docker exec $containerName php -m \
&& docker exec $containerName php --ri curl
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: ci-windows

on: [push, pull_request]

jobs:
ci-windows:
runs-on: windows-latest

strategy:
fail-fast: false
matrix:
php:
- "7.1"
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
- "8.4"
- "8.5"

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, openssl, mbstring, json
coverage: none
tools: composer:v2

- name: Show PHP info
run: |
php -v
php -m
php --ri curl

- name: Install dependencies
run: composer install --no-interaction --prefer-dist

- name: Run tests
run: composer test

- name: Print server logs (on failure)
if: failure()
run: php .github/print-logs.php
11 changes: 7 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push, pull_request]

jobs:
ci-only-curl:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

strategy:
fail-fast: false
Expand All @@ -15,7 +15,7 @@ jobs:
PHP_DOCKER_VERSION: ${{ matrix.php }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: prepare
run: |
Expand All @@ -29,7 +29,7 @@ jobs:
run: php .github/print-logs.php

ci-curl-swoole:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

strategy:
fail-fast: false
Expand All @@ -42,6 +42,9 @@ jobs:
5.0-php8.0,
5.0-php8.1,
5.0-php8.2,
6.2-php8.3,
6.2-php8.4,
6.2-php8.5,
4.8-php7.2,
4.8-php7.3,
4.8-php7.4,
Expand All @@ -53,7 +56,7 @@ jobs:
SWOOLE_DOCKER_VERSION: ${{ matrix.swoole }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: prepare
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push, pull_request]

jobs:
tests:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

strategy:
fail-fast: false
Expand All @@ -15,7 +15,7 @@ jobs:
SWOOLE_DOCKER_VERSION: ${{ matrix.swoole }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Prepare
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push, pull_request]

jobs:
tests:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

strategy:
fail-fast: false
Expand All @@ -15,12 +15,12 @@ jobs:
SWOOLE_DOCKER_VERSION: ${{ matrix.swoole }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Prepare
run: |
./.github/prepare-test.sh swoole
docker exec swoole composer require phpstan/phpstan:~1.10.0 --dev
docker exec swoole composer require phpstan/phpstan:1.10.0 --dev

- name: Test
run: docker exec swoole ./vendor/bin/phpstan analyse --memory-limit 1G
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"require": {
"php": ">=7.1",
"psr/http-message": "~1.0|~2.0",
"psr/log": "~1.0|~2.0|~3.0"
"psr/log": "~1.0|~2.0|~3.0",
"symfony/polyfill-php80": "~1.30.0"
},
"require-dev": {
"swoole/ide-helper": "^4.5",
Expand All @@ -31,4 +32,4 @@
"@composer test"
]
}
}
}
44 changes: 7 additions & 37 deletions src/HttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,6 @@ class HttpRequest
*/
public $websocketCompression = false;

/**
* 代理认证方式.
*
* @var array
*/
public static $proxyAuths = [];

/**
* 代理类型.
*
* @var array
*/
public static $proxyType = [];

/**
* 自动扩展名标志.
*/
Expand Down Expand Up @@ -912,6 +898,7 @@ protected function parseRequestBody($requestBody, $contentType)
}
}
$body = http_build_query($body, '', '&');
break;
}
}
else
Expand Down Expand Up @@ -943,9 +930,8 @@ public function buildRequest($url = null, $requestBody = null, $method = null, $
$method = $this->method;
}
list($body, $files) = $this->parseRequestBody(null === $requestBody ? $this->content : $requestBody, $contentType);
$request = new Request($url, $this->headers, $body, $method);
$saveFileOption = $this->saveFileOption;
$request = $request->withUploadedFiles($files)
$request = (new Request($url, $this->headers, $body, $method))->withUploadedFiles($files)
->withCookieParams($this->cookies)
->withAttribute(Attributes::MAX_REDIRECTS, $this->maxRedirects)
->withAttribute(Attributes::IS_VERIFY_CA, $this->isVerifyCA)
Expand Down Expand Up @@ -1127,7 +1113,7 @@ public function download($fileName, $url = null, $requestBody = null, $method =
$result = $this->saveFile($fileName)->send($url, $requestBody, $method);
if ($isAutoExt)
{
self::parseDownloadAutoExt($result, $fileName);
$result = self::parseDownloadAutoExt($result, $fileName);
}
$this->saveFileOption = [];

Expand Down Expand Up @@ -1174,9 +1160,9 @@ public static function checkDownloadIsAutoExt($fileName, &$tempFileName)
* @param \Yurun\Util\YurunHttp\Http\Response $response
* @param string $tempFileName
*
* @return void
* @return \Yurun\Util\YurunHttp\Http\Response
*/
public static function parseDownloadAutoExt(&$response, $tempFileName)
public static function parseDownloadAutoExt($response, $tempFileName)
{
$ext = MediaType::getExt($response->getHeaderLine('Content-Type'));
if (null === $ext)
Expand All @@ -1185,23 +1171,7 @@ public static function parseDownloadAutoExt(&$response, $tempFileName)
}
$savedFileName = substr($tempFileName, 0, -\strlen(self::AUTO_EXT_TEMP_EXT)) . '.' . $ext;
rename($tempFileName, $savedFileName);
$response = $response->withSavedFileName($savedFileName);
}
}

if (\extension_loaded('curl'))
{
// 代理认证方式
HttpRequest::$proxyAuths = [
'basic' => \CURLAUTH_BASIC,
'ntlm' => \CURLAUTH_NTLM,
];

// 代理类型
HttpRequest::$proxyType = [
'http' => \CURLPROXY_HTTP,
'socks4' => \CURLPROXY_SOCKS4,
'socks4a' => 6, // CURLPROXY_SOCKS4A
'socks5' => \CURLPROXY_SOCKS5,
];
return $response->withSavedFileName($savedFileName);
}
}
11 changes: 1 addition & 10 deletions src/YurunHttp/Co/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,8 @@ public static function run($requests, $timeout = null, $handlerClass = null, $op
{
if (isset($result[$i]))
{
$response = &$result[$i];
HttpRequest::parseDownloadAutoExt($result[$i], $result[$i]->getRequest()->getAttribute(Attributes::SAVE_FILE_PATH));
}
else
{
$response = null;
}
if ($response)
{
HttpRequest::parseDownloadAutoExt($response, $response->getRequest()->getAttribute(Attributes::SAVE_FILE_PATH));
}
unset($response);
}

return $result;
Expand Down
Loading
Loading