gwhite has asked for the wisdom of the Perl Monks concerning the following question:

I have a CGI script that runs on various server platforms, one section creates accounting data in one of several different file formats, the user clicks a link to view the file, which launches the same cgi which grabs the file and delivers it to the browser. This works fine with HTTP protocol, but does not work properly with HTTPS (for instance with XLS it opens the spreadsheet but without any contents). Here is a snippet of code where the file gets written (using the CGI.pm module):
if ($input->param('view')) { if($format eq 'pdf') { print $input->header(-type=>'application/pdf'); } if($format eq 'xls') { print $input->header(-type=>'application/vnd.ms-excel'); } if($format eq 'xml') { print $input->header(-type=>'text/xml'); } if($format eq 'csv') { print $input->header(-type=>'text/plain'); } binmode STDOUT; open (REPORT , "< " . $output_file_name); sysread REPORT, my $content, -s REPORT; print $content; close REPORT; exit; }
I can't seem to find anything saying this should or shouldn't work. Yes the files have contents, I can download them from the server via FTP and they are fine or if I call from the server using HTTP it works fine.

g_White

Replies are listed 'Best First'.
Re: Deliver a file via HTTPS
by pbeckingham (Parson) on Jul 07, 2004 at 20:17 UTC

    You could convert all that logic to:

    my %mimeTypes = ( 'pdf' => 'application/pdf', 'xls' => 'application/vnd.ms-excel', 'xml' => 'text/xml', 'csv' => 'text/plain');
    Then simply key into the hash with $format. I also suggest not using binmode STDOUT when the MIME type is text/plain.