| 1 | package Net::WebSocket::HTTP; | ||||||||||
| 2 | |||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 6 | ▶ | use Call::Context (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 6 | ▶ | use Net::WebSocket::X (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | =encoding utf-8 | ||||||||||
| 11 | |||||||||||
| 12 | =head1 NAME | ||||||||||
| 13 | |||||||||||
| 14 | Net::WebSocket::HTTP - HTTP utilities for Net::WebSocket | ||||||||||
| 15 | |||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||
| 17 | |||||||||||
| 18 | @tokens = Net::WebSocket::HTTP::split_tokens($tokens_str); | ||||||||||
| 19 | |||||||||||
| 20 | =head1 FUNCTIONS | ||||||||||
| 21 | |||||||||||
| 22 | =head2 @tokens = split_tokens( TOKENS_STR ) | ||||||||||
| 23 | |||||||||||
| 24 | A parser for the C<1#token> format as defined in L<RFC 2616|https://tools.ietf.org/html/rfc2616>. (C<1#> and C<token> are defined independently of each other.) | ||||||||||
| 25 | |||||||||||
| 26 | Returns a list of the HTTP tokens in TOKENS_STR. Throws an exception | ||||||||||
| 27 | if any of the tokens is invalid as per the RFC’s C<token> definition. | ||||||||||
| 28 | |||||||||||
| 29 | =cut | ||||||||||
| 30 | |||||||||||
| 31 | #Would this be useful to publish separately? It seemed so at one point, | ||||||||||
| 32 | #but “#1token” doesn’t appear in the HTTP RFC. | ||||||||||
| 33 | 38 | ▶ | sub split_tokens { | ||||||||
|
Subroutine
split_tokens: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 34 | 38 | my ($value) = @_; | |||||||||
| 35 | |||||||||||
| 36 | 38 | Call::Context::must_be_list(); | |||||||||
| 37 | |||||||||||
| 38 | 37 | $value =~ s<\A[ \t]+><>; | |||||||||
| 39 | 37 | $value =~ s<[ \t]+\z><>; | |||||||||
| 40 | |||||||||||
| 41 | 37 | my @tokens; | |||||||||
| 42 | 37 | for my $p ( split m<[ \t]*,[ \t]*>, $value ) { | |||||||||
| 43 | 41 | ▶ | if ($p =~ tr~()<>@,;:\\"/[]?={} \t~~) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 16 | die Net::WebSocket::X->create('BadToken', $p); | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 25 | push @tokens, $p; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 21 | return @tokens; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 6 | 1; | |||||||||