Skip to content

Fix StaticFileHandler to return 404 on file error#16025

Merged
straight-shoota merged 5 commits intocrystal-lang:masterfrom
straight-shoota:fix/http-static-file-handler-error
Aug 8, 2025
Merged

Fix StaticFileHandler to return 404 on file error#16025
straight-shoota merged 5 commits intocrystal-lang:masterfrom
straight-shoota:fix/http-static-file-handler-error

Conversation

@straight-shoota
Copy link
Member

Resolves #15901

@straight-shoota straight-shoota self-assigned this Jul 23, 2025
@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:networking labels Jul 23, 2025
@straight-shoota straight-shoota marked this pull request as draft July 23, 2025 18:15
@straight-shoota
Copy link
Member Author

I don't get why the new spec fails on Aarch64 CI and in the interpreter only. Aarch64 CI is the runs-on environment which uses a different base image than the hosted runners from GitHub. But interpreter specs should run in exactly the same environment as other jobs. 🤷
Even the guard to make sure the file isn't readable didn't help. The file has no permissions. Yet still, apparently the file handler can still read its contents. This is very weird.

At last, I added a File.read test in order to properly detect whether the file is actually readable. If anyone has any better idea, I'm happy for suggestions. Maybe we can introduce some other kind of error?

@straight-shoota straight-shoota marked this pull request as ready for review July 28, 2025 11:05
@straight-shoota straight-shoota added this to the 1.18.0 milestone Aug 6, 2025
@straight-shoota straight-shoota merged commit 2d08265 into crystal-lang:master Aug 8, 2025
39 checks passed
@straight-shoota straight-shoota deleted the fix/http-static-file-handler-error branch August 8, 2025 07:33
@HertzDevil
Copy link
Contributor

HertzDevil commented Aug 9, 2025

broken-symlink.txt is breaking Git on MSYS2, it should be created and deleted entirely within the new specs:

$ MSYS='winsymlinks:nativestrict' git restore --source=HEAD :/
error: unable to create symlink spec/std/data/static_file_handler/broken-symlink.txt: No such file or directory

(MSYS='winsymlinks:native' would successfully create an invalid WSL1 symlink using IO_REPARSE_TAG_LX_SYMLINK, which we don't want either.)

Also, why does the spec look for broken_symlink.txt with an underscore instead of a hyphen? Is this intentional?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:networking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP::StaticFileHandler raises an exception when given a long filename

4 participants