Practice of Programming

プログラム とか Linuxとかの話題

HTTP::Server::SimpleでPATH_INFOのslashがunencodeされるのを防ぐ

apache2だと、オプションを与えてやるらしいです。

これを解消するにはAllowEncodedSlashesをOnにします。

AllowEncodedSlashes On

http://kawama.jp/archives/2007/04/path_info2f404a.html

HTTP::Server::Simple::CGI使ってるんですが、これも、/ をunencodeしちゃって調子悪いので、適当に上書いてみた。

use ExportTo ('+HTTP::Server::Simple::CGI::Environment' =>
 {
  setup_environment_from_metadata => sub{
    no warnings 'uninitialized';
    my $self = shift;

    # XXX TODO: rather than clone functionality from the base class,
    # we should call super
    #
    while ( my ( $item, $value ) = splice @_, 0, 2 ) {
      if ( my $k = $HTTP::Server::Simple::CGI::Environment::ENV_MAPPING{$item} ) {
        $ENV{$k} = $value;
      }
    }

    # Apache and lighttpd both do one layer of unescaping on
    # path_info; we should duplicate that.
    $ENV{PATH_INFO} =~s{%2F}{\0}g;
    $ENV{PATH_INFO} = URI::Escape::uri_unescape($ENV{PATH_INFO});
    $ENV{PATH_INFO} =~s{\0}{%2F}g;
  }});