[Catalyst] Setting file handle as the response body generates warnings.

neil.lunn neil at mylunn.id.au
Thu Nov 21 02:04:30 GMT 2013


On 21/11/2013 11:48 AM, Bill Moseley wrote:
>
> Seems noncompliance may be rampant.
>
> Anyway, sounds like Catalyst isn't quite supporting this kind of file =

> handle as expected.   John, is there anything you would want me to try?
>

Hi Bill. Back to my original response, trying to get the size of this =

handle (or any other type of in memory handle) with a file stat operator =

will not work. What catalyst is trying to do:

$size =3D -s $response->body;

Because it reasonably expects you have provided a handle that can read =

and most importantly you have not provided a content length. Being the =

earlier conditional.

Thinking this through, if the file was on disk then -s would not return =

the uncompressed size. Which is what you want.

As for that not working for this type of handle ( aslo see something =

like IO::Scalar ), I can't see why Catalyst should be expected to do =

that for you. Which is why there is the provision to provide a =

content_length and avioding this fallback condition.

Your issue as I see it, is that something is borked on your setup with =

the Gzip implementation that is stopping you from getting the =

uncompressed size from the content. Therefore I suggest you start =

looking there.

Again I cannot see how or why Catalyst could or should be expected to =

work this out for you, and the best method is to set the correct =

content_length once you have sorted out the Gzip issue. Or failing that =

do you have some other way in your implementation to know the =

content_length when uncompressed.

As below just works, which is as near as I can see to what you are =

basically doing.


package Gzip::Web::Controller::Root;
use Moose;
use namespace::autoclean;

BEGIN { extends 'Catalyst::Controller' }

use IO::Compress::Gzip qw/gzip $GzipError/;
use IO::Uncompress::Gunzip;
use Data::Dumper;

__PACKAGE__->config(namespace =3D> '');

sub index :Path :Args(0) {
   my ( $self, $c ) =3D @_;

   my $data =3D "123456890ABCDEFGHIGQWERRTYYUIO";
   my ($comp, $body);

   gzip(\$data, \$comp) || die $GzipError;

   $c->res->content_type('text/plain');

   if ( $c->req->header('accept-encoding') =3D~ /gzip/ ) {
     $c->log->debug( 'Sending compressed' );
     $c->res->content_encoding('gzip');
     $body =3D $comp;
   } else {
     $c->log->debug( 'Sending uncompressed' );
     $body =3D IO::Uncompress::Gunzip->new( \$comp );
     $c->res->content_length( $body->getHeaderInfo->{ISIZE} );
     $c->log->debug( Dumper( $body->getHeaderInfo ) );
   }

   $c->res->body( $body );

}



>
>
> $ perl -MIO::Uncompress::Gunzip -le 'use Data::Dumper; print Dumper =

> +IO::Uncompress::Gunzip->new( "Catalyst-Runtime-5.90051.tar.gz" =

> )->getHeaderInfo'
> $VAR1 =3D {
>           'Time' =3D> 1383843952,
>           'Flags' =3D> 8,
>           'TextFlag' =3D> 0,
>           'MethodID' =3D> 8,
>           'ExtraField' =3D> [],
>           'CommentFlag' =3D> 0,
>           'Type' =3D> 'rfc1952',
>           'NameFlag' =3D> 1,
>           'ExtraFlags' =3D> 2,
>           'HeaderCRC' =3D> undef,
>           'isMinimalHeader' =3D> 0,
>           'MethodName' =3D> 'Deflated',
>           'ExtraFlag' =3D> 0,
>           'HeaderLength' =3D> 39,
>           'ExtraFieldRaw' =3D> undef,
>           'Comment' =3D> undef,
>           'OsName' =3D> 'Unix',
>           'FingerprintLength' =3D> 2,
>           'HeaderCRCFlag' =3D> 0,
>           'OsID' =3D> 3,
>           'TrailerLength' =3D> 8,
>           'Name' =3D> 'Catalyst-Runtime-5.90051.tar',
>           'Header' =3D> p?{RCatalyst-Runtime-5.90051.tar'
>         };
>
>
> -- =

> Bill Moseley
> moseley at hank.org <mailto:moseley at hank.org>
>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.u=
k/
> Dev site: http://dev.catalyst.perl.org/



---
This email is free from viruses and malware because avast! Antivirus protec=
tion is active.
http://www.avast.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20131121/a5085=
500/attachment.htm


More information about the Catalyst mailing list