# -------------------------------------------------------------------------------------
# flo::plugin::index::HTML
# -------------------------------------------------------------------------------------
#
#       Author : Jean-Michel Hiver (jhiver@cisedi.com).
#    Copyright : (c) MKDoc Holdings Ltd, 2001
# 
#      Unauthorized modification, use, reuse, distribution or redistribution
#      of this module is stricly forbidden
#
#    Description:
#
#      A plugin that is used to redirect HTTP requests that ask for
#      /something/index.html to /something/
#
# -------------------------------------------------------------------------------------
package flo::plugin::index::HTML;
use lib::Exception;
use flo::Standard;
use lib::sql::Table;
use lib::cgi::CGI;
use strict;


##
# $class->main;
# -------------
#   Redirects the HTTP query, if needed
##
sub main
{
    my $class = shift;
    my $cgi = cgi;
    my $raw_path_info = raw_path_info();    
    if ($raw_path_info eq '/index.html' or $raw_path_info eq '/index.htm')
    {
        $cgi->path_info ('/');
        print $cgi->redirect ($cgi->self_url);
        return 'TERMINATE';
    }
    if ($raw_path_info =~ /\/index\.html?$/)
    {
	$raw_path_info =~ s/\///;
	my @path = split /\//, $raw_path_info;
	pop (@path);
	my $new_path = join '/', @path;
	$new_path = '/' . $new_path . '/';
	$cgi->path_info ($new_path);
	print $cgi->redirect ($cgi->self_url);
	return 'TERMINATE';
    }
}


1;
