Bug 3239 - Content-Script-Type and Content-Style-Type
authorJoe Atzberger <joe.atzberger@liblime.com>
Fri, 22 May 2009 01:37:46 +0000 (20:37 -0500)
committerGalen Charlton <galen.charlton@liblime.com>
Fri, 22 May 2009 13:05:48 +0000 (08:05 -0500)
This adds headers to define the default script and style languages.
Please note that this output isn't 100% canonical from CGI yet, but
that is due to a bug in CGI:
  http://bugs.koha.org/cgi-bin/bugzilla3/show_bug.cgi?id=3243

So either CGI will perfect it's output, or we can switch to using
HTTP::Headers.  The latter may be desirable anyway, since then we
would not need a CGI $query argument at all.

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
C4/Output.pm

index f1cf80b..6604ae0 100644 (file)
@@ -373,37 +373,29 @@ sub output_with_http_headers($$$$;$) {
 
     my %content_type_map = (
         'html' => 'text/html',
-        'js' => 'text/javascript',
+        'js'   => 'text/javascript',
         'json' => 'application/json',
-        'xml' => 'text/xml',
+        'xml'  => 'text/xml',
         # NOTE: not using application/atom+xml or application/rss+xml because of
         # Internet Explorer 6; see bug 2078.
-        'rss' => 'text/xml',
+        'rss'  => 'text/xml',
         'atom' => 'text/xml'
     );
 
     die "Unknown content type '$content_type'" if ( !defined( $content_type_map{$content_type} ) );
-
-    if ($cookie) {
-        print $query->header(
-            -type    => $content_type_map{$content_type},
-            -status => $status,
-            -charset => 'UTF-8',
-            -cookie  => $cookie,
-            -Pragma => 'no-cache',
-            -'Cache-Control' => 'no-cache',
-        );
-    } else {
-        print $query->header(
-            -type    => $content_type_map{$content_type},
-            -status  => $status,
-            -charset => 'UTF-8',
-            -Pragma => 'no-cache',
-            -'Cache-Control' => 'no-cache',
-        );
+    my $options = {
+        type    => $content_type_map{$content_type},
+        status  => $status,
+        charset => 'UTF-8',
+        Pragma          => 'no-cache',
+        'Cache-Control' => 'no-cache',
+    };
+    $options->{cookie} = $cookie if $cookie;
+    if ($content_type eq 'html') {  # guaranteed to be one of the content_type_map keys, else we'd have died
+        $options->{'Content-Style-Type' } = 'text/css';
+        $options->{'Content-Script-Type'} = 'text/javascript';
     }
-
-    print $data;
+    print $query->header($options), $data;
 }
 
 sub output_html_with_http_headers ($$$) {