WebSocket/PMCE/deflate/Server.pm

filter: Statementstmt 88.1% 37 / 42 Branchbran 64.2% 9 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 79.7% 55 / 69 CC 11 SCAR 18.0
CC
11
Cov
81%
_consume_extension_options
9.2
_create_extension_header_parts
6.0
new
2.0
CRAP 6.1
« WebSocket/Endpoint.pm ↑ Summary WebSocket/PMCE/deflate/Client.pm »
1 package Net::WebSocket::PMCE::deflate::Server;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =encoding utf-8
7  
8 =head1 NAME
9  
10 Net::WebSocket::PMCE::deflate::Server - permessage-deflate for a server
11  
12 =head1 SYNOPSIS
13  
14 my $deflate = Net::WebSocket::PMCE::deflate::Server->new( %opts );
15  
16 #You’ll probably want Net::WebSocket::Handshake
17 #to do this for you, but just in case:
18 #$deflate->consume_parameters( @params_kv );
19  
20 #OPTIONAL: Inspect $deflate to be sure you’re happy with the setup
21 #that the client’s parameters allow.
22  
23 #Send this to the client.
24 my $handshake = $deflate->create_handshake_object();
25  
26 #...and now use this to send/receive messages.
27 my $data_obj = $deflate->create_data_object();
28  
29 =head1 DESCRIPTION
30  
31 The above should describe the workflow sufficiently.
32  
33 The optional “inspection” step is to ensure
34 that you’re satisfied with the compression parameters, which may be
35 different now from what you gave to the constructor.
36  
37 For example, if you do this:
38  
39 my $deflate = Net::WebSocket::PMCE::deflate::Server->new(
40 inflate_max_window_bits => 10,
41 );
42  
43 … and then this has no C<client_max_window_bits>:
44  
45 $deflate->consume_parameters( @extn_objs );
46  
47 … then that means the client doesn’t understand C<client_max_window_bits>,
48 which means we can’t send that parameter. When this happens, C<$deflate>
49 changes to return 15 rather than 10 from its C<inflate_max_window_bits()>
50 method.
51  
52 In general this should be fine, but if, for some reason, you want to
53 insist that the client compress with no more than 10 window bits,
54 then at this point you can fail the connection.
55  
56 =back
57  
58 =cut
59  
60 1 use parent qw(
61 Net::WebSocket::PMCE::deflate
62 1 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 use constant {
65 1 _ENDPOINT_CLASS => 'Server',
66 _PEER_NO_CONTEXT_TAKEOVER_PARAM => 'client_no_context_takeover',
67 _LOCAL_NO_CONTEXT_TAKEOVER_PARAM => 'server_no_context_takeover',
68 _DEFLATE_MAX_WINDOW_BITS_PARAM => 'server_max_window_bits',
69 _INFLATE_MAX_WINDOW_BITS_PARAM => 'client_max_window_bits',
70 1 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
71  
72 #----------------------------------------------------------------------
73  
74 #=head1 METHODS
75 #
76 #This inherits all methods from L<Net::WebSocket::PMCE::deflate>
77 #and also supplies the following:
78 #
79 #=head2 I<OBJ>->peer_supports_client_max_window_bits()
80 #
81 #Call this after C<consume_peer_extensions()> to ascertain whether the
82 #client indicated support for the C<client_max_window_bits> parameter.
83 #
84 #=cut
85 #
86 #sub peer_supports_client_max_window_bits {
87 # my ($self) = @_;
88 # return $self->{'_peer_supports_client_max_window_bits'};
89 #}
90  
91 #----------------------------------------------------------------------
92  
93 #Remove once legacy support goes.
94 sub new {
95 10 ▶ my ($class, @opts_kv) = @_;
Subroutine new: called CC=2 SCAR=7.0
Pod documented
96  
97 10 my $self = $class->SUPER::new(@opts_kv);
98  
99 6 ▶ $self->_warn_legacy() if $self->{'key'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"key"} 0 6 6
100  
101 6 return $self;
102 }
103  
104 =head2 I<OBJ>->consume_parameters( KEY1 => VALUE1, .. )
105  
106 Inherited from the base class. The alterations made in response
107 to the different parameters are:
108  
109 =over
110  
111 =item * <client_no_context_takeover> - Sets the object’s
112 C<inflate_no_context_takeover> flag.
113  
114 =item * <server_no_context_takeover> - Sets the object’s
115 C<deflate_no_context_takeover> flag.
116  
117 =item * <client_max_window_bits> - If given and less than the object’s
118 C<inflate_max_window_bits> option, then that option is reduced to the
119 new value.
120  
121 =item * <server_max_window_bits> - If given and less than the object’s
122 C<deflate_max_window_bits> option, then that option is reduced to the
123 new value.
124  
125 =back
126  
127 =cut
128  
129 sub _create_extension_header_parts {
130 0 ▶ my ($self) = @_;
Subroutine _create_extension_header_parts: not called CC=2 SCAR=17.9
131  
132 0 ▶ local $self->{'inflate_max_window_bits'} = undef if !$self->{'_peer_supports_client_max_window_bits'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_peer_supports_client_max_window_bits"} 0 0 0
133  
134 0 return $self->SUPER::_create_extension_header_parts();
135 }
136  
137 sub _consume_extension_options {
138 6 ▶ my ($self, $opts_hr) = @_;
Subroutine _consume_extension_options: called CC=9 SCAR=22.2
139  
140 6 for my $ept_opt ( [ client => 'inflate' ], [ server => 'deflate' ] ) {
141 12 my $mwb_opt = "$ept_opt->[0]_max_window_bits";
142  
143 12 ▶ if (exists $opts_hr->{$mwb_opt}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts_hr->{$mwb_opt}) 3 9 12
144 3 ▶ if ($ept_opt->[0] eq 'client') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ept_opt->[0] eq "client") 1 2 3
145 1 $self->{'_peer_supports_client_max_window_bits'} = 1;
146  
147 1 ▶ if (!defined $opts_hr->{$mwb_opt}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts_hr->{$mwb_opt}) 0 1 1
148 0 delete $opts_hr->{$mwb_opt};
149 0 next;
150 }
151 }
152  
153 3 my $self_opt = "$ept_opt->[1]_max_window_bits";
154 3 $self->__validate_max_window_bits($ept_opt->[0], $opts_hr->{$mwb_opt});
155  
156 3 ▶ my $max = $self->{$self_opt} || ( $self->VALID_MAX_WINDOW_BITS() )[-1];
Condition66%2/3
$self->{$self_opt} || ($self->VALID_MAX_WINDOW_BITS)[-1]
l!l&&r!l&&!r
210
MC/DC0%0/2
$self->{$self_opt} || ($self->VALID_MAX_WINDOW_BITS)[-1]
$self->{$self_opt} ($self->VALID_MAX_WINDOW_BITS)[-1]
Truth table66%2/3
A || B
A= $self->{$self_opt}B= ($self->VALID_MAX_WINDOW_BITS)[-1]
ABresult
1X1
011
000
157  
158 3 ▶ if ($opts_hr->{$mwb_opt} < $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts_hr->{$mwb_opt} < $max) 3 0 3
159 3 $self->{$self_opt} = $opts_hr->{$mwb_opt};
160 }
161  
162 #If the client requested a greater server_max_window_bits than
163 #we want, that’s no problem, but we’re just going to ignore it.
164  
165 3 delete $opts_hr->{$mwb_opt};
166 }
167 }
168  
169 6 for my $ept_opt ( [ client => 'inflate' ], [ server => 'deflate' ] ) {
170 12 my $nct_hdr = "$ept_opt->[0]_no_context_takeover";
171  
172 12 ▶ if (exists $opts_hr->{$nct_hdr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts_hr->{$nct_hdr}) 3 9 12
173 3 $self->__validate_no_context_takeover( $ept_opt->[0], $opts_hr->{$nct_hdr} );
174  
175 3 $self->{"$ept_opt->[1]_no_context_takeover"} = 1;
176  
177 3 delete $opts_hr->{$nct_hdr};
178 }
179 }
180  
181 6 return;
182 }
183  
184 1 1;
« WebSocket/Endpoint.pm ↑ Summary WebSocket/PMCE/deflate/Client.pm »