1{ ... }:
2{
3 name = "nginx-etag-compression";
4
5 nodes.machine =
6 { pkgs, lib, ... }:
7 {
8 services.nginx = {
9 enable = true;
10 recommendedGzipSettings = true;
11 virtualHosts.default = {
12 root = pkgs.runCommandLocal "testdir" { } ''
13 mkdir "$out"
14 cat > "$out/index.html" <<EOF
15 Hello, world!
16 Hello, world!
17 Hello, world!
18 Hello, world!
19 Hello, world!
20 Hello, world!
21 Hello, world!
22 Hello, world!
23 EOF
24 ${pkgs.gzip}/bin/gzip -k "$out/index.html"
25 '';
26 };
27 };
28 };
29
30 testScript =
31 { nodes, ... }:
32 ''
33 machine.wait_for_unit("nginx")
34 machine.wait_for_open_port(80)
35
36 etag_plain = machine.succeed("curl -s -w'%header{etag}' -o/dev/null -H 'Accept-encoding:' http://127.0.0.1/")
37 etag_gzip = machine.succeed("curl -s -w'%header{etag}' -o/dev/null -H 'Accept-encoding:gzip' http://127.0.0.1/")
38
39 with subtest("different representations have different etags"):
40 assert etag_plain != etag_gzip, f"etags should differ: {etag_plain} == {etag_gzip}"
41
42 with subtest("etag for uncompressed response is reproducible"):
43 etag_plain_repeat = machine.succeed("curl -s -w'%header{etag}' -o/dev/null -H 'Accept-encoding:' http://127.0.0.1/")
44 assert etag_plain == etag_plain_repeat, f"etags should be the same: {etag_plain} != {etag_plain_repeat}"
45
46 with subtest("etag for compressed response is reproducible"):
47 etag_gzip_repeat = machine.succeed("curl -s -w'%header{etag}' -o/dev/null -H 'Accept-encoding:gzip' http://127.0.0.1/")
48 assert etag_gzip == etag_gzip_repeat, f"etags should be the same: {etag_gzip} != {etag_gzip_repeat}"
49 '';
50}