5 use WgetTest; # For $WGETPATH.
10 my $SOCKET = HTTP::Daemon->new (LocalAddr => 'localhost',
11 ReuseAddr => 1) or die "Cannot create server!!!";
18 while (defined ($line = <$conn>)) {
20 last if $line eq "\r\n";
23 my $rqst = HTTP::Request->parse($content)
24 or die "Couldn't parse request:\n$content\n";
36 for my $expect_inner_auth (0, 1) {
38 $rqst = $conn->get_request;
40 # TODO: expect no auth the first time, request it, expect it the second
43 die "Method not CONNECT\n" if ($rqst->method ne 'CONNECT');
44 $rspn = HTTP::Response->new(200, 'OK');
45 $conn->send_response($rspn);
47 $conn = IO::Socket::SSL->new_from_fd($conn->fileno, SSL_server => 1,
48 SSL_passwd_cb => sub { return "Hello"; })
49 or die "Couldn't initiate SSL";
51 $rqst = &get_request($conn)
52 or die "Didn't get proxied request\n";
54 unless ($expect_inner_auth) {
55 die "Early proxied auth\n" if $rqst->header('Authorization');
57 # TODO: handle non-persistent connection here.
58 $rspn = HTTP::Response->new(401, 'Unauthorized', [
59 'WWW-Authenticate' => 'Basic realm="gondor"',
62 $rspn->protocol('HTTP/1.0');
63 print $rspn->as_string;
64 print $conn $rspn->as_string;
66 die "No proxied auth\n" unless $rqst->header('Authorization');
68 $rspn = HTTP::Response->new(200, 'OK', [
69 'Content-Type' => 'text/plain',
70 'Connection' => 'close',
72 $rspn->protocol('HTTP/1.0');
74 print $rspn->as_string;
76 print $conn $rspn->as_string;
87 die "Couldn't fork" if ($pid < 0);
94 system ('rm -f needs-auth.txt');
95 my $pid = &fork_server;
98 my $cmdline = $WgetTest::WGETPATH . " --user=fiddle-dee-dee"
99 . " --password=Dodgson -e https_proxy=localhost:{{port}}"
100 . " --no-check-certificate"
101 . " https://no.such.domain/needs-auth.txt";
102 $cmdline =~ s/{{port}}/$SOCKET->sockport()/e;
104 my $code = system($cmdline);
105 system ('rm -f needs-auth.txt');
107 warn "Got code: $code\n" if $code;