Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
oalders opened this issue Mar 31, 2017 · 0 comments
Open

Comments

@oalders
Copy link
Member

oalders commented Mar 31, 2017

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

Requestors:

From [email protected] 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant