Re: Custom PerlResponseHandler for a subrequest

Jan Pazdziora <[email protected]> Tue, 4 Jun 2024 17:55:52 +0200
Newsgroups gmane.comp.apache.mod-perl
Message-ID <[email protected]>
On Tue, Jun 04, 2024 at 03:35:06PM +0200, Jan Kasprzak wrote:
> 	Hello,
> 
> I am trying to do something like this in PerlAuthenHandler,
> and it mostly works:
> 
> sub auth_handler {
> 	my ($r) = @_;
> 	...
> 	if ($cond) {
> 		$r->set_handlers(PerlResponseHandler => sub {
> 			my ($r) = @_;
> 			$r->content_type('text/plain');
> 			$r->print("custom handler was here\n");
> 			return Apache2::Const::OK;
> 		});
> 		$r->user('dummy-user-for-a-dummy-handler');
> 		return Apache2::Const::OK;
> 	}
> 	...
> }
> 
> when $cond happens, I get 200 OK with "custom handler was here"
> instead of whatever is configured as PerlResponseHandler in httpd.conf.
> So far good.

[...]

> Then for requests meeting $cond above I get the following:
> 
> https://example.com/directory -> 302 to /directory/ (trailing slash, OK)
> https://example.com/directory/ -> 200 with custom handler as expected
> https://example.com/directory/index.pl -> 200 with custom handler as expected
> https://example.com/directory/index -> 200 from My::Ordinary::Handler - FAIL
> https://example.com/directory/foo.pl -> 200 with custom handler as expected
> https://example.com/directory/foo -> 200 from My::Ordinary::Handler - FAIL
> 
> It seems that the auth_handler gets called for all the above requests,
> but for the failed ones mod_rewrite creates subrequests, which do not inherit
> the custom PerlResponseHandler set by auth_handler(). How can I replace
> a PerlResponseHandler even for a subrequest? Or how can I tap to a subrequest
> creation? Or how can I bypass mod_rewrite from within the PerlAuthenHandler
> and return my own 200 OK response immediately?

Are you able to check / configure some logging to see if that
auth_handler was called at all in the redirect / subrequest case,
and if the $cond was found true there?

Do you still see the dummy-user-for-a-dummy-handler logged (with
My::Ordinary::Handler content), or is that user information missing
as well?

How is that auth_handler configured / enabled anyway?

-- 
Jan Pazdziora