| 1 | package Net::WebSocket::HTTP_R; | ||||||||||
| 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::HTTP_R - logic for HTTP::Request & HTTP::Response | ||||||||||
| 11 | |||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||
| 13 | |||||||||||
| 14 | Client: | ||||||||||
| 15 | |||||||||||
| 16 | my $resp = HTTP::Response->parse_string($http_response); | ||||||||||
| 17 | |||||||||||
| 18 | my $handshake = Net::WebSocket::Handshake::Client->new( .. ); | ||||||||||
| 19 | |||||||||||
| 20 | Net::WebSocket::HTTP_R::handshake_consume_response( $handshake, $resp ); | ||||||||||
| 21 | |||||||||||
| 22 | Server: | ||||||||||
| 23 | |||||||||||
| 24 | my $req = HTTP::Request->parse_string($http_request); | ||||||||||
| 25 | |||||||||||
| 26 | my $handshake = Net::WebSocket::Handshake::Server->new( .. ); | ||||||||||
| 27 | |||||||||||
| 28 | Net::WebSocket::HTTP_R::handshake_consume_request( $handshake, $req ); | ||||||||||
| 29 | |||||||||||
| 30 | =head1 DESCRIPTION | ||||||||||
| 31 | |||||||||||
| 32 | Net::WebSocket is agnostic as to which tools an implementor may use to parse | ||||||||||
| 33 | HTTP headers. CPAN offers a number of options for doing this, and different | ||||||||||
| 34 | applications may have varying reasons to prefer one or the other—or an | ||||||||||
| 35 | entirely different approach altogether. | ||||||||||
| 36 | |||||||||||
| 37 | This module provides convenient logic for the L<HTTP::Request> and | ||||||||||
| 38 | L<HTTP::Response> CPAN modules. Any implementation that uses one of these | ||||||||||
| 39 | modules (or a compatible implementation) can use Net::WebSocket::HTTP_R and | ||||||||||
| 40 | save a bit of time. | ||||||||||
| 41 | |||||||||||
| 42 | =cut | ||||||||||
| 43 | |||||||||||
| 44 | 1 | ▶ | sub handshake_consume_request { | ||||||||
|
Subroutine
handshake_consume_request: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 45 | 1 | my ($hsk, $req) = @_; | |||||||||
| 46 | |||||||||||
| 47 | 1 | $hsk->valid_protocol_or_die( $req->protocol() ); | |||||||||
| 48 | 1 | $hsk->valid_method_or_die( $req->method() ); | |||||||||
| 49 | |||||||||||
| 50 | 1 | return _handshake_consume_common($hsk, $req); | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 1 | ▶ | sub handshake_consume_response { | ||||||||
|
Subroutine
handshake_consume_response: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 54 | 1 | my ($hsk, $resp) = @_; | |||||||||
| 55 | |||||||||||
| 56 | 1 | $hsk->valid_status_or_die( $resp->code(), $resp->message() ); | |||||||||
| 57 | |||||||||||
| 58 | 1 | return _handshake_consume_common($hsk, $resp); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 2 | ▶ | sub _handshake_consume_common { | ||||||||
|
Subroutine
_handshake_consume_common: called CC=4 SCAR=14.1
| |||||||||||
| 62 | 2 | my ($hsk, $r_obj) = @_; | |||||||||
| 63 | |||||||||||
| 64 | 2 | my $hdrs_obj = $r_obj->headers(); | |||||||||
| 65 | |||||||||||
| 66 | 2 | my @hdrs; | |||||||||
| 67 | 2 | for my $hname ($hdrs_obj->header_field_names()) { | |||||||||
| 68 | 10 | my $value = $hdrs_obj->header($hname); | |||||||||
| 69 | 10 | ▶ | if ('ARRAY' eq ref $value) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | push @hdrs, $hname => $_ for @$value; | |||||||||
| 71 | } | ||||||||||
| 72 | else { | ||||||||||
| 73 | 10 | push @hdrs, $hname => $value; | |||||||||
| 74 | } | ||||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 2 | return $hsk->consume_headers(@hdrs); | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 1 | 1; | |||||||||