1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#!/usr/bin/perl -w
#
# This file is part of the dgit test suite.
#
# Copyright (C)2004-2015 Best Practical Solutions, LLC
# Copyright (C)2019 Ian Jackson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# invocation:
#
# < tests/tmp/$test/some-file \
# ftpmasterapi-static-server \
# tests/tmp/
use strict;
use IO::Handle;
$SIG{ALRM} = sub { print STDERR "y\n"; };
alarm(5);
package MyServer;
use strict;
use Socket qw(AF_INET SOCK_STREAM);
use Socket qw(AF_INET SOCK_STREAM unpack_sockaddr_in);
use IO::Handle;
use Data::Dumper;
use base qw(HTTP::Server::Simple::CGI);
use HTTP::Server::Simple::Static;
my $webroot = '/var/www';
sub handle_request {
my ( $self, $cgi ) = @_;
if ( !$self->serve_static( $cgi, $webroot ) ) {
print "HTTP/1.0 404 Not found\r\n";
print $cgi->header,
$cgi->start_html('Not found'),
$cgi->h1('Not found'),
$cgi->end_html;
}
}
sub port () { return 0; }
sub xsetup_listener ()
{
my $self=shift;
print STDERR "foo!", $self->stdio_handle(), "\n";
my $sock = new IO::Handle;
socket $sock, AF_INET, SOCK_STREAM, 0 or die $!;
#$self->stdio_handle($sock);
}
sub after_setup_listener () {
my $x = getsockname HTTP::Server::Simple::HTTPDaemon or die $!;
print STDERR Dumper(unpack_sockaddr_in $x);
}
package main;
my $server = MyServer->new();
$server->run();
|