From 8fc6b927dfae962f2e5df2f4928bb9c9a12e597d Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Mon, 2 Jun 2008 09:05:04 -0500 Subject: [PATCH] kohabug 2078 - send correct Content-type for search feeds OPAC search RSS and ATOM feeds now have the correct Content-type sent - "application/rss+xml" and "application/atom+xml", respectively. As part of this patch, added an optional fourth parameter to C4::Output::output_html_with_http_headers to specify the content type. If that parameter is now supplied, or if the value of the parameter does not contain at least a "/", the default type of "text/html" is returned. No documentation changes. Signed-off-by: Joshua Ferraro --- C4/Output.pm | 17 ++++++++++++----- opac/opac-search.pl | 5 ++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/C4/Output.pm b/C4/Output.pm index 5af9ef1882..2209ebb830 100644 --- a/C4/Output.pm +++ b/C4/Output.pm @@ -35,7 +35,7 @@ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); BEGIN { # set the version for version checking - $VERSION = 3.02; + $VERSION = 3.03; require Exporter; @ISA = qw(Exporter); @EXPORT_OK = qw(&output_ajax_with_http_headers &is_ajax); # More stuff should go here instead @@ -342,18 +342,25 @@ sub pagination_bar { =item output_html_with_http_headers - &output_html_with_http_headers($query, $cookie, $html) + &output_html_with_http_headers($query, $cookie, $html[, $content_type]) Outputs the HTML page $html with the appropriate HTTP headers, with the authentication cookie $cookie and a Content-Type that corresponds to the HTML page $html. +If the optional C<$content_type> parameter is called, set the +response's Content-Type to that value instead of "text/html". + =cut -sub output_html_with_http_headers ($$$) { - my($query, $cookie, $html) = @_; +sub output_html_with_http_headers ($$$;$) { + my $query = shift; + my $cookie = shift; + my $html = shift; + my $content_type = @_ ? shift : "text/html"; + $content_type = "text/html" unless $content_type =~ m!/!; # very basic sanity check print $query->header( - -type => 'text/html', + -type => $content_type, -charset => 'UTF-8', -cookie => $cookie, -Pragma => 'no-cache', diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 776ce554be..7c9b684227 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -577,4 +577,7 @@ if ( C4::Context->preference("kohaspsuggest") ) { } # VI. BUILD THE TEMPLATE -output_html_with_http_headers $cgi, $cookie, $template->output; +my $content_type = $cgi->param('format') =~ /rss/ ? "application/rss+xml" : + $cgi->param('format') =~ /atom/ ? "application/atom+xml" : + "text/html"; +output_html_with_http_headers $cgi, $cookie, $template->output, $content_type; -- 2.39.5