Skip to content

Fix warning with send_file.t on Windows#1779

Merged
xsawyerx merged 1 commit intomainfrom
fix/windows-send-file
Mar 7, 2026
Merged

Fix warning with send_file.t on Windows#1779
xsawyerx merged 1 commit intomainfrom
fix/windows-send-file

Conversation

@xsawyerx
Copy link
Copy Markdown
Member

@xsawyerx xsawyerx commented Mar 5, 2026

Confusing as heck... Closes GH #1772.

File::Temp on Windows uses FILE_FLAG_DELETE_ON_CLOSE semantics. The temp file is deleted when the OS file handle is closed. So close $temp deletes the file, and send_file($temp->filename, ...) subsequently fails the $file_path->exists check, which calls $err_response->(403), setting content type to text/plain and returning a 403.

So instead, we replace the File::Temp usage in the check_content_type route with
Path::Tiny::path(__FILE__)->absolute->stringify, which is the same pattern the /no_streaming and /options_streaming routes already use. The test only needs a readable file to verify that content_type => 'image/png' overrides MIME auto-detection. It doesn't require a temp file.

The core send_file implementation handles Windows absolute paths correctly (via the fix in df6a0a4). The issue was purely with the test's temp-file lifecycle assumption.

@wchristian now it's in your hands to confirm. :)

File::Temp on Windows uses `FILE_FLAG_DELETE_ON_CLOSE` semantics.
The temp file is deleted when the OS file handle is closed. So
`close $temp` deletes the file, and `send_file($temp->filename, ...)`
subsequently fails the `$file_path->exists` check, which calls
`$err_response->(403)`, setting content type to `text/plain` and
returning a 403.

So instead, we replace the File::Temp usage in the
`check_content_type` route with
`Path::Tiny::path(__FILE__)->absolute->stringify`, which is the same
pattern the `/no_streaming` and `/options_streaming` routes already
use. The test only needs a readable file to verify that
`content_type => 'image/png'` overrides MIME auto-detection. It
doesn't require a temp file.

The core `send_file` implementation handles Windows absolute paths
correctly (via the fix in df6a0a4). The issue was purely with the
test's temp-file lifecycle assumption.
@wchristian
Copy link
Copy Markdown
Contributor

that looks clever, and tests indeed indicate it passes quietly now :)

@xsawyerx
Copy link
Copy Markdown
Member Author

xsawyerx commented Mar 7, 2026

Confirmation from @wchristian is all I need to merge. :)

@xsawyerx xsawyerx merged commit 8400ba3 into main Mar 7, 2026
18 checks passed
@xsawyerx xsawyerx deleted the fix/windows-send-file branch March 7, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants