| 1 | package AnyEvent::HTTPD::HTTPConnection; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 12 | ▶ | use common::sense; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use AnyEvent::Handle; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use Object::Event; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use Time::Local; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use AnyEvent::HTTPD::Util; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 12 | ▶ | use Scalar::Util qw/weaken/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | our @ISA = qw/Object::Event/; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | AnyEvent::HTTPD::HTTPConnection - A simple HTTP connection for request and response handling | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | This class is a helper class for L<AnyEvent:HTTPD::HTTPServer> and L<AnyEvent::HTTPD>, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | it handles TCP reading and writing as well as parsing and serializing | ||||||||||||||||||||||||||||||||||||||||||
| 21 | http requests. | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | It has no public interface yet. | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | Copyright 2008-2011 Robin Redeker, all rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||
| 30 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 15 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 15 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 15 | ▶ | my $class = ref($this) || $this; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 15 | my $self = { @_ }; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 15 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | $self->{request_timeout} = 60 | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 15 | ▶ | unless defined $self->{request_timeout}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | $self->{hdl} = | ||||||||||||||||||||||||||||||||||||||||||
| 44 | AnyEvent::Handle->new ( | ||||||||||||||||||||||||||||||||||||||||||
| 45 | fh => $self->{fh}, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | on_eof => sub { $self->do_disconnect }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | ▶ | on_error => sub { $self->do_disconnect ("Error: $!") }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | ($self->{ssl} | ||||||||||||||||||||||||||||||||||||||||||
| 49 | ? (tls => "accept", tls_ctx => $self->{ssl}) | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 15 | ▶ | : ()), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 15 | $self->push_header_line; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 15 | return $self | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 7 | ▶ | sub error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 7 | my ($self, $code, $msg, $hdr, $content) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 7 | ▶ | if ($code !~ /^(1\d\d|204|304)$/o) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 7 | ▶ | unless (defined $content) { $content = "$code $msg\n" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 7 | $hdr->{'Content-Type'} = 'text/plain'; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 7 | $self->response ($code, $msg, $hdr, $content); | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 25 | ▶ | sub response_done { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
response_done: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 25 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 25 | ▶ | (delete $self->{transfer_cb})->() if $self->{transfer_cb}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | # sometimes a response might be written after connection is already dead: | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 25 | ▶ | return unless defined ($self->{hdl}) && !$self->{disconnected}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"hdl"} and not $self->{"disconnected"}
MC/DC0%0/2
defined $self->{"hdl"} and not $self->{"disconnected"}
defined $self->{"hdl"}
not $self->{"disconnected"}
Truth table33%1/3
A and not(B)
A= defined $self->{"hdl"}B= not $self->{"disconnected"}
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 25 | $self->{hdl}->on_drain; # clear any drain handlers | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 25 | ▶ | if ($self->{keep_alive}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 13 | $self->push_header_line; | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 12 | ▶ | $self->{hdl}->on_drain (sub { $self->do_disconnect }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 12 | our @DoW = qw(Sun Mon Tue Wed Thu Fri Sat); | |||||||||||||||||||||||||||||||||||||||||
| 88 | 12 | our @MoY = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 12 | our %MoY; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 12 | @MoY{@MoY} = (1..12); | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | # Taken from HTTP::Date module of LWP. | ||||||||||||||||||||||||||||||||||||||||||
| 93 | sub _time_to_http_date | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 25 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_time_to_http_date: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 25 | my $time = shift; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 25 | ▶ | $time = time unless defined $time; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 25 | my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime($time); | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 25 | sprintf("%s, %02d %s %04d %02d:%02d:%02d GMT", | |||||||||||||||||||||||||||||||||||||||||
| 101 | $DoW[$wday], | ||||||||||||||||||||||||||||||||||||||||||
| 102 | $mday, $MoY[$mon], $year + 1900, | ||||||||||||||||||||||||||||||||||||||||||
| 103 | $hour, $min, $sec); | ||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 25 | ▶ | sub response { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
response: called CC=14 SCAR=26.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 25 | my ($self, $code, $msg, $hdr, $content, $no_body) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 25 | ▶ | return if $self->{disconnected}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 25 | ▶ | return unless $self->{hdl}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 25 | my $res = "HTTP/1.0 $code $msg\015\012"; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 25 | ▶ | header_set ($hdr, 'Date' => _time_to_http_date time) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | unless header_exists ($hdr, 'Date'); | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 25 | ▶ | header_set ($hdr, 'Expires' => header_get ($hdr, 'Date')) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | unless header_exists ($hdr, 'Expires'); | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 25 | ▶ | header_set ($hdr, 'Cache-Control' => "max-age=0") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | unless header_exists ($hdr, 'Cache-Control'); | ||||||||||||||||||||||||||||||||||||||||||
| 119 | header_set ($hdr, 'Connection' => | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 25 | ▶ | ($self->{keep_alive} ? 'Keep-Alive' : 'close')); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 25 | ▶ | header_set ($hdr, 'Content-Length' => length "$content") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
header_exists($hdr, "Content-Length") or ref $content
MC/DC100%2/2
header_exists($hdr, "Content-Length") or ref $content
header_exists($hdr, "Content-Length")
ref $content
Truth table100%3/3
A or B
A= header_exists($hdr, "Content-Length")B= ref $content
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | unless header_exists ($hdr, 'Content-Length') | ||||||||||||||||||||||||||||||||||||||||||
| 124 | || ref $content; | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 25 | ▶ | unless (defined header_get ($hdr, 'Content-Length')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | # keep alive with no content length will NOT work. | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 2 | delete $self->{keep_alive}; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | header_set ($hdr, 'Connection' => 'close'); | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 25 | ▶ | while (my ($h, $v) = each %$hdr) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 148 | ▶ | next unless defined $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 145 | $res .= "$h: $v\015\012"; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 25 | $res .= "\015\012"; | |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 25 | ▶ | if ($no_body) { # for HEAD requests! | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 3 | $self->{hdl}->push_write ($res); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 3 | $self->response_done; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 22 | ▶ | if (ref ($content) eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | weaken $self; | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 5 | ▶ | my $chunk_cb = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=19.4
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 5 | my ($chunk) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 5 | ▶ | return 0 unless defined ($self) && defined ($self->{hdl}) && !$self->{disconnected}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $self and defined $self->{"hdl"} and not $self->{"disconnected"}
defined $self and defined $self->{"hdl"}
MC/DC0%0/3
defined $self and defined $self->{"hdl"} and not $self->{"disconnected"}
defined $self
defined $self->{"hdl"}
not $self->{"disconnected"}
Truth table25%1/4
A and B and not(C)
A= defined $selfB= defined $self->{"hdl"}C= not $self->{"disconnected"}
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 5 | delete $self->{transport_polled}; | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 5 | ▶ | if (defined ($chunk) && length ($chunk) > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $chunk and length $chunk > 0
MC/DC50%1/2
defined $chunk and length $chunk > 0
defined $chunk
length $chunk > 0
Truth table66%2/3
A and B
A= defined $chunkB= length $chunk > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 4 | $self->{hdl}->push_write ($chunk); | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | $self->response_done; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 5 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | $self->{transfer_cb} = $content; | |||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 5 | ▶ | $self->{hdl}->on_drain (sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.5
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 5 | ▶ | return unless $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 5 | ▶ | if (length $res) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | my $r = $res; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | undef $res; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | $chunk_cb->($r); | |||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | } elsif (not $self->{transport_polled}) { | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 4 | $self->{transport_polled} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 4 | ▶ | $self->{transfer_cb}->($chunk_cb) if $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | }); | |||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 21 | $res .= $content; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 21 | $self->{hdl}->push_write ($res); | |||||||||||||||||||||||||||||||||||||||||
| 184 | 21 | $self->response_done; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 10 | ▶ | sub _unquote { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unquote: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 10 | my ($str) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 10 | ▶ | if ($str =~ /^"(.*?)"$/o) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 8 | $str = $1; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 8 | my $obo = ''; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 8 | ▶ | while ($str =~ s/^(?:([^"]+)|\\(.))//so) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 8 | $obo .= $1; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 8 | $str = $obo; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | $str | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 10 | } | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 6 | ▶ | sub decode_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_part: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 6 | my ($self, $hdr, $cont) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 6 | $hdr = _parse_headers ($hdr); | |||||||||||||||||||||||||||||||||||||||||
| 205 | 6 | ▶ | if ($hdr->{'content-disposition'} =~ /form-data|attachment/o) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 6 | my ($dat, @pars) = split /\s*;\s*/o, $hdr->{'content-disposition'}; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 6 | my @params; | |||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | my %p; | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 6 | my @res; | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 6 | for my $name_para (@pars) { | |||||||||||||||||||||||||||||||||||||||||
| 214 | 8 | my ($name, $par) = split /\s*=\s*/o, $name_para; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 8 | ▶ | if ($par =~ /^".*"$/o) { $par = _unquote ($par) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 8 | $p{$name} = $par; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 6 | my ($ctype, $bound) = _content_type_boundary ($hdr->{'content-type'}); | |||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 6 | ▶ | if ($ctype eq 'multipart/mixed') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | my $parts = $self->decode_multipart ($cont, $bound); | |||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | for my $sp (keys %$parts) { | |||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | for (@{$parts->{$sp}}) { | |||||||||||||||||||||||||||||||||||||||||
| 225 | 2 | push @res, [$p{name}, @$_]; | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 5 | push @res, [$p{name}, $cont, $hdr->{'content-type'}, $p{filename}]; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | return @res | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 6 | } | |||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | (); | |||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 2 | ▶ | sub decode_multipart { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_multipart: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 2 | my ($self, $cont, $boundary) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 2 | my $parts = {}; | |||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | ▶ | while ($cont =~ s/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | ^--\Q$boundary\E \015?\012 | ||||||||||||||||||||||||||||||||||||||||||
| 246 | ((?:[^\015\012]+\015\012)* ) \015?\012 | ||||||||||||||||||||||||||||||||||||||||||
| 247 | (.*?) \015?\012 | ||||||||||||||||||||||||||||||||||||||||||
| 248 | (--\Q$boundary\E (--)? \015?\012) | ||||||||||||||||||||||||||||||||||||||||||
| 249 | /\3/xs) { | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 6 | my ($h, $c, $e) = ($1, $2, $4); | |||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 6 | ▶ | if (my (@p) = $self->decode_part ($h, $c)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 6 | for my $part (@p) { | |||||||||||||||||||||||||||||||||||||||||
| 254 | 7 | push @{$parts->{$part->[0]}}, [$part->[1], $part->[2], $part->[3]]; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 6 | ▶ | last if $e eq '--'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 2 | return $parts; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | # application/x-www-form-urlencoded | ||||||||||||||||||||||||||||||||||||||||||
| 265 | # | ||||||||||||||||||||||||||||||||||||||||||
| 266 | # This is the default content type. Forms submitted with this content type must | ||||||||||||||||||||||||||||||||||||||||||
| 267 | # be encoded as follows: | ||||||||||||||||||||||||||||||||||||||||||
| 268 | # | ||||||||||||||||||||||||||||||||||||||||||
| 269 | # 1. Control names and values are escaped. Space characters are replaced by | ||||||||||||||||||||||||||||||||||||||||||
| 270 | # `+', and then reserved characters are escaped as described in [RFC1738], | ||||||||||||||||||||||||||||||||||||||||||
| 271 | # section 2.2: Non-alphanumeric characters are replaced by `%HH', a percent | ||||||||||||||||||||||||||||||||||||||||||
| 272 | # sign and two hexadecimal digits representing the ASCII code of the | ||||||||||||||||||||||||||||||||||||||||||
| 273 | # character. Line breaks are represented as "CR LF" pairs (i.e., `%0D%0A'). | ||||||||||||||||||||||||||||||||||||||||||
| 274 | # | ||||||||||||||||||||||||||||||||||||||||||
| 275 | # 2. The control names/values are listed in the order they appear in the | ||||||||||||||||||||||||||||||||||||||||||
| 276 | # document. The name is separated from the value by `=' and name/value pairs | ||||||||||||||||||||||||||||||||||||||||||
| 277 | # are separated from each other by `&'. | ||||||||||||||||||||||||||||||||||||||||||
| 278 | # | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 24 | ▶ | sub _content_type_boundary { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_content_type_boundary: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 24 | my ($ctype) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 24 | my ($c, @params) = split /\s*[;,]\s*/o, $ctype; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 24 | my $bound; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 24 | for (@params) { | |||||||||||||||||||||||||||||||||||||||||
| 285 | 4 | ▶ | if (/^\s*boundary\s*=\s*(.*?)\s*$/o) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 2 | $bound = _unquote ($1); | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 24 | ($c, $bound) | |||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 18 | ▶ | sub handle_request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_request: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 18 | my ($self, $method, $uri, $hdr, $cont) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 18 | $self->{keep_alive} = ($hdr->{connection} =~ /keep-alive/io); | |||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 18 | my ($ctype, $bound) = _content_type_boundary ($hdr->{'content-type'}); | |||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 18 | ▶ | if ($ctype eq 'multipart/form-data') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | $cont = $self->decode_multipart ($cont, $bound); | |||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | } elsif ($ctype =~ /x-www-form-urlencoded/o) { | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | $cont = parse_urlencoded ($cont); | |||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 18 | $self->event (request => $method, $uri, $hdr, $cont); | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | # loosely adopted from AnyEvent::HTTP: | ||||||||||||||||||||||||||||||||||||||||||
| 310 | 24 | ▶ | sub _parse_headers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_headers: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 24 | my ($header) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 24 | my $hdr; | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 24 | $header =~ y/\015//d; | |||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 24 | ▶ | while ($header =~ /\G | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | ([^:\000-\037]+): | ||||||||||||||||||||||||||||||||||||||||||
| 318 | [\011\040]* | ||||||||||||||||||||||||||||||||||||||||||
| 319 | ( (?: [^\012]+ | \012 [\011\040] )* ) | ||||||||||||||||||||||||||||||||||||||||||
| 320 | \012 | ||||||||||||||||||||||||||||||||||||||||||
| 321 | /sgcxo) { | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 49 | $hdr->{lc $1} .= ",$2" | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 24 | ▶ | return undef unless $header =~ /\G$/sgxo; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 24 | for (keys %$hdr) { | |||||||||||||||||||||||||||||||||||||||||
| 329 | 49 | substr $hdr->{$_}, 0, 1, ''; | |||||||||||||||||||||||||||||||||||||||||
| 330 | # remove folding: | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 49 | $hdr->{$_} =~ s/\012([\011\040])/$1/sgo; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | $hdr | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 24 | } | |||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 18 | ▶ | sub push_header { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
push_header: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 18 | my ($self, $hdl) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | $self->{hdl}->unshift_read (line => | ||||||||||||||||||||||||||||||||||||||||||
| 341 | qr{(?<![^\012])\015?\012}o, | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 18 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 18 | my ($hdl, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 18 | my $hdr = _parse_headers ($data); | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 18 | ▶ | unless (defined $hdr) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | $self->error (599 => "garbled headers"); | |||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | 18 | push @{$self->{last_header}}, $hdr; | |||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 18 | ▶ | if (defined $hdr->{'content-length'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 3 | ▶ | $self->{hdl}->unshift_read (chunk => $hdr->{'content-length'}, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 3 | my ($hdl, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 355 | 3 | $self->handle_request (@{$self->{last_header}}, $data); | |||||||||||||||||||||||||||||||||||||||||
| 356 | 3 | }); | |||||||||||||||||||||||||||||||||||||||||
| 357 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 15 | $self->handle_request (@{$self->{last_header}}); | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 18 | ); | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 29 | ▶ | sub push_header_line { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
push_header_line: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 29 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 29 | ▶ | return if $self->{disconnected}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 29 | weaken $self; | |||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | $self->{req_timeout} = | ||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | AnyEvent->timer (after => $self->{request_timeout}, cb => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | return unless defined $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | $self->do_disconnect ("request timeout ($self->{request_timeout})"); | |||||||||||||||||||||||||||||||||||||||||
| 376 | 29 | }); | |||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 26 | ▶ | $self->{hdl}->push_read (line => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 26 | my ($hdl, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 380 | 26 | ▶ | return unless defined $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 26 | delete $self->{req_timeout}; | |||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 26 | ▶ | if ($line =~ /(\S+) \040 (\S+) \040 HTTP\/(\d+)\.(\d+)/xso) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 20 | my ($meth, $url, $vm, $vi) = ($1, $2, $3, $4); | |||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 20 | ▶ | if (not grep { $meth eq $_ } @{ $self->{allowed_methods} }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | $self->error (501, "not implemented", | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 2 | { Allow => join(",", @{ $self->{allowed_methods} })}); | |||||||||||||||||||||||||||||||||||||||||
| 390 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 18 | ▶ | if ($vm >= 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | $self->error (506, "http protocol version not supported"); | |||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 18 | $self->{last_header} = [$meth, $url]; | |||||||||||||||||||||||||||||||||||||||||
| 399 | 18 | $self->push_header; | |||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | } elsif ($line eq '') { | ||||||||||||||||||||||||||||||||||||||||||
| 402 | # ignore empty lines before requests, this prevents | ||||||||||||||||||||||||||||||||||||||||||
| 403 | # browser bugs w.r.t. keep-alive (according to marc lehmann). | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 1 | $self->push_header_line; | |||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 5 | $self->error (400 => 'bad request'); | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 29 | }); | |||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | 14 | ▶ | sub do_disconnect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_disconnect: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 14 | my ($self, $err) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 14 | ▶ | return if $self->{disconnected}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 12 | $self->{disconnected} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 418 | 12 | ▶ | $self->{transfer_cb}->() if $self->{transfer_cb}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 12 | delete $self->{transfer_cb}; | |||||||||||||||||||||||||||||||||||||||||
| 420 | 12 | delete $self->{req_timeout}; | |||||||||||||||||||||||||||||||||||||||||
| 421 | 12 | $self->event ('disconnect', $err); | |||||||||||||||||||||||||||||||||||||||||
| 422 | 12 | shutdown $self->{hdl}->{fh}, 1; | |||||||||||||||||||||||||||||||||||||||||
| 423 | 12 | ▶ | $self->{hdl}->on_read (sub { }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 12 | $self->{hdl}->on_eof (undef); | |||||||||||||||||||||||||||||||||||||||||
| 425 | 12 | my $timer; | |||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | $timer = AE::timer 2, 0, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | undef $timer; | |||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | delete $self->{hdl}; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 12 | }; | |||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||