-
Notifications
You must be signed in to change notification settings - Fork 0
/
50file-config.t
136 lines (122 loc) · 4.52 KB
/
50file-config.t
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
use strict;
use warnings;
use Test::More;
use t::Util;
plan skip_all => 'curl not found'
unless prog_exists('curl');
subtest 'root-redirect' => sub {
my $server = spawn_h2o(<< "EOT");
hosts:
default:
paths:
/abc:
file.dir: @{[ DOC_ROOT ]}
EOT
run_with_curl($server, sub {
my ($proto, $port, $curl) = @_;
my ($stderr, $stdout) = run_prog("$curl --silent --show-error --max-redirs 0 --dump-header /dev/stderr $proto://127.0.0.1:$port/abc");
like $stderr, qr{^HTTP/[^ ]+ 301\s}s, "is 301";
like $stderr, qr{^location: ?/abc/\r$}im, "location header";
});
};
subtest 'etag' => sub {
my $fetch = sub {
my $extra_conf = shift;
my $server = spawn_h2o(<< "EOT");
hosts:
default:
paths:
/:
file.dir: examples/doc_root
$extra_conf
EOT
return `curl --silent --dump-header /dev/stderr http://127.0.0.1:$server->{port}/ 2>&1 > /dev/null`;
};
my $etag_re = qr/^etag: /im;
my $resp = $fetch->('');
like $resp, $etag_re, "default is on";
$resp = $fetch->('file.etag: off');
unlike $resp, $etag_re, "off";
$resp = $fetch->('file.etag: on');
like $resp, $etag_re, "on";
};
subtest 'send-compressed' => sub {
my $doit = sub {
my ($send_compressed, $curl_opts, $expected_length) = @_;
my $server = spawn_h2o(<< "EOT");
hosts:
default:
paths:
/:
file.dir: t/assets/doc_root
@{[ defined $send_compressed ? "file.send-compressed: $send_compressed" : "" ]}
EOT
my $fetch = sub {
my $path = shift;
subtest "send-compressed:@{[ $send_compressed || q(default) ]}, $curl_opts, $path" => sub {
my $resp = `curl --silent --dump-header /dev/stderr $curl_opts http://127.0.0.1:$server->{port}$path 2>&1 > /dev/null`;
like $resp, qr/^content-length:\s*$expected_length\r$/im, "length is as expected";
if (($send_compressed || '') eq 'ON') {
like $resp, qr/^vary:\s*accept-encoding\r$/im, "has vary set";
} else {
unlike $resp, qr/^vary:\s*accept-encoding\r$/im, "not has vary set";
}
};
};
$fetch->('/index.txt');
$fetch->('/');
};
my $orig_len = (stat 't/assets/doc_root/index.txt')[7];
my $gz_len = (stat 't/assets/doc_root/index.txt.gz')[7];
my $br_len = (stat 't/assets/doc_root/index.txt.br')[7];
$doit->(undef, "", $orig_len);
$doit->(undef, q{--header "Accept-Encoding: gzip"}, $orig_len);
$doit->("OFF", q{--header "Accept-Encoding: gzip"}, $orig_len);
$doit->("OFF", q{--header "Accept-Encoding: br, gzip"}, $orig_len);
$doit->("ON", "", $orig_len);
$doit->("ON", q{--header "Accept-Encoding: gzip"}, $gz_len);
$doit->("ON", q{--header "Accept-Encoding: gzip, deflate"}, $gz_len);
$doit->("ON", q{--header "Accept-Encoding: deflate, gzip"}, $gz_len);
$doit->("ON", q{--header "Accept-Encoding: deflate"}, $orig_len);
$doit->("ON", q{--header "Accept-Encoding: br, gzip"}, $br_len);
$doit->("ON", q{--header "Accept-Encoding: gzip, br"}, $br_len);
$doit->("ON", q{--header "Accept-Encoding: br"}, $br_len);
subtest 'MSIE-workaround' => sub {
my $server = spawn_h2o(<< "EOT");
hosts:
default:
paths:
/:
file.dir: t/assets/doc_root
file.send-gzip: ON
EOT
my $resp = `curl --silent --dump-header /dev/stderr --user-agent "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)" --header "Accept-Encoding: gzip" http://127.0.0.1:$server->{port}/ 2>&1 > /dev/null`;
like $resp, qr/^content-length:\s*$gz_len\r$/im, "length is as expected";
like $resp, qr/^cache-control:.*private.*\r$/im, "cache-control: private";
unlike $resp, qr/^vary:/im, "no vary";
};
};
subtest 'dir-listing' => sub {
my $server = spawn_h2o(<< 'EOT');
hosts:
default:
paths:
/off:
file.dir: examples/doc_root
file.dirlisting: off
/on:
file.dir: examples/doc_root
file.dirlisting: on
file.index: []
EOT
my $fetch = sub {
my $path = shift;
run_prog("curl --silent --dump-header /dev/stderr http://127.0.0.1:$server->{port}$path");
};
my ($headers, $content) = $fetch->("/on/");
like $headers, qr{^HTTP/1\.[0-9]+ 200 }s, "ON returns 200";
unlike $content, qr{examples}, "result should not include internal info";
($headers, $content) = $fetch->("/off/");
like $headers, qr{^HTTP/1\.[0-9]+ 403 }s, "OFF returns 403";
};
done_testing();