Skip to content

Commit 8400ba3

Browse files
committed
Fix warning with send_file.t on Windows:
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.
1 parent 92892c2 commit 8400ba3

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

t/dsl/send_file.t

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use Encode 'encode_utf8';
66
use Test::More;
77
use Plack::Test;
88
use HTTP::Request::Common;
9-
use File::Temp;
109
use Path::Tiny ();
1110
use Ref::Util qw<is_coderef>;
1211

@@ -45,11 +44,8 @@ use Ref::Util qw<is_coderef>;
4544
};
4645

4746
get '/check_content_type' => sub {
48-
my $temp = File::Temp->new();
49-
print $temp "hello";
50-
close $temp;
51-
send_file($temp->filename, content_type => 'image/png',
52-
system_path => 1);
47+
my $file = Path::Tiny::path(__FILE__)->absolute->stringify;
48+
send_file($file, content_type => 'image/png', system_path => 1);
5349
};
5450

5551
get '/no_streaming' => sub {

0 commit comments

Comments
 (0)