thanks Charles, I think your patch is the way to go for now, or something
close to it for 1.22

On Thu, 13 Jan 2000, Charles Levert wrote:

> Hi.
> 
> [ I use Apache 1.3.9 and mod_perl 1.21. ]
> 
> I believe that there is a difference between the following two
> behaviors for an Apache module handler:
> 
>       -- setting the request's status field to a new value and also
>       returning that value;
> 
>       -- just returning a value without assigning it to the
>       request's status field.
> 
> It's an useful thing that a mod_perl script (what
> Apache::Registry::handler calls) be able to decide that, e.g.,
> HTTP_NOT_FOUND, should be returned to the browser and just return
> then.
> 
>       # example mod_perl script
> 
>       use Apache::Constants ':response';
>       my $r = Apache->request;
> 
>       if (...) {
>               $r->status(NOT_FOUND);
>               return;
>       }
> 
>       $r->content_type('text/html');
>       ...
> 
> We then expect that the normal ErrorDocument, as configured, should be
> returned in that case.  However, this is not what happens because
> Apache::Registry chooses the first behavior listed above and so an
> HTTP_NOT_FOUND also seems to apply to the ErrorDocument then.  (This
> is what Apache reports to the browser.)  The useful behavior would be
> the second one listed above.
> 
> Ideally, a method such as $r->return_value could be defined,
> independently of $r->status, and its argument could then be used when
> Apache::Registry::handler returns.  An other possibility which can
> probably be ruled out for compatibily with CGI scripts and existing
> mod_perl script is to use the return value from the mod_perl script
> itself.
> 
> I have appended a patch to Apache::Registry below which I believe to
> be an acceptable solution for now.  (It really disallows a script to
> set the status field, but uses the possibly changed status field as
> return value instead and resets the status field to its original
> value.)
> 
> Your comments are welcome.  Do you think that such a change or what I
> mention above ($r->return_value) should make it in the main
> distribution of mod_perl?
> 
> 
> Charles
> 
> 
> ========================================================================
> --- Registry.pm.orig-1.21     Tue Jan 12 21:56:34 1999
> +++ Registry.pm       Thu Jan 13 16:11:23 2000
> @@ -131,6 +131,8 @@
>           $Apache::Registry->{$package}{'mtime'} = $mtime;
>       }
>  
> +     my $old_status = $r->status;
> +
>       my $cv = \&{"$package\::handler"};
>       eval { &{$cv}($r, @_) } if $r->seqno;
>       $r->chdir_file("$Apache::Server::CWD/");
> @@ -155,7 +157,7 @@
>  #            return REDIRECT;
>  #        }
>  #    }
> -     return $r->status;
> +     return $r->status($old_status);
>      } else {
>       return NOT_FOUND unless $Debug && $Debug & 2;
>       return Apache::Debug::dump($r, NOT_FOUND);
> ========================================================================
> 

Reply via email to