Re: mod_perl Apache2 RequestRec allowed problem

2007-10-09 Thread Christopher Stanton
$r->allowed_methods($reset, $list) only seems to respect the reset
flag if the return code from the handler is either
Apache2::Const::HTTP_METHOD_NOT_ALLOWED or
Apache2::Const::HTTP_NOT_IMPLEMENTED which is not in the
documentation.

The OPTIONS request is supposed to be URI/resource specific (unless
the URI is '*') but Apache seems to be treating it as '*' plus
whatever other additional options I set. OPTIONS is supposed to return
the set of methods available for the specific URI.

So can anyone shed some light on why Apache is ignoring the reset flag
when I am returning Apache2::Const::DECLINED?

And why $r->allowed() does not work as advertised in the documentation?

And which way is the proper/standard way of:
1) setting the "Allow" header field when responding to an OPTIONS
request on a URI
2) returing from handling an OPTIONS request. is it Apache2::Const::DECLINED?
2) setting the "Allow" header field when responding with either
HTTP_METHOD_NOT_ALLOWED or HTTP_NOT_IMPLEMENTED return codes

I have included a basic example handler and and returned output below.
The Allow hearder field for both OPTION and GET requests should be the
same, but as you can see, they are not.

I am using:
Fedora Core 6
Apache 2.2.4-2.1
mod_perl 2.0.2-6.2

thanks,
Christopher

--

sub handler {
  my $r = shift;
  my $status_code = Apache2::Const::SERVER_ERROR;

  if ($r->method eq "OPTIONS"){
$r->allow_methods(1, qw(PUT DELETE));
$status_code = Apache2::Const::DECLINED;
  } else {
$r->allow_methods(1, qw(PUT DELETE));
$status_code = Apache2::Const::HTTP_METHOD_NOT_ALLOWED;
  }
  return $status_code
}

--

#curl -D header.txt -X OPTIONS http://localhost:9080/somedir
#cat header.txt
HTTP/1.1 200 OK
Date: Tue, 09 Oct 2007 22:10:58 GMT
Server: Apache/2.2.4 (Fedora)
Allow: GET,HEAD,POST,OPTIONS,DELETE,PUT,TRACE
Content-Length: 0
Connection: close
Content-Type: text/plain; charset=UTF-8

--

#curl -D header.txt -X GET http://localhost:9080/somedir
#cat header.txt
HTTP/1.1 405 Method Not Allowed
Date: Tue, 09 Oct 2007 22:14:26 GMT
Server: Apache/2.2.4 (Fedora)
Allow: DELETE,PUT,TRACE
Content-Length: 308
Connection: close
Content-Type: text/html; charset=iso-8859-1


Re: mod_perl Apache2 RequestRec allowed problem

2007-10-09 Thread Christopher Stanton
Thanks for the reply Geoffrey.

I have updated the code to use $r->allow_methods rather than
$r->allowed per the documentation at:
http://perl.apache.org/docs/2.0/api/Apache2/Access.html#C_allow_methods_

Now additional methods are being included in the response, but the
reset boolean does not seem to completely reset the list of Allow
results.

$r->allow_methods(1, qw(PUT));
return Apache2::Const::DECLINED;
results in
Allow: GET,HEAD,POST,OPTIONS,PUT,TRACE
being returned to the client rather than
Allow: OPTIONS,PUT,TRACE

$r->allow_methods(1, qw(HEAD GET));
return Apache2::Const::DECLINED;
results in
Allow: GET,HEAD,POST,OPTIONS,TRACE
being returned to the client rather than maybe
Allow: HEAD,GET,OPTIONS,TRACE

So, this does not seem to be working as I would expect either.

And additional source of confusion is the fact that the documentation
(http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_allowed_)
about the $r->allowed() method states:
"This bitvector is used to construct the "Allow:" header required for
OPTIONS requests, and Apache2::Const::HTTP_METHOD_NOT_ALLOWED (405)
and Apache2::Const::HTTP_NOT_IMPLEMENTED (501) status codes."

