1#!/usr/bin/env perl
2
3use strict;
4use warnings;
5
6use WgetFeature qw(iri);
7use HTTPTest;
8
9# " Kon'nichiwa <dot> Japan
10my $utf8_hostname = "\344\273\212\346\227\245\343\201\257.\346\227\245\346\234\254";
11my $punycoded_hostname = 'xn--v9ju72g90p.xn--wgv71a';
12
13###############################################################################
14
15my $starter_file = <<EOF;
16<a href="http://$utf8_hostname/foo.txt">The link</a>
17EOF
18
19my $result_file = <<EOF;
20Found me!
21EOF
22
23# code, msg, headers, content
24my %urls = (
25    "http://$punycoded_hostname/index.html" => {
26        code => "200",
27        msg => "Yes, please",
28        headers => {
29            'Content-Type' => 'text/html; charset=UTF-8',
30        },
31        content => $starter_file,
32    },
33    "http://$punycoded_hostname/foo.txt" => {
34        code => "200",
35        msg => "Uh-huh",
36        headers => {
37            'Content-Type' => 'text/plain',
38        },
39        content => $result_file,
40    },
41    "http://$punycoded_hostname/robots.txt" => {
42        code => "200",
43        msg => "Uh-huh",
44        headers => {
45            'Content-Type' => 'text/plain',
46        },
47        content => '',
48    },
49);
50
51my $cmdline = $WgetTest::WGETPATH . " --iri -r"
52    . " -e http_proxy=localhost:{{port}} --local-encoding=UTF-8"
53    . " http://$utf8_hostname/";
54
55my $expected_error_code = 0;
56
57my %expected_downloaded_files = (
58    "$punycoded_hostname/index.html" => {
59        content => $starter_file,
60    },
61    "$punycoded_hostname/foo.txt" => {
62        content => $result_file,
63    },
64    "$punycoded_hostname/robots.txt" => {
65        content => '',
66    },
67);
68
69###############################################################################
70
71my $the_test = HTTPTest->new (input => \%urls,
72                              cmdline => $cmdline,
73                              errcode => $expected_error_code,
74                              output => \%expected_downloaded_files);
75exit $the_test->run();
76
77# vim: et ts=4 sw=4
78