X-Git-Url: https://git.deb.at/?a=blobdiff_plain;f=lib%2FPackages%2FDoIndex.pm;h=064a18ad2aa4b386c336dccc3d01af144ca25a0e;hb=a38d98d27880c8fc0f4d98646e318ecc1d39884f;hp=3e6041d26d03a735459e3e59301ccd58333a99b4;hpb=e23d2d2080a904ddd6d989a878f3c9b164f0a075;p=deb%2Fpackages.git diff --git a/lib/Packages/DoIndex.pm b/lib/Packages/DoIndex.pm index 3e6041d..064a18a 100644 --- a/lib/Packages/DoIndex.pm +++ b/lib/Packages/DoIndex.pm @@ -12,10 +12,26 @@ use Packages::I18N::Locale; use Packages::CGI; our @ISA = qw( Exporter ); -our @EXPORT = qw( do_index ); +our @EXPORT = qw( do_index do_allpackages ); sub do_index { - my ($params, $opts, $html_header) = @_; + return send_file( 'index', @_ ); +} +sub do_allpackages { + return send_file( 'allpackages', @_ ); +} + +# no real need for more flexibility here, I think... +my %mime_types = ( + txt => 'text/plain', + 'txt.gz' => 'text/plain', + html => 'text/html', + ); +my %encoding = ( + 'txt.gz' => 'x-gzip', + ); +sub send_file { + my ($file, $params, $opts, $html_header) = @_; if ($params->{errors}{suite}) { fatal_error( _g( "suite not valid or not specified" ) ); @@ -32,14 +48,17 @@ sub do_index { $path .= "$opts->{archive}[0]/" if @{$opts->{archive}} == 1; $path .= "$opts->{subsection}[0]/" if @{$opts->{subsection}}; # we don't have translated index pages for subsections yet - $opts->{lang} = 'en' if @{$opts->{subsection}}; - $path .= "index.$opts->{lang}.html"; + $opts->{lang} = 'en' if @{$opts->{subsection}} or $file eq 'allpackages'; + $path .= "$file.$opts->{lang}.$opts->{format}"; unless (@Packages::CGI::fatal_errors) { my $buffer; if (open( INDEX, '<', "$wwwdir/$path" )) { - my $charset = get_charset( $opts->{lang} ); - print header( -charset => $charset ); + my %headers; + $headers{'-charset'} = get_charset( $opts->{lang} ); + $headers{'-type'} = $mime_types{$opts->{format}} || 'text/plain'; + $headers{'-content-encoding'} = $encoding{$opts->{format}} if exists $encoding{$opts->{format}}; + print header( %headers ); binmode INDEX; while (read INDEX, $buffer, 4096) { @@ -64,7 +83,7 @@ sub do_index { suite => 'all', section => 'all', exact => 1, - debug => $Packages::Search::debug, + debug => $Packages::CGI::debug, }, ); }