line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Furl::PSGI::HTTP; |
2
|
|
|
|
|
|
|
$Furl::PSGI::HTTP::VERSION = '0.02'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Furl's low-level interface, wired to PSGI |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Carp (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
13
|
|
9
|
1
|
|
|
1
|
|
495
|
use HTTP::Parser::XS; |
|
1
|
|
|
|
|
1009
|
|
|
1
|
|
|
|
|
49
|
|
10
|
1
|
|
|
1
|
|
457
|
use HTTP::Message::PSGI (); |
|
1
|
|
|
|
|
22239
|
|
|
1
|
|
|
|
|
30
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
8
|
use parent 'Furl::HTTP'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
3
|
|
|
3
|
1
|
6
|
my $class = shift; |
17
|
3
|
|
|
|
|
17
|
my $self = $class->next::method(@_); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
defined $self->{app} |
20
|
3
|
50
|
|
|
|
171
|
or Carp::croak "'app' attribute must be provided"; |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
21
|
$self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
8
|
|
|
8
|
0
|
4153
|
sub connect { 1 } |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
*connect_ssl = *connect_ssl_over_proxy = \&connect; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub write_all { |
30
|
8
|
|
|
8
|
0
|
416
|
my ($self, $sock, $p, $timeout_at) = @_; |
31
|
|
|
|
|
|
|
|
32
|
8
|
50
|
|
|
|
45
|
$self->{request} = '' if !exists $self->{request}; |
33
|
8
|
|
|
|
|
21
|
$self->{request} .= $p; |
34
|
|
|
|
|
|
|
|
35
|
8
|
|
|
|
|
27
|
1; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub read_timeout { |
39
|
15
|
|
|
15
|
0
|
527
|
my ($self, $sock, $bufref, $len, $off, $timeout_at) = @_; |
40
|
|
|
|
|
|
|
|
41
|
15
|
100
|
|
|
|
44
|
if (my $request = delete $self->{request}) { |
42
|
8
|
|
|
|
|
16
|
my $env = {}; |
43
|
8
|
|
|
|
|
81
|
my $ret = HTTP::Parser::XS::parse_http_request($request, $env); |
44
|
8
|
50
|
33
|
|
|
37
|
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
|
|
|
|
|
65
|
my $response = |
52
|
|
|
|
|
|
|
'HTTP/1.1 ' . HTTP::Message::PSGI::res_from_psgi($res)->as_string("\015\012"); |
53
|
|
|
|
|
|
|
|
54
|
8
|
|
|
|
|
23344
|
$$bufref = $response; |
55
|
8
|
|
|
|
|
49
|
return length($response); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
7
|
|
|
|
|
16
|
0; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _psgi500 { |
62
|
1
|
|
|
1
|
|
18
|
my ($self, $e) = @_; |
63
|
1
|
|
|
|
|
3
|
my $body = "Internal Response: $e"; |
64
|
|
|
|
|
|
|
[ |
65
|
1
|
|
|
|
|
8
|
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__ |