php-extended / php-http-client-gzip
符合psr-18规范的中间件客户端,处理gz压缩和解压缩
7.0.6
2024-07-31 13:47 UTC
Requires
- php: >=8.0
- ext-zip: *
- psr/http-client: ^1
- psr/http-factory: ^1
Requires (Dev)
- dev-master
- 7.0.6
- 7.0.5
- 7.0.4
- 7.0.3
- 7.0.2
- 7.0.1
- 7.0.0
- 6.1.6
- 6.1.5
- 6.1.4
- 6.1.3
- 6.1.2
- 6.1.1
- 6.1.0
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.0.1
- 5.0.0
- 4.0.1
- 4.0.0
- 3.1.23
- 3.1.22
- 3.1.21
- 3.1.20
- 3.1.19
- 3.1.18
- 3.1.17
- 3.1.16
- 3.1.15
- 3.1.14
- 3.1.13
- 3.1.12
- 3.1.11
- 3.1.10
- 3.1.9
- 3.1.8
- 3.1.7
- 3.1.6
- 3.1.5
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.0.0
- 1.0.2
- 1.0.1
- 1.0.0
This package is auto-updated.
Last update: 2024-08-31 12:02:47 UTC
README
符合psr-18规范的中间件客户端,处理gz压缩和解压缩。
安装
此库的安装通过composer完成,所有类的自动加载都通过其自动加载器完成。
- 从他们的网站下载
composer.phar
。 - 然后运行以下命令安装此库作为依赖项
php composer.phar php-extended/php-http-client-gzip ^7
基本用法
此库用于为http请求和响应创建中间人,并在请求通过时记录事件。可以使用以下方式使用
/** @var $client Psr\Http\Message\ProcessorInterface */ // psr-18
/** @var $request Psr\Http\Message\RequestInterface */ // psr-7
$client = new GzipClient($client);
$response = $client->sendRequest($request);
/** @var $response Psr\Http\Message\ResponseInterface */
此库处理请求中添加 Accept-Header
和响应中根据 Content-Encoding
头解码。
此库还可以解压缩接收到的类似gz的文件。为了使其工作
- 首先,请求必须包含一个指向有效文件路径的
X-Php-Download-File
头。如果该位置已存在文件,它将被覆盖。 - 其次,http客户端必须支持
X-Php-Download-File
头以将下载的文件写入该位置并从该文件创建一个StreamInterface
。
如果响应给 X-Php-Download-File
的文件是兼容gzip的文件,它将被解压缩到与当前文件相同的目录中,但具有一个新名字。tarball或等效文件中的所有文件都将连接到该位置。
此客户端将设置 X-Php-Uncompressed-File
头,以包含新解压缩文件的路径,并将指向下载文件的现有 StreamInterface
替换为指向解压缩文件的新 StreamInterface
。
下载的文件不会删除,删除下载的文件和解压缩文件是调用库的职责,一旦工作完成。
$client = new GzipClient($client);
$request = $request->withAddedHeader('X-Php-Download-File' => '/tmp/file.gz');
$response = $client->sendRequest($response);
$stream = $response->getBody();
/** @var $stream \Psr\Http\Message\StreamInterface */
// the stream points to the /tmp/{$sha1} file that is unzipped
// the exact location of the file can be uncovered with :
$filePath = $response->getHeader('X-Php-Uncompressed-File');
许可证
MIT (见 许可证文件).