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/Defragmenter.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 =cut
57  
58 1 ▶use parent qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
59 Net::WebSocket::PMCE::deflate
60 1 );
61  
62 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
63 1 _ENDPOINT_CLASS => 'Server',
64 _PEER_NO_CONTEXT_TAKEOVER_PARAM => 'client_no_context_takeover',
65 _LOCAL_NO_CONTEXT_TAKEOVER_PARAM => 'server_no_context_takeover',
66 _DEFLATE_MAX_WINDOW_BITS_PARAM => 'server_max_window_bits',
67 _INFLATE_MAX_WINDOW_BITS_PARAM => 'client_max_window_bits',
68 1 };
69  
70 #----------------------------------------------------------------------
71  
72 #=head1 METHODS
73 #
74 #This inherits all methods from L<Net::WebSocket::PMCE::deflate>
75 #and also supplies the following:
76 #
77 #=head2 I<OBJ>->peer_supports_client_max_window_bits()
78 #
79 #Call this after C<consume_peer_extensions()> to ascertain whether the
80 #client indicated support for the C<client_max_window_bits> parameter.
81 #
82 #=cut
83 #
84 #sub peer_supports_client_max_window_bits {
85 # my ($self) = @_;
86 # return $self->{'_peer_supports_client_max_window_bits'};
87 #}
88  
89 #----------------------------------------------------------------------
90  
91 #Remove once legacy support goes.
92 10 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
93 10 my ($class, @opts_kv) = @_;
94  
95 10 my $self = $class->SUPER::new(@opts_kv);
96  
97 6 ▶ $self->_warn_legacy() if $self->{'key'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"key"} 0 6 6
98  
99 6 return $self;
100 }
101  
102 =head2 I<OBJ>->consume_parameters( KEY1 => VALUE1, .. )
103  
104 Inherited from the base class. The alterations made in response
105 to the different parameters are:
106  
107 =over
108  
109 =item * <client_no_context_takeover> - Sets the object’s
110 C<inflate_no_context_takeover> flag.
111  
112 =item * <server_no_context_takeover> - Sets the object’s
113 C<deflate_no_context_takeover> flag.
114  
115 =item * <client_max_window_bits> - If given and less than the object’s
116 C<inflate_max_window_bits> option, then that option is reduced to the
117 new value.
118  
119 =item * <server_max_window_bits> - If given and less than the object’s
120 C<deflate_max_window_bits> option, then that option is reduced to the
121 new value.
122  
123 =back
124  
125 =cut
126  
127 0 ▶sub _create_extension_header_parts {
Subroutine _create_extension_header_parts: not called CC=2 SCAR=17.9
128 0 my ($self) = @_;
129  
130 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
131  
132 0 return $self->SUPER::_create_extension_header_parts();
133 }
134  
135 6 ▶sub _consume_extension_options {
Subroutine _consume_extension_options: called CC=9 SCAR=22.2
136 6 my ($self, $opts_hr) = @_;
137  
138 6 for my $ept_opt ( [ client => 'inflate' ], [ server => 'deflate' ] ) {
139 12 my $mwb_opt = "$ept_opt->[0]_max_window_bits";
140  
141 12 ▶ if (exists $opts_hr->{$mwb_opt}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts_hr->{$mwb_opt}) 3 9 12
142 3 ▶ if ($ept_opt->[0] eq 'client') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ept_opt->[0] eq "client") 1 2 3
143 1 $self->{'_peer_supports_client_max_window_bits'} = 1;
144  
145 1 ▶ if (!defined $opts_hr->{$mwb_opt}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts_hr->{$mwb_opt}) 0 1 1
146 0 delete $opts_hr->{$mwb_opt};
147 0 next;
148 }
149 }
150  
151 3 my $self_opt = "$ept_opt->[1]_max_window_bits";
152 3 $self->__validate_max_window_bits($ept_opt->[0], $opts_hr->{$mwb_opt});
153  
154 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
155  
156 3 ▶ if ($opts_hr->{$mwb_opt} < $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts_hr->{$mwb_opt} < $max) 3 0 3
157 3 $self->{$self_opt} = $opts_hr->{$mwb_opt};
158 }
159  
160 #If the client requested a greater server_max_window_bits than
161 #we want, that’s no problem, but we’re just going to ignore it.
162  
163 3 delete $opts_hr->{$mwb_opt};
164 }
165 }
166  
167 6 for my $ept_opt ( [ client => 'inflate' ], [ server => 'deflate' ] ) {
168 12 my $nct_hdr = "$ept_opt->[0]_no_context_takeover";
169  
170 12 ▶ if (exists $opts_hr->{$nct_hdr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts_hr->{$nct_hdr}) 3 9 12
171 3 $self->__validate_no_context_takeover( $ept_opt->[0], $opts_hr->{$nct_hdr} );
172  
173 3 $self->{"$ept_opt->[1]_no_context_takeover"} = 1;
174  
175 3 delete $opts_hr->{$nct_hdr};
176 }
177 }
178  
179 6 return;
180 }
181  
182 1 1;
« WebSocket/Defragmenter.pm ↑ Summary WebSocket/PMCE/deflate/Client.pm »