Are the docs just wrong?

thanks,
Christopher

On 10/9/07, Geoffrey Young <[EMAIL PROTECTED]> wrote:
>
>
> Christopher Stanton wrote:
> > I am trying to set the allowed bitmask in a custom request handler
> > when I receive the OPTIONS method (and when I receive a method request
> > for a method I do not support).
> >
> > I have followed the example in
> > http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_allowed_
> > but Apache always returns "Allow: GET,HEAD,POST,OPTIONS,TRACE" in the
> > header irrespective of what options I set.
> >
> > For example, lets say I only accept PUT to try to restrict the
> > available options to OPTIONS, TRACE, and PUT.
> >
> > I have tried both
> > $r->allowed($r->allowed | (1<< Apache2::Const::M_PUT));
> > and
> > $r->allowed(1< > with a return of Apache2::Const::DECLINED in either case in my handler.
> >
> > Neither ends up modifying the supported options sent to the client.
> >
> > In tha handler if I print the return value of $r->allowed:
> > print $r->allowed(1< > print $r->allowed() . "\n";
> > return Apache2::Const::DECLINED;
> >
> > I get:
> > 1
> > 2
> >
> > So the record is being updated, but for some reason Apache is not
> > basing its response to the client off of the record.
> >
> > Can anyone provide any insight into why I am unable to modify the list
> > of request methods my handler is capable of servicing?
>
> the Allow header appears to be built not from r->allowed but
> r->allowed_methods->method_mask.  so, try this:
>
> http://perl.apache.org/docs/2.0/api/Apache2/Access.html#C_allow_methods_
>
> HTH
>
> --Geoff
>


Re: mod_perl Apache2 RequestRec allowed problem

2007-10-09 Thread Geoffrey Young


Christopher Stanton wrote:
> I am trying to set the allowed bitmask in a custom request handler
> when I receive the OPTIONS method (and when I receive a method request
> for a method I do not support).
> 
> I have followed the example in
> http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_allowed_
> but Apache always returns "Allow: GET,HEAD,POST,OPTIONS,TRACE" in the
> header irrespective of what options I set.
> 
> For example, lets say I only accept PUT to try to restrict the
> available options to OPTIONS, TRACE, and PUT.
> 
> I have tried both
> $r->allowed($r->allowed | (1<< Apache2::Const::M_PUT));
> and
> $r->allowed(1< with a return of Apache2::Const::DECLINED in either case in my handler.
> 
> Neither ends up modifying the supported options sent to the client.
> 
> In tha handler if I print the return value of $r->allowed:
> print $r->allowed(1< print $r->allowed() . "\n";
> return Apache2::Const::DECLINED;
> 
> I get:
> 1
> 2
> 
> So the record is being updated, but for some reason Apache is not
> basing its response to the client off of the record.
> 
> Can anyone provide any insight into why I am unable to modify the list
> of request methods my handler is capable of servicing?

the Allow header appears to be built not from r->allowed but
r->allowed_methods->method_mask.  so, try this:

http://perl.apache.org/docs/2.0/api/Apache2/Access.html#C_allow_methods_

HTH

--Geoff


mod_perl Apache2 RequestRec allowed problem

2007-10-09 Thread Christopher Stanton
I am trying to set the allowed bitmask in a custom request handler
when I receive the OPTIONS method (and when I receive a method request
for a method I do not support).

I have followed the example in
http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_allowed_
but Apache always returns "Allow: GET,HEAD,POST,OPTIONS,TRACE" in the
header irrespective of what options I set.

For example, lets say I only accept PUT to try to restrict the
available options to OPTIONS, TRACE, and PUT.

I have tried both
$r->allowed($r->allowed | (1<< Apache2::Const::M_PUT));
and
$r->allowed(1allowed(1