php-extended/php-api-endpoint-http-gzip

This package is abandoned and no longer maintained. The author suggests using the php-extended/php-http-client-gzip package instead.

An implementation of the php-extended/php-api-endpoint-http-interface that unzip data on the fly when the responses are queried

6.0.5 2023-08-13 13:32 UTC

README

An implementation of the php-extended/php-api-endpoint-http-interface that unzip data on the fly when the responses are queried.

coverage build status

Installation

The installation of this library is made via composer and the autoloading of all classes of this library is made through their autoloader.

  • Download composer.phar from their website.
  • Then run the following command to install this library as dependency :
  • php composer.phar php-extended/php-api-endpoint-http-gzip ^6

Basic Usage

This library needs multiple conditions for it to work :

  • First, The request must contain an X-Php-Download-File header pointing to a possible valid file in an existing and writeable directory. This is where the downloaded file will be downloaded by the http client.
  • Second, an http client that supports the X-Php-Download-File header to write the body of the http request in that file.
  • Third, the http client must set an X-Request-Header-X-Php-Download-File header in the response that points to that same file. If it does not, it may set an X-Php-Download-File header instead.
  • Fourth, the http client must give a Response with a stream that points to this file.

What this endpoint does is, for each time a file is requested, it will try to uncompress it in the same directory as it is, with a new name. It will replace the existing X-Request-Header-X-Php-Download-File and X-Php-Download-File headers in the request to point to the new uncompressed file, and will change the stream of the response with a new stream pointing to the new file. The old file that was requested at the X-Php-Download-File header in the request is deleted if the uncompress operation is successful.


/* @var $httpEndpoint \PhpExtended\Endpoint\EndpointInterface */

$gzipEndpoint = new GzipHttpEndpoint($httpEndpoint);

$stream = $gzipEndpoint->httpGet($gzipEndpoint->createUri('https://example.com/path/to/file.gz'), [
	'X-Php-Download-File' => '/tmp/file.gz',
]);

/* @var $stream \Psr\Http\Message\StreamInterface */

Once you're finished with the stream you can delete the file (using the metadata of the stream you can find the file name). Alternatively, using $gzipEndpoint->httpGetResponse() you will get the http response instead of only the stream and can get the file path with the X-Php-Download-File header.

License

MIT (See license file).