| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTTP::UserAgentClientHints; |
|
2
|
2
|
|
|
2
|
|
182448
|
use strict; |
|
|
2
|
|
|
|
|
13
|
|
|
|
2
|
|
|
|
|
59
|
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
48
|
|
|
4
|
2
|
|
|
2
|
|
856
|
use HTTP::UserAgentClientHints::BrandVersion; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
59
|
|
|
5
|
2
|
|
|
2
|
|
12
|
use HTTP::UserAgentClientHints::Util; |
|
|
2
|
|
|
|
|
11
|
|
|
|
2
|
|
|
|
|
124
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $HTTP_HEADER_PREFIX = 'Sec-CH-UA'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my @FIELDS = qw/ |
|
12
|
|
|
|
|
|
|
UA |
|
13
|
|
|
|
|
|
|
Mobile |
|
14
|
|
|
|
|
|
|
Platform |
|
15
|
|
|
|
|
|
|
Arch |
|
16
|
|
|
|
|
|
|
Bitness |
|
17
|
|
|
|
|
|
|
Model |
|
18
|
|
|
|
|
|
|
Full-Version-List |
|
19
|
|
|
|
|
|
|
Full-Version |
|
20
|
|
|
|
|
|
|
Platform-Version |
|
21
|
|
|
|
|
|
|
/; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Build getters |
|
24
|
|
|
|
|
|
|
for my $field (@FIELDS) { |
|
25
|
|
|
|
|
|
|
my $method = __PACKAGE__->_as_method($field); |
|
26
|
2
|
|
|
2
|
|
10
|
no strict 'refs'; ## no critic |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
1574
|
|
|
27
|
|
|
|
|
|
|
*{__PACKAGE__ . '::' . $method} = sub { |
|
28
|
17
|
|
|
17
|
|
10387
|
my $self = shift; |
|
29
|
17
|
100
|
|
|
|
57
|
if (exists $self->{_value}{$method}) { |
|
30
|
3
|
|
|
|
|
14
|
return $self->{_value}{$method}; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
14
|
|
|
|
|
32
|
my $raw_value = $self->{_headers}->header($self->_as_http_header_key($field)); |
|
33
|
14
|
|
|
|
|
537
|
return $self->{_value}{$method} = $self->_normalize($raw_value, $field); |
|
34
|
|
|
|
|
|
|
}; |
|
35
|
|
|
|
|
|
|
*{__PACKAGE__ . '::' . $method . '_raw'} = sub { |
|
36
|
15
|
|
|
15
|
|
9451
|
my $self = shift; |
|
37
|
15
|
100
|
|
|
|
50
|
if (exists $self->{_value_raw}{$method}) { |
|
38
|
1
|
|
|
|
|
5
|
return $self->{_value_raw}{$method}; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
14
|
|
|
|
|
35
|
return $self->{_value_raw}{$method} = $self->{_headers}->header($self->_as_http_header_key($field)); |
|
41
|
|
|
|
|
|
|
}; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $FULL_ACCEPT_CH = __PACKAGE__->_accept_ch; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _as_method { |
|
47
|
18
|
|
|
18
|
|
36
|
my ($self, $field) = @_; |
|
48
|
|
|
|
|
|
|
|
|
49
|
18
|
|
|
|
|
41
|
$field =~ s/-/_/g; |
|
50
|
18
|
|
|
|
|
40
|
$field = lc $field; |
|
51
|
|
|
|
|
|
|
|
|
52
|
18
|
|
|
|
|
38
|
return $field; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _as_http_header_key { |
|
56
|
64
|
|
|
64
|
|
123
|
my ($self, $field) = @_; |
|
57
|
|
|
|
|
|
|
|
|
58
|
64
|
100
|
66
|
|
|
341
|
return $HTTP_HEADER_PREFIX . (!$field || $field eq 'UA' ? '' : "-$field"); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _normalize { |
|
62
|
14
|
|
|
14
|
|
35
|
my ($self, $value, $field) = @_; |
|
63
|
|
|
|
|
|
|
|
|
64
|
14
|
100
|
|
|
|
42
|
return $value unless defined $value; |
|
65
|
|
|
|
|
|
|
|
|
66
|
11
|
100
|
100
|
|
|
82
|
if ($field eq 'UA' || $field eq 'Full-Version-List') { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
67
|
2
|
|
|
|
|
10
|
$value = HTTP::UserAgentClientHints::BrandVersion->new($value); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
elsif ($field =~ m!^(?:Platform|Arch|Bitness|Model|Full-Version)$!) { |
|
70
|
6
|
|
|
|
|
18
|
$value = HTTP::UserAgentClientHints::Util->strip_quote($value); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
elsif ($field eq 'Mobile') { |
|
73
|
2
|
|
|
|
|
7
|
$value =~ s/^\?//; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
11
|
|
|
|
|
59
|
return $value; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub new { |
|
80
|
3
|
|
|
3
|
1
|
2604
|
my ($class, $http_headers_obj) = @_; |
|
81
|
|
|
|
|
|
|
|
|
82
|
3
|
100
|
|
|
|
24
|
unless ($http_headers_obj->can('header')) { |
|
83
|
1
|
|
|
|
|
12
|
die q|Argument object:| . ref($http_headers_obj) . q| doesn't have "header" method to get HTTP header value.|; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
bless { |
|
87
|
2
|
|
|
|
|
9
|
_headers => $http_headers_obj, |
|
88
|
|
|
|
|
|
|
_value_raw => {}, |
|
89
|
|
|
|
|
|
|
_value => {}, |
|
90
|
|
|
|
|
|
|
}, $class; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub accept_ch { |
|
94
|
3
|
100
|
|
3
|
1
|
1975
|
return $FULL_ACCEPT_CH unless $_[1]; |
|
95
|
|
|
|
|
|
|
|
|
96
|
2
|
|
|
|
|
11
|
return _accept_ch(@_); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _accept_ch { |
|
100
|
4
|
|
|
4
|
|
32
|
my ($self, $excepts) = @_; |
|
101
|
|
|
|
|
|
|
|
|
102
|
4
|
|
100
|
|
|
31
|
$excepts ||= []; |
|
103
|
|
|
|
|
|
|
|
|
104
|
4
|
|
|
|
|
8
|
unshift @{$excepts}, 'Sec-CH-UA', 'Sec-CH-UA-Mobile', 'Sec-CH-UA-Platform'; # Default fields |
|
|
4
|
|
|
|
|
15
|
|
|
105
|
|
|
|
|
|
|
|
|
106
|
4
|
|
|
|
|
8
|
my @accept_ch; |
|
107
|
4
|
|
|
|
|
9
|
for my $field (@FIELDS) { |
|
108
|
36
|
|
|
|
|
69
|
my $f = $self->_as_http_header_key($field); |
|
109
|
36
|
100
|
|
|
|
62
|
next if grep { lc($f) eq lc($_) } @{$excepts}; |
|
|
135
|
|
|
|
|
288
|
|
|
|
36
|
|
|
|
|
60
|
|
|
110
|
21
|
|
|
|
|
44
|
push @accept_ch, $f; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
4
|
|
|
|
|
23
|
return join(', ', @accept_ch); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |