lib/HTTP/Promise/Headers/ExpectCT.pm

filter: Statementstmt 100% 44 / 44 Branchbran 66.6% 8 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 14 / 14 Podpod 100% 7 / 7 totaltotal 91.4% 75 / 82 CC 9 SCAR 13.1
CC
9
Cov
92%
init
8.1
report_uri
2.1
BEGIN
1.0
CRAP 3.7
« lib/HTTP/Promise/Headers/Accept.pm ↑ Summary blib/lib/HTTP/Promise/Headers/ContentSecurityPolicy.pm »
1 ##----------------------------------------------------------------------------
2 ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Headers/ExpectCT.pm
3 ## Version v0.1.0
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/05/08
7 ## Modified 2022/05/08
8 ## All rights reserved.
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package HTTP::Promise::Headers::ExpectCT;
15 BEGIN
16 {
17 3 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶ warnings::register_categories( 'HTTP::Promise' );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶ use parent qw( HTTP::Promise::Headers::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 our $VERSION = 'v0.1.0';
22 };
23  
24 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 sub init
28 {
29 4 ▶ my $self = shift( @_ );
Subroutine init: called CC=8 SCAR=20.9
Pod documented
30 4 $self->{params} = [];
31 4 $self->{properties} = {};
32 4 $self->{_needs_quotes} = { 'report-uri' => 1 };
33 # Works like HTTP::Promise::Headers::CacheControl
34 4 ▶ @_ = () if( @_ == 1 && $self->_is_a( $_[0] => 'Module::Generic::Null' ) );
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and $self->_is_a($_[0], "Module::Generic::Null") 0 4 4
Condition66%2/3
@_ == 1 and $self->_is_a($_[0], "Module::Generic::Null")
!ll&&!rl&&r
130
MC/DC0%0/2
@_ == 1 and $self->_is_a($_[0], "Module::Generic::Null")
@_ == 1 $self->_is_a($_[0], "Module::Generic::Null")
Truth table66%2/3
A and B
A= @_ == 1B= $self->_is_a($_[0], "Module::Generic::Null")
ABresult
0X0
100
111
35 4 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 1 4
36 {
37 3 my $this = shift( @_ );
38 3 ▶ my $ref = $self->_is_array( $this ) ? $this : [split( /[[:blank:]\h]*\,[[:blank:]\h]*/, "$this" )];
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($this) ? : 0 3 3
39 3 my $params = $self->params;
40 3 my $props = $self->properties;
41 3 foreach my $pair ( @$ref )
42 {
43 9 my( $prop, $val ) = split( /=/, $pair, 2 );
44 9 ▶ $val =~ s/^"|(?<!\\)"$//g if( defined( $val ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 6 3 9
45 9 $props->{ $prop } = $val;
46 9 $params->push( $prop );
47 }
48 }
49 4 $self->{_init_strict_use_sub} = 1;
50 4 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 4 4
51 4 $self->_field_name( 'Expect-CT' );
52 4 return( $self );
53 }
54  
55 5 ▶sub as_string { return( shift->_set_get_properties_as_string ); }
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
56  
57 5 ▶sub enforce { return( shift->_set_get_property_boolean( 'enforce', @_ ) ); }
Subroutine enforce: called CC=1 SCAR=0.0
Pod documented
58  
59 5 ▶sub max_age { return( shift->_set_get_property_number( 'max-age', @_ ) ); }
Subroutine max_age: called CC=1 SCAR=0.0
Pod documented
60  
61 23 ▶sub params { return( shift->_set_get_array_as_object( 'params', @_ ) ); }
Subroutine params: called CC=1 SCAR=0.0
Pod documented
62  
63 23 ▶sub properties { return( shift->_set_get_hash_as_mix_object( 'properties', @_ ) ); }
Subroutine properties: called CC=1 SCAR=0.0
Pod documented
64  
65 5 ▶sub report_uri { return( shift->_set_get_property_value( 'report-uri', @_, ( @_ > 1 ? { needs_quotes => 1 } : () ) ) ); }
Subroutine report_uri: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 5 5
66  
67 5 ▶sub _needs_quotes { return( shift->_set_get_hash_as_mix_object( '_needs_quotes', @_ ) ); }
Subroutine _needs_quotes: called CC=1 SCAR=0.0
68  
69 3 1;
70 # NOTE: POD
71 __END__
72  
73 =encoding utf-8
74  
75 =head1 NAME
76  
77 HTTP::Promise::Headers::ExpectCT - Expect-CT Header Field
78  
79 =head1 SYNOPSIS
80  
81 use HTTP::Promise::Headers::ExpectCT;
82 my $expect = HTTP::Promise::Headers::ExpectCT->new ||
83 die( HTTP::Promise::Headers::ExpectCT->error, "\n" );
84 $h->max_age(86400);
85 $h->report_uri( 'https://foo.example.com/report' );
86 $h->enforce(1);
87  
88 =head1 VERSION
89  
90 v0.1.0
91  
92 =head1 DESCRIPTION
93  
94 The following is an extract from Mozilla documentation.
95  
96 The C<Expect-CT> header lets sites opt in to reporting and/or enforcement of Certificate Transparency requirements, to prevent the use of misissued certificates for that site from going unnoticed.
97  
98 For example:
99  
100 Expect-CT: max-age=86400, enforce, report-uri="https://foo.example.com/report"
101  
102 =head1 METHODS
103  
104 =head2 as_string
105  
106 Returns a string representation of the C<Expect-CT> object.
107  
108 =head2 enforce
109  
110 This is optional.
111  
112 This is a boolean property and takes a true or false value. If true, the property is set, and if false it is removed.
113  
114 Signals to the user agent that compliance with the Certificate Transparency policy should be enforced (rather than only reporting compliance) and that the user agent should refuse future connections that violate its Certificate Transparency policy.
115  
116 =head2 max_age
117  
118 The number of seconds after reception of the Expect-CT header field during which the user agent should regard the host of the received message as a known Expect-CT host.
119  
120 =head2 params
121  
122 Returns the L<array object|Module::Generic::Array> used by this header field object containing all the properties set.
123  
124 =head2 properties
125  
126 Returns the L<hash object|Module::Generic::hash> used as a repository of properties.
127  
128 =head2 report_uri
129  
130 This is optional.
131  
132 This takes an URI as a value. The URI where the user agent should report C<Expect-CT> failures.
133  
134 =head1 THREAD-SAFETY
135  
136 This module is thread-safe for all operations, as it operates on per-object state and uses thread-safe external libraries.
137  
138 =head1 AUTHOR
139  
140 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
141  
142 =head1 SEE ALSO
143  
144 See also L<rfc draft|https://tools.ietf.org/html/draft-ietf-httpbis-expect-ct-08> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect-CT>
145  
146 L<HTTP::Promise>, L<HTTP::Promise::Request>, L<HTTP::Promise::Response>, L<HTTP::Promise::Message>, L<HTTP::Promise::Entity>, L<HTTP::Promise::Headers>, L<HTTP::Promise::Body>, L<HTTP::Promise::Body::Form>, L<HTTP::Promise::Body::Form::Data>, L<HTTP::Promise::Body::Form::Field>, L<HTTP::Promise::Status>, L<HTTP::Promise::MIME>, L<HTTP::Promise::Parser>, L<HTTP::Promise::IO>, L<HTTP::Promise::Stream>, L<HTTP::Promise::Exception>
147  
148 =head1 COPYRIGHT & LICENSE
149  
150 Copyright(c) 2022 DEGUEST Pte. Ltd.
151  
152 All rights reserved.
153  
154 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
155  
156 =cut
« lib/HTTP/Promise/Headers/Accept.pm ↑ Summary blib/lib/HTTP/Promise/Headers/ContentSecurityPolicy.pm »