NAME
Tailscale::HttpServer - minimal HTTP server on a Tailscale network
SYNOPSIS
use Tailscale;
use Tailscale::HttpServer;
use HTTP::Response;
my $ts = Tailscale->new(
config_path => "state.json",
auth_key => "tskey-auth-...",
);
my $httpd = Tailscale::HttpServer->new(
tailscale => $ts,
port => 8080,
);
$httpd->run(sub {
my ($req) = @_; # HTTP::Request
my $res = HTTP::Response->new(200);
$res->header('Content-Type' => 'text/plain');
$res->content("Hello from Perl!\n");
return $res;
});
DESCRIPTION
A simple, single-threaded HTTP/1.0 server that runs on a Tailscale network. It uses HTTP::Request for parsing incoming requests and HTTP::Response for formatting outgoing responses. The actual network transport is provided by the Tailscale TCP primitives.
This is intentionally minimal. For production use you would likely want to build a PSGI/Plack adapter on top of the Tailscale TCP API instead.
CONSTRUCTOR
new
my $httpd = Tailscale::HttpServer->new(%args);
Arguments:
- tailscale (required)
-
A Tailscale object representing the node to serve on.
- port
-
The TCP port to listen on. Defaults to 80.
METHODS
run
$httpd->run(\&handler);
Listens on the configured port and enters an accept loop. For each incoming connection the request is parsed into an HTTP::Request and passed to \&handler, which must return an HTTP::Response. The response is sent back to the client and the connection is closed.
This method does not return.
accept_once
$httpd->accept_once($listener, \&handler);
Accepts a single connection on the given Tailscale::TcpListener, handles it with \&handler, and returns. Useful for testing.
SEE ALSO
Tailscale, Tailscale::TcpStream, HTTP::Request, HTTP::Response
AUTHOR
Brad Fitzpatrick <brad@danga.com>
LICENSE
BSD-3-Clause