libwww-perl / libwww-perl/HTTP-Daemon

Modernize `send_file_response` to use 3-arg `open` with a lexical filehandle

Open Beginner friendly
#83 0 comments 0 reactions 0 assignees View on GitHub

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 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.