You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jonathan Vanasco <mo...@2xlp.com> on 2007/05/03 21:09:48 UTC

Apache::Request question

I'm posting to mp , as this is perl-glue related.

as a note, I'm using OS X as a dev box , and apreq doesn't compile  
right on it - so that might be the problem

-----

i'm standardizing my some functions to release into cpan and am at a  
bit of a loss on catching apreq errors.

I have this code:

my 	$want_to_die= 0;
my	 $req;	
eval {
	$req= Apache2::Request->new( $r , %apr_args );
		$r->discard_request_body;
	my 	$args_status = $req->args_status ;
	my 	$body_status = $req->body_status ;
	my 	$param_status= $req->param_status ;

	print STDERR "\n args_status $args_status || " . ( ref $args_status );
	print STDERR "\n body_status  $body_status || " . ( ref $body_status );
	print STDERR "\n param_status $param_status ||" . ( ref  
$param_status );

	my 	$body;
	if ( $want_to_die ) {
		my 	$body = $req->body ;
		print STDERR "\n body $body ||" . ( ref $body );
	}

};
	print STDERR "$@ || " . ( ref $@ );

The behavior I've observed is:

	If there is no POST , param_status + body_status are 'Missing input  
data'
	If there is POST, but its too big, param_status + body_status is  
'Exceeds configured maximum limit'
	If i submit any query string GET args, args_status is "Unknown  
error: 0"
	If i submit no query string / GET args, args_status is "Missing  
input data"

	if i try to access the body on an overlimit, THEN i'll pull an error  
into $@.  ( $want_to_die= 1 )

The issue I have is:
	All of the _status returns are just plain strings,
	The text I get on what seems to be valid calls doesn't make sense:  
Missing input data / Unknown error -- those look like errors to me.   
but they're not.
	The only way I can seem to pull an actual error is accessng the body/ 
param directly , and ignoring the object.

So : Is there a standardized way I can test for having an error or  
not ? and are my status strings giving me the correct info ?



// Jonathan Vanasco

| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -
| SyndiClick.com
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -
|      FindMeOn.com - The cure for Multiple Web Personality Disorder
|      Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -
|      RoadSound.com - Tools For Bands, Stuff For Fans
|      Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -



Re: Apache::Request question

Posted by Clinton Gormley <cl...@traveljury.com>.
> Ok.  that answers a ton.
> 
> Word-for-word, that should be in the PerlGlue docs.
> 

libapreq is great, but the docs are seriously lacking.

I implemented my own wrapper for it, but it required a lot of delving
into the Apache2/APR::Request code to figure out how to make it work.
Non-trivial to say the least.

When I have some time, I'll try to write some decent docs / tutorials,
and then send them here for somebody who knows to check that I have
understood it correctly!

Of course, if anybody else has time....

clint


Re: Apache::Request question

Posted by Jonathan Vanasco <jv...@2xlp.com>.
On May 3, 2007, at 9:44 PM, Joe Schaefer wrote:
>
> The "Unknown Error" string is operating system dependent. On
> my linux box it would be reported as "Success", since the error
> code in any case is 0.  "Missing input data" comes from the
> apreq ala APR::Request::Error::NODATA, and counts as a trivial
> error (since there's nothing to parse).  FWIW, here's the
> code for apreq_module_status_is_error:

Ok.  that answers a ton.

Word-for-word, that should be in the PerlGlue docs.

> static APR_INLINE
> unsigned apreq_module_status_is_error(apr_status_t s) {
> ==snip==
> Everything else triggers a die in $req->args or $req->body.
> Perhaps we should expose that function in the perl glue?

yeah - that would be great.  that has been what is so confusing about  
the perl glue -- its really hard to tell when an error is really an  
error.


Re: Apache::Request question

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Jonathan Vanasco <jv...@2xlp.com> writes:

> On May 3, 2007, at 9:19 PM, Joe Schaefer wrote:
>
>> Here's what I was alluding to on apreq-dev when you asked about it:
>
> that code makes sense...
>
> it makes me wonder more though:
>
> a)
> 	what's the deal with
> 		Missing input data
> 		Unknown Error : 0

The "Unknown Error" string is operating system dependent. On
my linux box it would be reported as "Success", since the error
code in any case is 0.  "Missing input data" comes from the 
apreq ala APR::Request::Error::NODATA, and counts as a trivial
error (since there's nothing to parse).  FWIW, here's the 
code for apreq_module_status_is_error:

static APR_INLINE
unsigned apreq_module_status_is_error(apr_status_t s) {
    switch (s) {
    case APR_SUCCESS:
    case APR_INCOMPLETE:
    case APR_EINIT:
    case APREQ_ERROR_NODATA:
    case APREQ_ERROR_NOPARSER:
    case APREQ_ERROR_NOHEADER:
        return 0;
    default:
        return 1;
    }
}

Everything else triggers a die in $req->args or $req->body.
Perhaps we should expose that function in the perl glue?

-- 
Joe Schaefer

Re: Apache::Request question

Posted by Jonathan Vanasco <jv...@2xlp.com>.
On May 3, 2007, at 9:19 PM, Joe Schaefer wrote:

> Here's what I was alluding to on apreq-dev when you asked about it:

that code makes sense...

it makes me wonder more though:

a)
	what's the deal with
		Missing input data
		Unknown Error : 0

	are those trivial errors?
	are those success messages ?

	I'm just lost as to why I see what seems to be error messages on  
what seems to be ok parses

b)
	is there a way to catch the error as being major / not trivial with  
