HTTP::Daemon::send_file_response currently uses an antique I/O idiom (lib/HTTP/Daemon.pm:565-567):
local (*F);
sysopen(F, $file, 0) or return $self->send_error(RC_FORBIDDEN);
binmode(F);
This predates the style perlopentut has recommended for many years: 3-arg open with an explicit mode and a lexical filehandle. The same tutorial deliberately stays away from sysopen, which is a lower-level primitive intended for cases that need O_* flag combinations (e.g. O_EXCL for atomic creates) — not plain read-only access.
Suggested replacement:
open(my $fh, '<', $file) or return $self->send_error(RC_FORBIDDEN);
binmode($fh);
Then pass $fh into send_file instead of \*F.
Notes:
- The mode argument
0 is O_RDONLY as a bare magic number, which is harder to read than an explicit <.
- The localized typeglob
*F is only needed because the handle is a bareword; a lexical $fh removes that requirement entirely.
- Behaviour is unchanged: 3-arg
open with explicit < opens the file read-only and does not interpret any 2-arg open magic in the path.
Scope: this is a cleanup of send_file_response only. send_file already uses the modern form.
HTTP::Daemon::send_file_responsecurrently uses an antique I/O idiom (lib/HTTP/Daemon.pm:565-567):This predates the style
perlopentuthas recommended for many years: 3-argopenwith an explicit mode and a lexical filehandle. The same tutorial deliberately stays away fromsysopen, which is a lower-level primitive intended for cases that needO_*flag combinations (e.g.O_EXCLfor atomic creates) — not plain read-only access.Suggested replacement:
Then pass
$fhintosend_fileinstead of\*F.Notes:
0isO_RDONLYas a bare magic number, which is harder to read than an explicit<.*Fis only needed because the handle is a bareword; a lexical$fhremoves that requirement entirely.openwith explicit<opens the file read-only and does not interpret any 2-argopenmagic in the path.Scope: this is a cleanup of
send_file_responseonly.send_filealready uses the modern form.