File Coverage

blib/lib/Net/WebSocket/PMCE/deflate/Client.pm
Criterion Covered Total %
statement 17 39 43.5
branch 2 16 12.5
condition n/a
subroutine 5 6 83.3
pod n/a
total 24 61 39.3


line stmt bran cond sub pod time code
1             package Net::WebSocket::PMCE::deflate::Client;
2              
3 1     1   57125 use strict;
  1         10  
  1         26  
4 1     1   4 use warnings;
  1         2  
  1         30  
5              
6             =encoding utf-8
7              
8             =head1 NAME
9              
10             Net::WebSocket::PMCE::deflate::Client - permessage-deflate for a client
11              
12             =head1 SYNOPSIS
13              
14             my $deflate = Net::WebSocket::PMCE::deflate::Server->new( %opts );
15              
16             #Send this to the server.
17             my $handshake = $deflate->create_handshake_object();
18              
19             #You’ll probably want Net::WebSocket::Handshake
20             #to do this for you, but just in case:
21             #$deflate->consume_parameters( @params_kv );
22              
23             #OPTIONAL: Inspect $deflate to be sure you’re happy with the setup
24             #that the client’s parameters allow.
25              
26             #...and now use this to send/receive messages.
27             my $data_obj = $deflate->create_data_object();
28              
29             =head1 DESCRIPTION
30              
31             See L for general information about
32             this class.
33              
34             =head1 METHODS
35              
36             =head2 I->consume_parameters( KEY1 => VALUE1, .. )
37              
38             Inherited from the base class. The alterations made in response
39             to the different parameters are:
40              
41             =over
42              
43             =item * - Sets the object’s
44             C flag.
45              
46             =item * - If the object’s
47             C flag is set, and if
48             we do *not* receive this flag from the peer, then we C.
49             This option is ignored otherwise.
50              
51             =item * - If given and less than the object’s
52             C option, then that option is reduced to the
53             new value.
54              
55             =item * - If given and less than the object’s
56             C option, then that option is reduced to the
57             new value. If given and B than the object’s
58             C option, then we C.
59              
60             =back
61              
62             =cut
63              
64 1         4 use parent qw(
65             Net::WebSocket::PMCE::deflate
66 1     1   209 );
  1         205  
67              
68             use constant {
69 1         268 _PEER_NO_CONTEXT_TAKEOVER_PARAM => 'server_no_context_takeover',
70             _LOCAL_NO_CONTEXT_TAKEOVER_PARAM => 'client_no_context_takeover',
71             _DEFLATE_MAX_WINDOW_BITS_PARAM => 'client_max_window_bits',
72             _INFLATE_MAX_WINDOW_BITS_PARAM => 'server_max_window_bits',
73              
74             _ENDPOINT_CLASS => 'Client',
75 1     1   44 };
  1         1  
76              
77             sub _create_extension_header_parts {
78 4     4   7 my ($self) = @_;
79              
80 4         12 my @parts = $self->SUPER::_create_extension_header_parts();
81              
82             #Let’s always advertise support for this feature.
83 4 100       10 if (!defined $self->{'deflate_max_window_bits'}) {
84 3         7 push @parts, _DEFLATE_MAX_WINDOW_BITS_PARAM() => undef;
85             }
86              
87 4         17 return @parts;
88             }
89              
90             sub _consume_extension_options {
91 0     0     my ($self, $opts_hr) = @_;
92              
93 0 0         if (exists $opts_hr->{'server_max_window_bits'}) {
94 0           $self->__validate_max_window_bits('server', $opts_hr->{'server_max_window_bits'});
95              
96 0 0         if ( $opts_hr->{'server_max_window_bits'} > $self->inflate_max_window_bits() ) {
97 0           die 'server_max_window_bits greater than client stipulated!';
98             }
99              
100 0           $self->{'inflate_max_window_bits'} = $opts_hr->{'server_max_window_bits'};
101 0           delete $opts_hr->{'server_max_window_bits'};
102             }
103              
104 0 0         if (exists $opts_hr->{'client_max_window_bits'}) {
105 0           $self->__validate_max_window_bits('client', $opts_hr->{'client_max_window_bits'});
106              
107 0           my $max = $self->deflate_max_window_bits();
108              
109 0 0         if ($opts_hr->{'client_max_window_bits'} < $max) {
110 0           $self->{'deflate_max_window_bits'} = $opts_hr->{'client_max_window_bits'};
111             }
112              
113             #If the server requested a greater client_max_window_bits than
114             #we gave, that’s no problem, but we’re just going to ignore it.
115              
116 0           delete $opts_hr->{'client_max_window_bits'};
117             }
118              
119 0 0         if (exists $opts_hr->{'client_no_context_takeover'}) {
120 0           $self->__validate_no_context_takeover( $opts_hr->{'client_no_context_takeover'} );
121              
122 0           $self->{'deflate_no_context_takeover'} = 1;
123              
124 0           delete $opts_hr->{'client_no_context_takeover'};
125             }
126              
127 0 0         if (exists $opts_hr->{'server_no_context_takeover'}) {
    0          
128 0           $self->__validate_no_context_takeover( $opts_hr->{'server_no_context_takeover'} );
129 0           delete $opts_hr->{'server_no_context_takeover'};
130             }
131             elsif ($self->{'inflate_no_context_takeover'}) {
132              
133             #The RFC doesn’t seem to have a problem with a server that
134             #neglects a client’s server_no_context_takeover request.
135              
136             #die 'server didn’t accept server_no_context_takeover';
137              
138 0           delete $self->{'inflate_no_context_takeover'};
139             }
140              
141 0           return;
142             }
143              
144             1;