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