libwww-perl / libwww-perl/HTTP-Message

HTTP::Response constructor to set Content-Length [rt.cpan.org #106990]

Open
#61 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Perl
Stars
32
Forks
63
Avg merge
5h 14m
Merged PRs (30d)
1

Description

Migrated from rt.cpan.org#106990 (status was 'new')

Requestors:

  • leonerd-cpan@leonerd.org.uk

From leonerd-cpan@leonerd.org.uk on 2015-09-09 15:33:38:

Often it's convenient to send an HTTP response from an inline-constructed H:R object:

   $req->respond( HTTP::Response->new( 200, "OK", [ "Content-Type" => "text/plain" ],
      "Hello, world",
   ) );

Problem is if I do this, the response object has no Content-Length, no Connection=close and no chunked transfer encoding. The HTTP server/client now have no way to communicate the end of the response and the client will never see the end.

It's not always convenient to store the content in a variable first,

   my $content = ...
   $req->respond( HTTP::Response->new( 200, "OK", [ "Content-Type" => "text/plain", "Content-Length" => length $content ], $content ) );

It might be nice to have a constructor to do this

  sub new_with_content_length
  {
     my $self = shift->new( @_ );
     $self->content_length( length $self->content ) if defined $self->content;
     $self;
  }

-- 

Paul Evans

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 with the HTTP::Response->new constructor and the existing content_length behavior. Add a constructor path that derives Content-Length from defined content, then verify that an inline response communicates its end correctly without requiring the caller to store the content separately.

Written by the indexing model from the issue text.

Assessment

Tech stack
perl
Domain
networking
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.