libwww-perl / libwww-perl/HTTP-Daemon
Modernize `send_file_response` to use 3-arg `open` with a lexical filehandle
Nobody has claimed this yet.
- Dominant language
- Perl
- Stars
- 6
- Forks
- 17
- PR merge metrics
- No merged PRs in 30d
Description
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
0isO_RDONLYas a bare magic number, which is harder to read than an explicit<. - The localized typeglob
*Fis only needed because the handle is a bareword; a lexical$fhremoves that requirement entirely. - Behaviour is unchanged: 3-arg
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_response only. send_file already uses the modern form.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/HTTP/Daemon.pm around lines 565-567 and compare send_file_response with the existing send_file implementation. Check how the file handle is passed into send_file; done means send_file_response uses the modern read-only handle style while preserving its existing forbidden-error behavior and limited scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- perl
- Domain
- backend, networking
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 86/100