fix HTTP response headers for PDF files master
authorTroy Sankey <sankeytms@gmail.com>
Fri, 16 May 2014 20:00:10 +0000 (13:00 -0700)
committerTroy Sankey <sankeytms@gmail.com>
Fri, 16 May 2014 20:00:10 +0000 (13:00 -0700)
* calculate and return content-length
* remove charset

index.pl

index ad9da97..2906e57 100755 (executable)
--- a/index.pl
+++ b/index.pl
@@ -589,11 +589,15 @@ sub print_body_keylists {
       $filename = "keylist_$keylist_date_str.pdf";
     }
     binmode STDOUT, ':raw';  # this is binary PDF output, so don't use utf-8
+    my $pdf_bytes = get_pdf($party_idx);
+    use bytes; # use bytes as a measurement of length (instead of chars)
+    my $content_length = length($pdf_bytes);
     print $q->header(-expires=>'now',
                      -type=>'application/pdf',
                      -content_disposition=>"inline; filename=$filename",
-                     -charset=>"utf-8");
-    print get_pdf($party_idx);
+                     -charset=>"",
+                     -content_length=>"$content_length");
+    print $pdf_bytes;
   } elsif ($rel_url =~ /^(....-..-..)$/) {
     print $q->header(-type=>"text/html", -charset=>"utf-8");
     print $q->start_html(-title=>$page_title, -encoding=>"UTF-8");