comparison Lib/IMPL/Web/QueryHandler/PageFormat.pm @ 162:39c8788eded5

corrected PATH_INFO handling
author wizard
date Wed, 29 Dec 2010 16:55:24 +0300
parents 3f09584bf189
children 4267a2ac3d46
comparison
equal deleted inserted replaced
161:47c9877ccacc 162:39c8788eded5
18 18
19 BEGIN { 19 BEGIN {
20 public property templatesCharset => prop_all; 20 public property templatesCharset => prop_all;
21 public property templatesBase => prop_all; 21 public property templatesBase => prop_all;
22 public property includes => prop_all | prop_list; 22 public property includes => prop_all | prop_list;
23 public property defaultTarget => prop_all;
24 public property pathinfoPrefix => prop_all; 23 public property pathinfoPrefix => prop_all;
25 public property cache => prop_all; 24 public property cache => prop_all;
26 public property preprocess => prop_all; 25 public property preprocess => prop_all;
27 public property formatOutput => prop_all; 26 public property formatOutput => prop_all;
28 public property template => prop_all; 27 public property template => prop_all;
46 $this->templatesBase($ENV{DOCUMENT_ROOT}) unless $this->templatesBase; 45 $this->templatesBase($ENV{DOCUMENT_ROOT}) unless $this->templatesBase;
47 46
48 my ($requestUri) = split /\?/, $ENV{REQUEST_URI}; 47 my ($requestUri) = split /\?/, $ENV{REQUEST_URI};
49 48
50 my $pathInfo; 49 my $pathInfo;
50 my @root = ('');
51 my @base;
51 52
52 if ( $requestUri eq $ENV{SCRIPT_NAME}.$ENV{PATH_INFO} ) { 53 if ( $requestUri eq $ENV{SCRIPT_NAME}.$ENV{PATH_INFO} ) {
53 # CGI with path info 54 # CGI with path info, for example
55 # /base/cgi-bin/myscript.cgi/path/info
56 # PATH_INFO will be /path/info
54 $pathInfo = $ENV{PATH_INFO}; 57 $pathInfo = $ENV{PATH_INFO};
55 } else { 58 } else {
56 die "REQUEST_URI: $requestUri\nPATH_INFO: $ENV{PATH_INFO}" unless $requestUri eq $ENV{PATH_INFO}; 59 # usual url, for exmaple
60 # /base/script.cgi will have PATH_INFO /base/script.cgi
61 # /base/ will have PATH_INFO /base/index.cgi (if index.cgi is a DirectoryIndex)
62 $pathInfo = $ENV{PATH_INFO};
63
64 if (my $rx = $this->pathinfoPrefix) {
65 $requestUri =~ s/^($rx)//;
66 $pathInfo =~ s/^($rx)//;
67 push @root, grep $_, split /\//, $1 if $1;
68 }
57 } 69 }
58 70
59 my @root = ('');
60 my @base;
61
62 if (my $rx = $this->pathinfoPrefix) {
63 $requestUri =~ s/^($rx)//;
64 push @root, grep $_, split /\//, $1 if $1;
65 }
66
67 $pathInfo = $requestUri unless defined $pathInfo;
68
69 @base = grep $_, split /\//, ($pathInfo ? substr $requestUri,0, -length($pathInfo) : $requestUri); 71 @base = grep $_, split /\//, ($pathInfo ? substr $requestUri,0, -length($pathInfo) : $requestUri);
70 72
71 local $ENV{PATH_INFO} = $pathInfo || $this->defaultTarget; 73 local $ENV{PATH_INFO} = $pathInfo;
72 74
73 my @path = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("PATH_INFO is empty and no defaultTarget specified" ); 75 my @path = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("PATH_INFO is empty and no defaultTarget specified" );
74 76
75 my @pathContainer = @path; 77 my @pathContainer = @path;
76 pop @pathContainer; 78 pop @pathContainer;