a call to body_status ( instead of trying to read body )
	if i read body, i get the $@ die / exception / error object
	if i call body_status, i just get the string message -- which is  
fine -- but i can't tell the difference between success , major  
error , trivial error

i'm trying to do an abstraction class that will catch + log the  
body_status errors on my dispatcher -- before the body is used within  
some dispatched module.    i could toss the info in a pnote or  
something , but I'd rather just read + undef the variable in a single  
location


Re: Apache::Request question

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Jonathan Vanasco <mo...@2xlp.com> writes:

> i'm standardizing my some functions to release into cpan and am at a bit of a
> loss on catching apreq errors.

Here's what I was alluding to on apreq-dev when you asked about it:

   my $body = eval { $req->body };
   if ($@) {
      if ($@ == APR::Request::Error::OVERLIMIT) {
       ... $@ is an APR::Request::Error object 
            which can be stringified or numified ...
      }
      elsif ($@ == ...) {
      ...
      }
   }

The reason for that approach is that $req->body won't die
on "trivial" errors (as determined by the C function 
apreq_module_status_is_error()), so you only need to check 
for non-trivial ones.  Does this not work for you?

-- 
Joe Schaefer


Re: Apache::Request question

Posted by Jonathan Mangin <jo...@comcast.net>.
Sorry, I don't know the answer.
My little testing on Solaris gives me similar results,
and I'd like to back up your request.


----- Original Message ----- 
From: "Jonathan Vanasco" <mo...@2xlp.com>
To: "modperl mod_perl" <mo...@perl.apache.org>
Sent: Thursday, May 03, 2007 3:09 PM
Subject: Apache::Request question


> I'm posting to mp , as this is perl-glue related.
> 
> as a note, I'm using OS X as a dev box , and apreq doesn't compile  
> right on it - so that might be the problem
> 
> -----
> 
> i'm standardizing my some functions to release into cpan and am at a  
> bit of a loss on catching apreq errors.
> 
> I have this code:
> 
> my $want_to_die= 0;
> my $req; 
> eval {
> $req= Apache2::Request->new( $r , %apr_args );
> $r->discard_request_body;
> my $args_status = $req->args_status ;
> my $body_status = $req->body_status ;
> my $param_status= $req->param_status ;
> 
> print STDERR "\n args_status $args_status || " . ( ref $args_status );
> print STDERR "\n body_status  $body_status || " . ( ref $body_status );
> print STDERR "\n param_status $param_status ||" . ( ref  
> $param_status );
> 
> my $body;
> if ( $want_to_die ) {
> my $body = $req->body ;
> print STDERR "\n body $body ||" . ( ref $body );
> }
> 
> };
> print STDERR "$@ || " . ( ref $@ );
> 
> The behavior I've observed is:
> 
> If there is no POST , param_status + body_status are 'Missing input  
> data'
> If there is POST, but its too big, param_status + body_status is  
> 'Exceeds configured maximum limit'
> If i submit any query string GET args, args_status is "Unknown  
> error: 0"
> If i submit no query string / GET args, args_status is "Missing  
> input data"
>
>
GET with a query string returns "Error 0".
The docs say "...APR_SUCCESS on success, error otherwise".
I'd like to know where Error 0 is defined, what it means, and
how it possibly knows it wasn't successful.



> 
> if i try to access the body on an overlimit, THEN i'll pull an error  
> into $@.  ( $want_to_die= 1 )
> 
> The issue I have is:
> All of the _status returns are just plain strings,
> The text I get on what seems to be valid calls doesn't make sense:  
> Missing input data / Unknown error -- those look like errors to me.   
> but they're not.
> The only way I can seem to pull an actual error is accessng the body/ 
> param directly , and ignoring the object.
> 
> So : Is there a standardized way I can test for having an error or  
> not ? and are my status strings giving me the correct info ?
> 
> 
> 
> // Jonathan Vanasco
>