NixOS / hydra

Hydra, the Nix-based continuous build system
http://nixos.org/hydra
GNU General Public License v3.0
1.1k stars 291 forks source link

Fix MIME types when serving .js and .css to fix rendering of HTML reports #1268

Closed knedlsepp closed 8 months ago

knedlsepp commented 1 year ago

To correctly render HTML reports we make sure to return the following MIME types instead of "text/plain"

Fixes: #1267

drupol commented 1 year ago

I confirm the issue when using Chromium, not in Firefox.

While I agree that the proposed changes might be fixing the issue, I think it would be better to investigate why there is a permission issue on the server.

To reproduce it:

Anyone can reproduce the issue by doing:

❯ curl -I https://hydra.nixos.org/build/196107287/download/1/hydra/fonts/fonts.css
HTTP/2 200 
strict-transport-security: max-age=15552000
vary: Accept
content-type: cannot open `/nix/store/mp2x9s34n3m2lyd7hk9x15l1sry5qkda-hydra-manual-0.1.20221021.312cb42/share/doc/hydra/fonts/fonts.css' (No such file or directory); charset=cannot open `/nix/store/mp2x9s34n3m2lyd7hk9x15l1sry5qkda-hydra-manual-0.1.20221021.312cb42/share/doc/hydra/fonts/fonts.css' (No such file or directory)
last-modified: Sat, 22 Oct 2022 06:13:00 GMT
content-length: 3620
date: Mon, 10 Jul 2023 15:39:41 GMT
set-cookie: hydra_session=27212460deb4407adab3872f6adb1645739e1576; path=/; expires=Mon, 17-Jul-2023 15:39:41 GMT; HttpOnly; SameSite=Lax
server: Apache/2.4.54 (Unix) OpenSSL/1.1.1s

❯ curl -I https://hydra.nixos.org/build/196107287/download/1/hydra/clipboard.min.js
HTTP/2 200 
strict-transport-security: max-age=15552000
vary: Accept
content-type: cannot open `/nix/store/mp2x9s34n3m2lyd7hk9x15l1sry5qkda-hydra-manual-0.1.20221021.312cb42/share/doc/hydra/clipboard.min.js' (No such file or directory); charset=cannot open `/nix/store/mp2x9s34n3m2lyd7hk9x15l1sry5qkda-hydra-manual-0.1.20221021.312cb42/share/doc/hydra/clipboard.min.js' (No such file or directory)
last-modified: Sat, 22 Oct 2022 06:13:00 GMT
content-length: 10754
date: Mon, 10 Jul 2023 15:41:15 GMT
set-cookie: hydra_session=0052635d3699320dc95669657ee2b6ed0304b596; path=/; expires=Mon, 17-Jul-2023 15:41:15 GMT; HttpOnly; SameSite=Lax
server: Apache/2.4.54 (Unix) OpenSSL/1.1.1s
knedlsepp commented 1 year ago

I think it would be better to investigate why there is a permission issue on the server.

The issue was introduced in https://github.com/NixOS/hydra/pull/1240. When I debugged this locally the issue was that the content type changed from "text/css" to "text/plain". In this case we get a "(No such file or directory)". I'm guessing there are probably two issues with #1240 only one of which I identified. I don't know exactly how the official hydra.nixos.org is set up, but to my understanding the files are really stored on S3. Potentially the perl logic to determine the MIME type based on the content assumes that the file is available in the local nix store: https://github.com/NixOS/hydra/pull/1240/files#diff-752f4108f73ba8852c4532ebb985cdbd4601fbdb8971f746669c29157688ddf9R241-R242

It could be that this issue would still persist with the change I'm proposing here (which is a partial revert of #1240). It would at least be limited to files without an extension, but then again the question is if #1240 should be reverted altogether?