You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-dev@httpd.apache.org by Randy Kobes <ra...@theoryx5.uwinnipeg.ca> on 2004/07/27 03:23:44 UTC

[apreq-2] cookies

I'm having a problem with cookies in a simple handler;
this is with the current apreq-2 cvs, current mod_perl-1.99
cvs, and Apache/2.0.50, both on Win32 (perl-5.8.4,
multithreaded) and Linux (perl-5.8.5, non-multithreaded).
All the supplied tests passed on both, save for a couple of
(I think) unrelated minor issues. The handler is :
=======================================================
package Apache::Fail;
use strict;
use warnings;
use Apache::Request;
use Apache::Cookie;
use Apache::RequestRec;
use Apache::RequestUtil;
use Apache::Const -compile => qw(OK);
my $cookie_name = 'cookie_name';

sub handler {
  my $r = shift;
  my $mirror;
  my $req = Apache::Request->new($r);
  my %cookies = Apache::Cookie->fetch($r);
  if (my $c = $cookies{$cookie_name}) {
    $mirror = $c->value;
  }
  else {
    my $host = $req->param('key') || 'default';
    my $cookie = Apache::Cookie->new($r, name => $cookie_name,
                                     value => $host);
    $cookie->bake;
    $mirror = $host;
  }
  $r->content_type('text/html');
  $r->print($mirror);
  Apache::OK;
}
1;
================================================================
with configuration

PerlModule Apache::Fail
<Location /fail>
  SetHandler perl-script
  PerlResponseHandler Apache::Fail
</Location>

If I call this as
   http://localhost/fail?key=whatever
with no cookies present, then the cookie gets created
with the proper value. However, if I then reload
the page, and so try to use the stored cookie, I get
many instances of
  Could not find specified socket in poll list.:
    Skipping bad NAME=VALUE pair: cookie
    Skipping bad NAME=VALUE pair:
    Skipping bad NAME=VALUE pair:
             .....
until I have to kill the server.

The problem seems to be the presence of '_' in the
cookie name - if I use instead a name like
   my $cookie_name = 'cookiename';
then it works. I thought though that it was OK
to have underscores in the cookie name?

-- 
best regards,
randy

Re: [apreq-2] cookies

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Tue, 27 Jul 2004, Joe Schaefer wrote:

> Joe Schaefer <jo...@sunstarsys.com> writes:
>
> [...]
>
> > Just about anything under the sun is a valid
> > cookie name.  The only restriction I know of is
> > that it cannot contain a token character.
>           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Oops, I actually should have wrote "can only contain token characters".
>
> > We just need to make get_pair smart enough to actually allow this.
>
> I've reworked the get_pair logic now. Randy, are you still having
> similar problems with current cvs?

Works great now - that was fast! Thanks, Joe.

-- 
best regards,
randy

Re: [apreq-2] cookies

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Joe Schaefer <jo...@sunstarsys.com> writes:


[...]

> Just about anything under the sun is a valid
> cookie name.  The only restriction I know of is
> that it cannot contain a token character.
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Oops, I actually should have wrote "can only contain token characters".

> We just need to make get_pair smart enough to actually allow this.

I've reworked the get_pair logic now. Randy, are you still having 
similar problems with current cvs?


-- 
Joe Schaefer


Re: [apreq-2] cookies

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Randy Kobes <ra...@theoryx5.uwinnipeg.ca> writes:

[...]

>   Could not find specified socket in poll list.:

Blech.  We need to start using our own status
codes in apreq.  Borrowing apr's strerror is 
worse than printing nothing at all.

>     Skipping bad NAME=VALUE pair: cookie
>     Skipping bad NAME=VALUE pair:
>     Skipping bad NAME=VALUE pair:
>              .....
> until I have to kill the server.

The bug is in apreq_cookie.c's get_pair 
(it's getting stuck on the '_', which isn't an alnum). 
I'll have it fixed shortly, but I want to
make sure the infinite loop goes away as well.

> The problem seems to be the presence of '_' in the
> cookie name - if I use instead a name like
>    my $cookie_name = 'cookiename';
> then it works. I thought though that it was OK
> to have underscores in the cookie name?

Just about anything under the sun is a valid
cookie name.  The only restriction I know of is
that it cannot contain a token character.  We just
need to make get_pair smart enough to actually
allow this.

-- 
Joe Schaefer