NAME

HTTP::UserAgentClientHints - To Handle User Agent Client Hints

SYNOPSIS

This is an example of app.psgi application with HTTP::UserAgentclientHints.

use strict;
use warnings;
use Plack::Request;
use HTTP::UserAgentClientHints;

my $app = sub {
    my $env = shift;

    my $req = Plack::Request->new($env);
    my $uach = HTTP::UserAgentClientHints->new($req->headers);

    return [
        200,
        [
            "Content-Type", "text/plain",
            "Accept-CH", $uach->accept_ch,
        ],
        [$uach->platform || ''],
    ];
};

Within a browser it supports UA-CH, then a response will include a platform information.

DESCRIPTION

HTTP::UserAgentClientHints is the module which gives you a utility to handle User Agent Client Hints (UA-CH)

METHODS

new($http_headers_object)

The constructor. The $http_headers_object is required. It should be an object like HTTP::Headers which needs to have header method to get HTTP Header.

Getters for Sec-CH-UA*

These methods below are normalized to remove double-quotes around value and strip `?` on Sec-UA-CH-Mobile.

ua

To get the value of Sec-CH-UA as an object of HTTP::UserAgentClientHints::BrandVersion

mobile

To get the value of Sec-CH-UA-Mobile

platform

To get the value of Sec-CH-UA-Platform

platform_version

To get the value of Sec-CH-UA-Platform-Version

arch

To get the value of Sec-CH-UA-Arch

bitness

To get the value of Sec-CH-UA-Bitness

model

To get the value of Sec-CH-UA-Model

full_version_list

To get the value of Sec-CH-UA-Full-Version-List as an object of HTTP::UserAgentClientHints::BrandVersion

full_version

To get the value of Sec-CH-UA-Full-Version

Getters for Sec-CH-UA* raw values

ua_raw

mobile_raw

platform_raw

platform_version_raw

arch_raw

bitness_raw

model_raw

full_version_list_raw

full_version_raw

accept_ch(\@excepts)

To get a string for Accept-CH header in order to request UA-CH. By default, there are the full fields of UA-CH which are including Sec-CH-UA-Full-Version even it's deprecated. If you want to filter fields, then you should set the argument as array ref like below.

# filtered Sec-CH-UA-Full-Version and Sec-CH-UA-Bitness
$uach->accept_ch(qw/Sec-CH-UA-Full-Version Sec-CH-UA-Bitness/);

REPOSITORY

HTTP::UserAgentClientHints is hosted on github: http://github.com/bayashi/HTTP-UserAgentClientHints

I appreciate any feedback :D

AUTHOR

Dai Okabayashi <bayashi@cpan.org>

SEE ALSO

https://github.com/WICG/ua-client-hints/blob/main/README.md

https://wicg.github.io/ua-client-hints/

LICENSE

HTTP::UserAgentClientHints is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. (Note that, unlike the Artistic License 1.0, version 2.0 is GPL compatible by itself, hence there is no benefit to having an Artistic 2.0 / GPL disjunction.) See the file LICENSE for details.