added proper mime type handling

git-svn-id: http://yolanda.mister-muffin.de/svn@252 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2008-03-09 19:32:24 +00:00
parent feb46a4574
commit eaeffc6fa2
2 changed files with 75 additions and 36 deletions

View file

@ -50,6 +50,7 @@ if($query->param('id'))
}
#in both cases - do some slurp-eaze to the browser
#TODO: lol insecure!
open(FILE, "<$root/videos/".$query->param('id'));
$filesize = -s "$root/videos/".$query->param('id');

View file

@ -142,36 +142,6 @@ sub output_page
my $parser = XML::LibXML->new();
my $xslt = XML::LibXSLT->new();
#let the XSLT param choose other stylesheets or default to xhtml.xsl
my $param_xslt = $query->param('xslt');
$param_xslt =~ s/[^\w]//gi;
if( -f "$root/xsl/$param_xslt.xsl")
{
$xsltpath = "$root/xsl/$param_xslt.xsl"
}
else
{
$xsltpath = "$root/xsl/xhtml.xsl";
}
my $stylesheet = $xslt->parse_stylesheet($parser->parse_file($xsltpath));
# TODO: this usage of libxsl omits the xsl:output definition (no ident of html) but outputs in UTF8
# TODO: later versions of XML::LibXSLT (>= 1.62) define output_as_bytes - this is what we want to use
# TODO: wait for debian packagers to update to 1.62 or later
# TODO: "foo" is not a meaningful variable name
$foo = $stylesheet->transform(
$parser->parse_string(
XMLout(
$page,
KeyAttr => {},
RootName => 'page',
AttrIndent => '1'
)
)
);
if($query->param('cortado') eq 'true')
{
@cookies = [$session->cookie(-name=>$session_name, -value=>$session->id), $session->cookie(-name=>'cortado', -value=>'true')];
@ -185,13 +155,81 @@ sub output_page
@cookies = [$session->cookie(-name=>$session_name, -value=>$session->id)];
}
#send everything including http headers to the user - if XSLT chosen is XSPF set download filename
return $session->header(
-type=>'application/xhtml+xml',
# TODO: fix the MIME type so that every XSLT works again
# (you earned eternal hate for this, josch)
#let the XSLT param choose other stylesheets or default to xhtml.xsl
my $param_xslt = $query->param('xslt');
$param_xslt =~ s/[^\w]//gi;
if($param_xslt eq "null")
{
$output = $parser->parse_string(
XMLout(
$page,
KeyAttr => {},
RootName => 'page',
AttrIndent => '1'
)
);
return $session->header(
-type=>'application/xml',
-charset=>'UTF-8',
-cookie=>@cookies
),
$foo->toString;
$output->toString;
}
else
{
if( -f "$root/xsl/$param_xslt.xsl")
{
$xsltpath = "$root/xsl/$param_xslt.xsl"
}
else
{
$xsltpath = "$root/xsl/xhtml.xsl";
}
my $stylesheet = $xslt->parse_stylesheet($parser->parse_file($xsltpath));
# TODO: this usage of libxsl omits the xsl:output definition (no ident of html) but outputs in UTF8
# TODO: later versions of XML::LibXSLT (>= 1.62) define output_as_bytes - this is what we want to use
# TODO: wait for debian packagers to update to 1.62 or later
$output = $stylesheet->transform(
$parser->parse_string(
XMLout(
$page,
KeyAttr => {},
RootName => 'page',
AttrIndent => '1'
)
)
);
if($param_xslt eq "xspf")
{
return $session->header(
-type=>'application/xspf+xml',
-charset=>'UTF-8',
-attachment=>$query->param('query').".xspf",
-cookie=>@cookies
),
$output->toString;
}
elsif($param_xslt eq "rss")
{
return $session->header(
-type=>'application/rss+xml',
-charset=>'UTF-8',
-cookie=>@cookies
),
$output->toString;
}
else
{
return $session->header(
-type=>'application/xhtml+xml',
-charset=>'UTF-8',
-cookie=>@cookies
),
$output->toString;
}
}
}