line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Furl::PSGI::HTTP; |
2
|
|
|
|
|
|
|
$Furl::PSGI::HTTP::VERSION = '0.01'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Furl's low-level interface, wired to PSGI |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use Carp (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
9
|
1
|
|
|
1
|
|
460
|
use HTTP::Parser::XS; |
|
1
|
|
|
|
|
998
|
|
|
1
|
|
|
|
|
46
|
|
10
|
1
|
|
|
1
|
|
441
|
use HTTP::Message::PSGI (); |
|
1
|
|
|
|
|
21459
|
|
|
1
|
|
|
|
|
27
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
8
|
use parent 'Furl::HTTP'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
3
|
|
|
3
|
1
|
7
|
my $class = shift; |
17
|
3
|
|
|
|
|
21
|
my $self = $class->next::method(@_); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
defined $self->{app} |
20
|
3
|
50
|
|
|
|
189
|
or Carp::croak "'app' attribute must be provided"; |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
25
|
$self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
3
|
|
|
3
|
0
|
401
|
sub connect { 1 } |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
*connect_ssl = *connect_ssl_over_proxy = \&connect; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub write_all { |
30
|
3
|
|
|
3
|
0
|
186
|
my ($self, $sock, $p, $timeout_at) = @_; |
31
|
|
|
|
|
|
|
|
32
|
3
|
|
50
|
|
|
36
|
($self->{request} //= '') .= $p; |
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
|
|
8
|
1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub read_timeout { |
38
|
5
|
|
|
5
|
0
|
228
|
my ($self, $sock, $bufref, $len, $off, $timeout_at) = @_; |
39
|
|
|
|
|
|
|
|
40
|
5
|
100
|
|
|
|
19
|
if (my $request = delete $self->{request}) { |
41
|
3
|
|
|
|
|
6
|
my $env = {}; |
42
|
3
|
|
|
|
|
37
|
my $ret = HTTP::Parser::XS::parse_http_request($request, $env); |
43
|
3
|
50
|
33
|
|
|
16
|
if ($ret && $ret < 0) { |
44
|
0
|
|
|
|
|
0
|
Carp::confess "Error $ret trying to parse buffered HTTP request"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
3
|
|
66
|
|
|
6
|
my $res = eval { $self->{app}->($env) } |
48
|
|
|
|
|
|
|
|| $self->_psgi500($@); |
49
|
|
|
|
|
|
|
|
50
|
3
|
|
|
|
|
27
|
my $response = |
51
|
|
|
|
|
|
|
'HTTP/1.1 ' . HTTP::Message::PSGI::res_from_psgi($res)->as_string("\015\012"); |
52
|
|
|
|
|
|
|
|
53
|
3
|
|
|
|
|
21694
|
$$bufref = $response; |
54
|
3
|
|
|
|
|
24
|
return length($response); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
6
|
0; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _psgi500 { |
61
|
1
|
|
|
1
|
|
16
|
my ($self, $e) = @_; |
62
|
1
|
|
|
|
|
5
|
my $body = "Internal Response: $e"; |
63
|
|
|
|
|
|
|
[ |
64
|
1
|
|
|
|
|
8
|
500, |
65
|
|
|
|
|
|
|
[ |
66
|
|
|
|
|
|
|
'X-Internal-Response' => 1, |
67
|
|
|
|
|
|
|
'Content-Type' => 'text/plain', |
68
|
|
|
|
|
|
|
'Content-Length' => length($body) |
69
|
|
|
|
|
|
|
], |
70
|
|
|
|
|
|
|
[$body] |
71
|
|
|
|
|
|
|
] |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |