How to work with http web server through file socket in perl?

You can work with a web server living in a file socket with linux commands:

# /bin/echo -e "GET /containers/json?all=1 HTTP/1.0\r\n" | nc -U /var/run/docker.sock ; echo ''
HTTP/1.0 200 OK
Content-Type: application/json
Date: Sun, 03 Jan 2016 23:31:54 GMT
Content-Length: 2

[]
#

How can I do the same with Perl modules? I would prefer to do the same with HTTP :: Tiny , but I cannot figure out how to use it with a file socket.

Right now I just use perl system(), but I want to use HTTP :: Tiny to make the code simpler.

+4
source share
2 answers

I could not find a way to get HTTP :: Tiny to use UNIX sockets, but I found a way to get LWP to work:

use strict;
use warnings;
use LWP::UserAgent;
use LWP::Protocol::http::SocketUnixAlt;

my $socket = "/var/run/docker.sock";
my $geturi = "/containers/json?all=1"; #GET

LWP::Protocol::implementor( http => 'LWP::Protocol::http::SocketUnixAlt' );

my $ua = LWP::UserAgent->new();
my $res = $ua->get("http:/var/run/docker.sock/"."$geturi");
print $res->content;

CPAN, , HTTP- - .

+3

HTTP::Tiny::UNIX , . :

HTTP:: Tiny HTTP- Unix.

Starman HTTP unix-socket, HTTP:: Tiny:: UNIX. .

0

Source: https://habr.com/ru/post/1622659/


All Articles