render_binary - kelp 0.4501

24 views
Skip to first unread message

Miguel Prz

unread,
Aug 16, 2013, 3:00:00 AM8/16/13
to perl...@googlegroups.com
I think there is a small bug in documentation of this new method

res->set_content_type('image/jpeg')->render_binary( $content );

should be:

$self->res->set_content_type('image/jpeg')->render_binary( $content );

Also, how can I specify the Content-Length of a binary resource? I was using this piece of code:

$self->res->set_code(200);
$self->res->set_content_type( $doc->mime );
$self->res->content_length( $doc->size );
$self->res->rendered(1);
$self->res->body( $doc->content->bytes );

Thanks,
Miguel

Stefan Geneshky

unread,
Aug 16, 2013, 11:08:00 AM8/16/13
to perl...@googlegroups.com
That's not a typo in the docs. The example is using Kelp::Less - https://metacpan.org/module/Kelp::Less and res is a valid keyword.

Keep using that code for the content length. It's correct:

$self->res->set_content_length( $doc->mime )->render_binary( $doc->content->bytes );

You can also see if you can use Plack::Middleware::ContentLength for that.

Stefan

Miguel Prz

unread,
Aug 17, 2013, 2:49:00 AM8/17/13
to perl...@googlegroups.com
Thanks, but that method 

Can't locate object method "set_content_length"

At Plack::Response, we have "content_length", but it doesn't return the $self instance to allow chained method call.

Stefan Geneshky

unread,
Aug 17, 2013, 11:38:41 AM8/17/13
to perl...@googlegroups.com
You're right. My apologies. The "content_length" method comes from Plack::Response and is not chainable. Don't chain it.

Stefan
Reply all
Reply to author
Forward
0 new messages