Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Send filename header if applicable

  • Loading branch information...
commit 6b8fb253b65bc4ab515a987021933403133371de 1 parent 0f02a6a
@pudge pudge authored
Showing with 13 additions and 1 deletion.
  1. +13 −1 Slash/XML/XML.pm
View
14 Slash/XML/XML.pm
@@ -71,6 +71,13 @@ Boolean for whether to print (false) or return (true) the
processed template data. Default is to print output via
Apache, with full HTML headers.
+=item filename
+
+A name for the generated filename Apache sends out. "Unsafe"
+chars are replaced, and ".xml" is appended if there is no "."
+in the name already. "foo bar" becomes "foo_bar.xml" and
+"foo bar.rss" becomes "foo_bar.rss".
+
=back
=back
@@ -111,8 +118,13 @@ sub xmlDisplay {
return $content;
} else {
my $r = Apache->request;
- $r->header_out('Cache-Control', 'private');
$r->content_type('text/xml');
+ $r->header_out('Cache-Control', 'private');
+ if ($opt->{filename}) {
+ $opt->{filename} =~ s/[^\w.-]/_/;
+ $opt->{filename} .= '.xml' unless $opt->{filename} =~ /\./;
+ $r->header_out('Content-Disposition', "filename=$opt->{filename}");
+ }
$r->status(200);
$r->send_http_header;
return 1 if $r->header_only;
Please sign in to comment.
Something went wrong with that request. Please try again.