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 = -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 => '');

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

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

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

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

  if ( $c->req->header('accept-encoding') =~ /gzip/ ) {
    $c->log->debug( 'Sending compressed' );
    $c->res->content_encoding('gzip');
    $body = $comp;
  } else {
    $c->log->debug( 'Sending uncompressed' );
    $body = 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 = {
          'Time' => 1383843952,
          'Flags' => 8,
          'TextFlag' => 0,
          'MethodID' => 8,
          'ExtraField' => [],
          'CommentFlag' => 0,
          'Type' => 'rfc1952',
          'NameFlag' => 1,
          'ExtraFlags' => 2,
          'HeaderCRC' => undef,
          'isMinimalHeader' => 0,
          'MethodName' => 'Deflated',
          'ExtraFlag' => 0,
          'HeaderLength' => 39,
          'ExtraFieldRaw' => undef,
          'Comment' => undef,
          'OsName' => 'Unix',
          'FingerprintLength' => 2,
          'HeaderCRCFlag' => 0,
          'OsID' => 3,
          'TrailerLength' => 8,
          'Name' => 'Catalyst-Runtime-5.90051.tar',
          'Header' => p?{RCatalyst-Runtime-5.90051.tar'
        };


--
Bill Moseley
mose...@hank.org <mailto:mose...@hank.org>


_______________________________________________
List: Catalyst@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.uk/
Dev site: http://dev.catalyst.perl.org/



---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com
_______________________________________________
List: Catalyst@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.uk/
Dev site: http://dev.catalyst.perl.org/

Reply via email to