The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

HTTP::UserAgentClientHints - To Handle User Agent Client Hints

SYNOPSIS

    use HTTP::UserAgentClientHints;

    my $uach = HTTP::UserAgentClientHints->new($headers);
    print $uach->platform;

    $headers->header('Accept-CH' => $uach->accept_ch);

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.

WARNIGS: The value of ua and full_version_list are not concreted. These are sama value as *_raw method for now. In the future, these would be changed to a hash reference value after parsing.

ua

To get the value of Sec-CH-UA

mobile

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

platform

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

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

full_version

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

Getters for Sec-CH-UA* raw values

ua_raw =head3 mobile_raw =head3 platform_raw =head3 arch_raw =head3 bitness_raw =head3 model_raw =head3 full_version_list_raw =head3 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

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.