Skip to content

Utilities for working with HTTP Client Hints.

License

NotificationsYou must be signed in to change notification settings

jsor/http-client-hints

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP Client Hints

Build StatusCoverage Status

Utilities for working with HTTP Client Hints.

Installation

Install the latest version with Composer.

composer require jsor/http-client-hints

Check the Packagist page for all available versions.

Example

$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://.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.

About

Utilities for working with HTTP Client Hints.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages