You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Gavin Carr <ga...@openfusion.com.au> on 2000/09/14 13:29:18 UTC

Arbitrary handler return values from Embperl?

Hi Gerald et al,

I've got an Embperl page where I'd like to have Embperl stop
processing and return an Apache FORBIDDEN or DECLINED or some other
arbitrary handler return code if particular conditions are true.
Apache::exit does the stop but not the return code. I can think of a
few kludges, but was wondering if there's a nice elegant mechanism to
do this that I'm missing?

Thanks in advance,
Gavin


Re: Arbitrary handler return values from Embperl?

Posted by Gerald Richter <ri...@ecos.de>.
>
> I was guessing it might be because even though the status has been set
> manually Embperl as the handler is returning an OK?
>

Yes, you are guessing right...

> Any suggestions where to go from here?
>

If you don't want to return the status to the client, but triggering an
errordocument, you can use "die" ;

[- die -]
[- exit -]

exit must be in a separate block

This will trigger the 500 ErrorDocument.

$req_rec -> prev -> pnotes ('EMBPERL_ERRORS')

inside the errordocument will return an array ref to all error messages

Gerald




Re: Arbitrary handler return values from Embperl?

Posted by Gavin Carr <ga...@openfusion.com.au>.
Yeah I've tried this (and variations, with $optReturnError both ways
as well) but it doesn't seem to do the job - I just get a blank page,
and if an ErrorDocument is defined it doesn't get picked up. The
difference can be seen below, with the first being the embperl page
doing a [- $req_rec->status(404); exit; -], and the second a real
non-existent page:

	storm:~> telnet localhost 80
	Trying 127.0.0.1...
	Connected to localhost.localdomain.
	Escape character is '^]'.
	GET /fail.ehtml HTTP/1.0
	 
	HTTP/1.1 404 Not Found
	Date: Fri, 15 Sep 2000 01:31:06 GMT
	Server: Apache/1.3.12 (Unix) mod_perl/1.24
	Content-Length: 2
	Connection: close
	Content-Type: text/html
	 
	Connection closed by foreign host.

vs. 

	storm:~> telnet localhost 80
	Trying 127.0.0.1...
	Connected to localhost.localdomain.
	Escape character is '^]'.
	GET /foobar.html HTTP/1.0
	 
	HTTP/1.1 404 Not Found
	Date: Fri, 15 Sep 2000 01:31:17 GMT
	Server: Apache/1.3.12 (Unix) mod_perl/1.24
	Connection: close
	Content-Type: text/html; charset=iso-8859-1
	 
	<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
	<HTML><HEAD>
	<TITLE>404 Not Found</TITLE>
	</HEAD><BODY>
	<H1>Not Found</H1>
	The requested URL /foobar.ehtml was not found on this server.<P>
	<HR>
	<ADDRESS>Apache/1.3.12 Server at storm Port 80</ADDRESS>
	</BODY></HTML>
	Connection closed by foreign host.

I was guessing it might be because even though the status has been set
manually Embperl as the handler is returning an OK?

Any suggestions where to go from here?

Cheers,
Gavin

On Thu, Sep 14, 2000 at 03:07:07PM +0200, Gerald Richter wrote:
> There isn't a possibility to return DECLINED, but you can set arbitarry http
> status codes by using the Apache API:
> 
> [-
> $req_rec -> status (401) ;
> exit ;
> -]
> 
> See "perldoc Apache" for more details
> 
> Gerald
>
> > I've got an Embperl page where I'd like to have Embperl stop
> > processing and return an Apache FORBIDDEN or DECLINED or some other
> > arbitrary handler return code if particular conditions are true.
> > Apache::exit does the stop but not the return code. I can think of a
> > few kludges, but was wondering if there's a nice elegant mechanism to
> > do this that I'm missing?

Re: Arbitrary handler return values from Embperl?

Posted by Gerald Richter <ri...@ecos.de>.
>
> I've got an Embperl page where I'd like to have Embperl stop
> processing and return an Apache FORBIDDEN or DECLINED or some other
> arbitrary handler return code if particular conditions are true.
> Apache::exit does the stop but not the return code. I can think of a
> few kludges, but was wondering if there's a nice elegant mechanism to
> do this that I'm missing?
>

There isn't a possibility to return DECLINED, but you can set arbitarry http
status codes by using the Apache API:

[-
$req_rec -> status (401) ;
exit ;
-]

See "perldoc Apache" for more details

Gerald


-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------