https://github.com/jsor/http-client-hints
Utilities for working with HTTP Client Hints.
https://github.com/jsor/http-client-hints
Last synced: 30 days ago
JSON representation
Utilities for working with HTTP Client Hints.
- Host: GitHub
- URL: https://github.com/jsor/http-client-hints
- Owner: jsor
- License: mit
- Created: 2016-02-11T19:41:20.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-09-06T06:49:26.000Z (almost 8 years ago)
- Last Synced: 2025-01-25T10:41:36.247Z (over 1 year ago)
- Language: PHP
- Size: 18.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
HTTP Client Hints
=================
[](https://travis-ci.org/jsor/http-client-hints?branch=master)
[](https://coveralls.io/github/jsor/http-client-hints?branch=master)
Utilities for working with
[HTTP Client Hints](https://httpwg.org/http-extensions/client-hints.html).
Installation
------------
Install the latest version with [Composer](https://getcomposer.org).
```bash
composer require jsor/http-client-hints
```
Check the [Packagist page](https://packagist.org/packages/jsor/http-client-hints)
for all available versions.
Example
-------
```php
$resolved = (new Jsor\HttpClientHints\Resolver())
->withAllowedHeaders([
// Process only Width and DPR headers
'Width',
'DPR',
])
->withMapping([
// Map Width header to w key
'width' => 'w',
// Needed to extract the height from the query params
// for recalculation depending on Width if present
'height' => 'h',
])
->resolve($_SERVER, $_GET)
;
if (isset($resolved['dpr'])) {
header('Content-DPR: ' . $resolved['dpr']);
header('Vary: DPR', false);
}
if (isset($resolved['w'])) {
header('Vary: Width', false);
}
// Use $resolved to generate thumbnails.
// If you use Glide (https://github.com/thephpleague/glide), this could look
// something like:
$server = League\Glide\ServerFactory::create([
'source' => 'path/to/source/folder',
'cache' => 'path/to/cache/folder',
]);
$server->outputImage($path, array_merge($_GET, $resolved));
```
License
-------
Copyright (c) 2016-2018 Jan Sorgalla.
Released under the [MIT License](LICENSE).