<%init>
if ( $m->dhandler_arg !~ /^[0-9a-f]{32}\.css$/ ) {
    # This doesn't look like a real request for squished CSS,
    # so redirect to a more failsafe place
    Jifty->web->redirect( "/static/css/" . $m->dhandler_arg );
}

Jifty->web->generate_css;

use HTTP::Date ();

if ( Jifty->handler->cgi->http('If-Modified-Since')
        and $m->dhandler_arg eq Jifty->web->cached_css_digest . '.css' )
{
    Jifty->log->debug("Returning 304 for cached css");
    $r->header_out( Status => 304 );
    return;
}

$r->content_type("text/css");
$r->header_out( 'Expires' => HTTP::Date::time2str(time + 31536000) );

# XXX TODO: If we start caching the squished CSS in a file somewhere, we
# can have the static handler serve it, which would take care of gzipping
# for us.
use Compress::Zlib qw();

if ( Jifty::View::Static::Handler->client_accepts_gzipped_content ) {
    Jifty->log->debug("Sending gzipped squished CSS");
    $r->header_out( "Content-Encoding" => "gzip" );
    binmode STDOUT;
    print Compress::Zlib::memGzip( Jifty->web->cached_css );
}
else {
    Jifty->log->debug("Sending squished CSS");
    print Jifty->web->cached_css;
}
return;
</%init>
