5 use WgetTest; # For $WGETPATH.
8 use IO::Socket::SSL 'debug4';
15 while (defined ($line = <$conn>)) {
17 last if $line eq "\r\n";
20 my $rqst = HTTP::Request->parse($content)
21 or die "Couldn't parse request:\n$content\n";
29 my $s = HTTP::Daemon->new (LocalAddr => 'localhost',
31 ReuseAddr => 1) or die "Cannot create server!!!";
35 for my $expect_inner_auth (0, 1) {
37 $rqst = $conn->get_request;
39 # TODO: expect no auth the first time, request it, expect it the second
42 die "Method not CONNECT\n" if ($rqst->method ne 'CONNECT');
43 $rspn = HTTP::Response->new(200, 'OK');
44 $conn->send_response($rspn);
46 $conn = IO::Socket::SSL->new_from_fd($conn->fileno, SSL_server => 1,
47 SSL_passwd_cb => sub { return "Hello"; })
48 or die "Couldn't initiate SSL";
50 $rqst = &get_request($conn)
51 or die "Didn't get proxied request\n";
53 unless ($expect_inner_auth) {
54 die "Early proxied auth\n" if $rqst->header('Authorization');
56 # TODO: handle non-persistent connection here.
57 $rspn = HTTP::Response->new(401, 'Unauthorized', [
58 'WWW-Authenticate' => 'Basic realm="gondor"',
61 $rspn->protocol('HTTP/1.0');
62 print $rspn->as_string;
63 print $conn $rspn->as_string;
65 die "No proxied auth\n" unless $rqst->header('Authorization');
67 $rspn = HTTP::Response->new(200, 'OK', [
68 'Content-Type' => 'text/plain',
69 'Connection' => 'close',
71 print $conn $rspn->as_string;
82 die "Couldn't fork" if ($pid < 0);
89 system ('rm -f needs-auth.txt');
93 my $cmdline = $WgetTest::WGETPATH . " --user=fiddle-dee-dee"
94 . " --password=Dodgson -e https_proxy=localhost:8080"
95 . " --no-check-certificate"
96 . " https://no.such.domain/needs-auth.txt";
98 my $code = system($cmdline);
100 warn "Got code: $code\n" if $code;