-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge Last-Modified fix for nginx (#76697)
This fixes the patch for nginx to clear the Last-Modified header if a static file is served from the Nix store. So far we only used the ETag from the store path, but if the Last-Modified header is always set to "Thu, 01 Jan 1970 00:00:01 GMT", Firefox and Chrome/Chromium seem to ignore the ETag and simply use the cached content instead of revalidating. Alongside the fix, this also adds a dedicated NixOS VM test, which uses WebDriver and Firefox to check whether the content is actually served from the browser's cache and to have a more real-world test case.
- Loading branch information
Showing
3 changed files
with
95 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import ./make-test-python.nix { | ||
name = "nginx-etag"; | ||
|
||
nodes = { | ||
server = { pkgs, lib, ... }: { | ||
networking.firewall.enable = false; | ||
services.nginx.enable = true; | ||
services.nginx.virtualHosts.server = { | ||
root = pkgs.runCommandLocal "testdir" {} '' | ||
mkdir "$out" | ||
cat > "$out/test.js" <<EOF | ||
document.getElementById('foobar').setAttribute('foo', 'bar'); | ||
EOF | ||
cat > "$out/index.html" <<EOF | ||
<!DOCTYPE html> | ||
<div id="foobar">test</div> | ||
<script src="test.js"></script> | ||
EOF | ||
''; | ||
}; | ||
|
||
nesting.clone = lib.singleton { | ||
services.nginx.virtualHosts.server = { | ||
root = lib.mkForce (pkgs.runCommandLocal "testdir2" {} '' | ||
mkdir "$out" | ||
cat > "$out/test.js" <<EOF | ||
document.getElementById('foobar').setAttribute('foo', 'yay'); | ||
EOF | ||
cat > "$out/index.html" <<EOF | ||
<!DOCTYPE html> | ||
<div id="foobar">test</div> | ||
<script src="test.js"></script> | ||
EOF | ||
''); | ||
}; | ||
}; | ||
}; | ||
|
||
client = { pkgs, lib, ... }: { | ||
virtualisation.memorySize = 512; | ||
environment.systemPackages = let | ||
testRunner = pkgs.writers.writePython3Bin "test-runner" { | ||
libraries = [ pkgs.python3Packages.selenium ]; | ||
} '' | ||
import os | ||
import time | ||
from selenium.webdriver import Firefox | ||
from selenium.webdriver.firefox.options import Options | ||
options = Options() | ||
options.add_argument('--headless') | ||
driver = Firefox(options=options) | ||
driver.implicitly_wait(20) | ||
driver.get('http://server/') | ||
driver.find_element_by_xpath('//div[@foo="bar"]') | ||
open('/tmp/passed_stage1', 'w') | ||
while not os.path.exists('/tmp/proceed'): | ||
time.sleep(0.5) | ||
driver.get('http://server/') | ||
driver.find_element_by_xpath('//div[@foo="yay"]') | ||
open('/tmp/passed', 'w') | ||
''; | ||
in [ pkgs.firefox-unwrapped pkgs.geckodriver testRunner ]; | ||
}; | ||
}; | ||
|
||
testScript = { nodes, ... }: let | ||
inherit (nodes.server.config.system.build) toplevel; | ||
newSystem = "${toplevel}/fine-tune/child-1"; | ||
in '' | ||
start_all() | ||
server.wait_for_unit("nginx.service") | ||
client.wait_for_unit("multi-user.target") | ||
client.execute("test-runner &") | ||
client.wait_for_file("/tmp/passed_stage1") | ||
server.succeed( | ||
"${newSystem}/bin/switch-to-configuration test >&2" | ||
) | ||
client.succeed("touch /tmp/proceed") | ||
client.wait_for_file("/tmp/passed") | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters