6 use WgetFeature qw(https);
7 use WgetTest; # For $WGETPATH.
13 my $top_srcdir = shift @ARGV;
14 $key_path = "$top_srcdir/tests/certs/server-key.pem";
15 $cert_path = "$top_srcdir/tests/certs/server-cert.pem";
22 my $SOCKET = HTTP::Daemon->new (LocalAddr => 'localhost',
23 ReuseAddr => 1) or die "Cannot create server!!!";
30 while (defined ($line = <$conn>)) {
32 last if $line eq "\r\n";
35 my $rqst = HTTP::Request->parse($content)
36 or die "Couldn't parse request:\n$content\n";
48 for my $expect_inner_auth (0, 1) {
50 $rqst = $conn->get_request;
52 # TODO: expect no auth the first time, request it, expect it the second
55 die "Method not CONNECT\n" if ($rqst->method ne 'CONNECT');
56 $rspn = HTTP::Response->new(200, 'OK');
57 $conn->send_response($rspn);
61 SSL_passwd_cb => sub { return "Hello"; });
63 $options{SSL_cert_file} = $cert_path if ($cert_path);
64 $options{SSL_key_file} = $key_path if ($key_path);
66 my @options = %options;
68 $conn = IO::Socket::SSL->new_from_fd($conn->fileno, @options)
69 or die "Couldn't initiate SSL";
71 $rqst = &get_request($conn)
72 or die "Didn't get proxied request\n";
74 unless ($expect_inner_auth) {
75 die "Early proxied auth\n" if $rqst->header('Authorization');
77 # TODO: handle non-persistent connection here.
78 $rspn = HTTP::Response->new(401, 'Unauthorized', [
79 'WWW-Authenticate' => 'Basic realm="gondor"',
82 $rspn->protocol('HTTP/1.0');
83 print $rspn->as_string;
84 print $conn $rspn->as_string;
86 die "No proxied auth\n" unless $rqst->header('Authorization');
88 $rspn = HTTP::Response->new(200, 'OK', [
89 'Content-Type' => 'text/plain',
90 'Connection' => 'close',
92 $rspn->protocol('HTTP/1.0');
94 print $rspn->as_string;
96 print $conn $rspn->as_string;
107 die "Couldn't fork" if ($pid < 0);
114 system ('rm -f needs-auth.txt');
115 my $pid = &fork_server;
118 my $cmdline = $WgetTest::WGETPATH . " --user=fiddle-dee-dee"
119 . " --password=Dodgson -e https_proxy=localhost:{{port}}"
120 . " --no-check-certificate"
121 . " https://no.such.domain/needs-auth.txt";
122 $cmdline =~ s/{{port}}/$SOCKET->sockport()/e;
124 my $code = system($cmdline);
125 system ('rm -f needs-auth.txt');
127 warn "Got code: $code\n" if $code;