Skip to content

Commit 63fd496

Browse files
committed
Adding WebSocket (ws) URI
1 parent 7accc80 commit 63fd496

File tree

5 files changed

+205
-0
lines changed

5 files changed

+205
-0
lines changed

dist.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ stopword = Miyagawa
142142
stopword = OIDs
143143
stopword = OpenLDAP
144144
stopword = Punycode
145+
stopword = WebSocket
145146
stopword = relativize
146147
stopword = Tatsuhiko
147148
stopword = TCP

lib/URI.pm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,18 @@ separated by dots. A C<URI> object belonging to this namespace has an
12231223
additional method called $uri->oid that can be used to get/set the oid
12241224
value. In a list context, oid numbers are returned as separate elements.
12251225
1226+
=item B<ws>:
1227+
1228+
The <ws> URI scheme is specified in L<RFC 6455|http://tools.ietf.org/html/rfc6455>.
1229+
The C<WebSocket> Protocol enables two-way communication between a client
1230+
running untrusted code in a controlled environment to a remote host
1231+
that has opted-in to communications from that code.
1232+
1233+
=item B<wss>:
1234+
1235+
The I<wss> URI scheme is specified in L<RFC 6455|http://tools.ietf.org/html/rfc6455> as well.
1236+
The scheme is used to reference C<WebSocket> servers through SSL connections.
1237+
12261238
=back
12271239
12281240
=head1 CONFIGURATION VARIABLES

lib/URI/ws.pm

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package URI::ws;
2+
3+
use strict;
4+
use warnings;
5+
6+
our $VERSION = '5.33';
7+
8+
use parent 'URI::http';
9+
10+
1;
11+
__END__
12+
13+
=head1 NAME
14+
15+
URI::ws - URI scheme for WebSocket Identifiers
16+
17+
=head1 VERSION
18+
19+
Version 5.20
20+
21+
=head1 SYNOPSIS
22+
23+
use URI::ws;
24+
25+
my $uri = URI->new('ws://example.com/');
26+
27+
=head1 DESCRIPTION
28+
29+
This module implements the C<ws:> URI scheme defined in L<RFC 6455|http://tools.ietf.org/html/rfc6455>.
30+
31+
=head1 SUBROUTINES/METHODS
32+
33+
This module inherits the behaviour of L<URI::http|URI::http>.
34+
35+
=head1 DIAGNOSTICS
36+
37+
See L<URI|URI>
38+
39+
=head1 CONFIGURATION AND ENVIRONMENT
40+
41+
See L<URI|URI#CONFIGURATION-VARIABLES> and L<URI|URI#ENVIRONMENT-VARIABLES>
42+
43+
=head1 DEPENDENCIES
44+
45+
None
46+
47+
=head1 INCOMPATIBILITIES
48+
49+
None reported
50+
51+
=head1 BUGS AND LIMITATIONS
52+
53+
See L<URI|URI#BUGS>
54+
55+
=head1 SEE ALSO
56+
57+
L<RFC 3507|http://tools.ietf.org/html/rfc3507>
58+
59+
=head1 AUTHOR
60+
61+
David Dick, C<< <ddick at cpan.org> >>
62+
63+
=head1 LICENSE AND COPYRIGHT
64+
65+
Copyright 2016 David Dick.
66+
67+
This program is free software; you can redistribute it and/or modify it
68+
under the terms of either: the GNU General Public License as published
69+
by the Free Software Foundation; or the Artistic License.
70+
71+
See L<http://dev.perl.org/licenses/> for more information.

lib/URI/wss.pm

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package URI::wss;
2+
3+
use strict;
4+
use warnings;
5+
6+
our $VERSION = '5.33';
7+
8+
use parent 'URI::https';
9+
10+
1;
11+
__END__
12+
13+
=head1 NAME
14+
15+
URI::wss - URI scheme for WebSocket Identifiers
16+
17+
=head1 VERSION
18+
19+
Version 5.20
20+
21+
=head1 SYNOPSIS
22+
23+
use URI::wss;
24+
25+
my $uri = URI->new('wss://example.com/');
26+
27+
=head1 DESCRIPTION
28+
29+
This module implements the C<wss:> URI scheme defined in L<RFC 6455|http://tools.ietf.org/html/rfc6455>.
30+
31+
=head1 SUBROUTINES/METHODS
32+
33+
This module inherits the behaviour of L<URI::https|URI::https>.
34+
35+
=head1 DIAGNOSTICS
36+
37+
See L<URI|URI>
38+
39+
=head1 CONFIGURATION AND ENVIRONMENT
40+
41+
See L<URI|URI#CONFIGURATION-VARIABLES> and L<URI|URI#ENVIRONMENT-VARIABLES>
42+
43+
=head1 DEPENDENCIES
44+
45+
None
46+
47+
=head1 INCOMPATIBILITIES
48+
49+
None reported
50+
51+
=head1 BUGS AND LIMITATIONS
52+
53+
See L<URI|URI#BUGS>
54+
55+
=head1 SEE ALSO
56+
57+
L<RFC 3507|http://tools.ietf.org/html/rfc3507>
58+
59+
=head1 AUTHOR
60+
61+
David Dick, C<< <ddick at cpan.org> >>
62+
63+
=head1 LICENSE AND COPYRIGHT
64+
65+
Copyright 2016 David Dick.
66+
67+
This program is free software; you can redistribute it and/or modify it
68+
under the terms of either: the GNU General Public License as published
69+
by the Free Software Foundation; or the Artistic License.
70+
71+
See L<http://dev.perl.org/licenses/> for more information.

t/ws.t

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use strict;
2+
use warnings;
3+
4+
use Test::More tests => 16;
5+
6+
use URI ();
7+
8+
my $u = URI->new("<ws://www.example.com/path?q=fôo>");
9+
10+
#print "$u\n";
11+
is($u, "ws://www.example.com/path?q=f%F4o");
12+
13+
is($u->port, 80);
14+
15+
# play with port
16+
my $old = $u->port(8080);
17+
ok($old == 80 && $u eq "ws://www.example.com:8080/path?q=f%F4o");
18+
19+
$u->port(80);
20+
is($u, "ws://www.example.com:80/path?q=f%F4o");
21+
22+
$u->port("");
23+
ok($u eq "ws://www.example.com:/path?q=f%F4o" && $u->port == 80);
24+
25+
$u->port(undef);
26+
is($u, "ws://www.example.com/path?q=f%F4o");
27+
28+
my @q = $u->query_form;
29+
is_deeply(\@q, ["q", "fôo"]);
30+
31+
$u->query_form(foo => "bar", bar => "baz");
32+
is($u->query, "foo=bar&bar=baz");
33+
34+
is($u->host, "www.example.com");
35+
36+
is($u->path, "/path");
37+
38+
ok(!$u->secure);
39+
40+
$u->scheme("wss");
41+
is($u->port, 443);
42+
43+
is($u, "wss://www.example.com/path?foo=bar&bar=baz");
44+
45+
ok($u->secure);
46+
47+
$u = URI->new("ws://%65%78%61%6d%70%6c%65%2e%63%6f%6d/%70%75%62/%61/%32%30%30%31/%30%38/%32%37/%62%6a%6f%72%6e%73%74%61%64%2e%68%74%6d%6c");
48+
is($u->canonical, "ws://example.com/pub/a/2001/08/27/bjornstad.html");
49+
50+
ok($u->has_recognized_scheme);

0 commit comments

Comments
 (0)