line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::UserAgent::UnixSocket; |
2
|
2
|
|
|
2
|
|
191128
|
use Carp 'carp'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
126
|
|
3
|
2
|
|
|
2
|
|
2116
|
use Mojo::Base 'Mojo::UserAgent'; |
|
2
|
|
|
|
|
48782
|
|
|
2
|
|
|
|
|
24
|
|
4
|
2
|
|
|
2
|
|
1302578
|
use DummySocket; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
32
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.021'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub start { |
9
|
1
|
|
|
1
|
1
|
6374
|
my ($self, $tx, $cb) = @_; |
10
|
1
|
50
|
|
|
|
43
|
if ($tx->req->url->scheme eq 'unix') { |
11
|
1
|
|
|
|
|
93
|
my $path = $tx->req->url->path; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# pull out the sock_path ('host') and url path. |
14
|
1
|
|
|
|
|
64
|
my $sock_path = ($path =~ m#(^.+\.sock)\/#)[0]; |
15
|
1
|
|
|
|
|
640
|
(my $url_path = $path) =~ s/$sock_path//; |
16
|
1
|
|
|
|
|
141
|
$tx->req->url->path($url_path); |
17
|
1
|
|
|
|
|
78
|
$tx->req->url->host('localhost'); |
18
|
|
|
|
|
|
|
|
19
|
1
|
50
|
|
|
|
114
|
if (-S $sock_path) { |
20
|
1
|
|
|
|
|
58
|
my $sock = DummySocket->new(Peer => $sock_path); |
21
|
1
|
|
|
|
|
493
|
$tx->connection($sock); |
22
|
|
|
|
|
|
|
} else { |
23
|
0
|
|
|
|
|
0
|
my $message = "$sock_path is not a readable socket."; |
24
|
0
|
|
|
|
|
0
|
carp $message; |
25
|
0
|
|
|
|
|
0
|
$tx->req->error({message => $message}); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
1
|
|
|
|
|
114
|
$self->SUPER::start($tx, $cb); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=encoding utf8 |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 NAME |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Mojo::UserAgent::UnixSocket - User Agent connections over UNIX sockets. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 VERSION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
0.01 |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SYNOPSIS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
use Mojo::UserAgent::UnixSocket; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $ua = Mojo::UserAgent::UnixSocket->new; |
48
|
|
|
|
|
|
|
say $ua->get('unix:///var/run/docker.sock/images/json?all=true')->res->body; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 DESCRIPTION |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
L transparently enables L to interact with services listening on Unix domain sockets. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Any invocation that works with L should also work here. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
It expects URLs in the following format (the .sock is required, pending a clever patch): |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
unix://.sock/ |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
For example, talking to the L daemon, whose socket is (typically) located at C: |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
unix:///var/run/docker.sock/images/nginx/json |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 SEE ALSO |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
L, L |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|