Loading ...
Sorry, an error occurred while loading the content.

Re: Apache::Cookie

Expand Messages
  • Perrin Harkins
    ... I see the problem. There is mistake in the Apache::Cookie documentation, but the correct way to do this is shown in the mod_perl guide:
    Message 1 of 17 , Jun 2, 2003
    • 0 Attachment
      On Mon, 2003-06-02 at 09:05, cap wrote:
      > i have an application that uses CGI and sets the cookie values as a hashref.
      > im then attempting to retreive the values with Apache::Cookie with:
      >
      > $cookies = Apache::Cookie->fetch;
      >
      > $ccokies is a hashref so i should be able to get the individual values with:
      >
      > $cookies->{uid};
      >
      > right? however, this doesn't appear to work.

      I see the problem. There is mistake in the Apache::Cookie
      documentation, but the correct way to do this is shown in the mod_perl
      guide:
      http://perl.apache.org/docs/1.0/guide/porting.html#Converting_to_use_Apache_Perl_Modules

      Change your last line to this:

      my $uid = defined $cookies->{'uid'} ? $cookies->{'uid'}->value() :
      undef;

      - Perrin
    • cap
      Well, here s what I have to do to get direct access to values from the original cookie hash: my $cookies = Apache::Cookie- fetch; my %hash = defined
      Message 2 of 17 , Jun 2, 2003
      • 0 Attachment
        Well, here's what I have to do to get direct access to values from the
        original cookie hash:

        my $cookies = Apache::Cookie->fetch;
        my %hash = defined $cookies->{'session'} ? $cookies->{'session'}->value :
        undef;

        Strange. Thanks for the lead.




        >-----Original Message-----
        >From: Perrin Harkins [mailto:perrin@...]
        >Sent: Monday, June 02, 2003 2:41 PM
        >To: thecap@...
        >Cc: modperl
        >Subject: Re: Apache::Cookie
        >
        >
        >On Mon, 2003-06-02 at 09:05, cap wrote:
        >> i have an application that uses CGI and sets the cookie values
        >as a hashref.
        >> im then attempting to retreive the values with Apache::Cookie with:
        >>
        >> $cookies = Apache::Cookie->fetch;
        >>
        >> $ccokies is a hashref so i should be able to get the individual
        >values with:
        >>
        >> $cookies->{uid};
        >>
        >> right? however, this doesn't appear to work.
        >
        >I see the problem. There is mistake in the Apache::Cookie
        >documentation, but the correct way to do this is shown in the mod_perl
        >guide:
        >http://perl.apache.org/docs/1.0/guide/porting.html#Converting_to_us
        >e_Apache_Perl_Modules
        >
        >Change your last line to this:
        >
        >my $uid = defined $cookies->{'uid'} ? $cookies->{'uid'}->value() :
        >undef;
        >
        >- Perrin
        >
      • Stas Bekman
        ... That s a bogus code. Obviously you are running without warnings mode on. Add: use warnings; and you will see why it is bogus. Perhaps your cookie was
        Message 3 of 17 , Jun 2, 2003
        • 0 Attachment
          cap wrote:
          > Well, here's what I have to do to get direct access to values from the
          > original cookie hash:
          >
          > my $cookies = Apache::Cookie->fetch;
          > my %hash = defined $cookies->{'session'} ? $cookies->{'session'}->value :
          > undef;
          >
          > Strange. Thanks for the lead.

          That's a bogus code. Obviously you are running without warnings mode on. Add:

          use warnings;

          and you will see why it is bogus. Perhaps your cookie was always valid so you
          didn't notice it. Howerer:

          perl -lwe '%h = undef'
          Name "main::h" used only once: possible typo at -e line 1.
          Odd number of elements in hash assignment at -e line 1.
          Use of uninitialized value in list assignment at -e line 1.




          >>-----Original Message-----
          >>From: Perrin Harkins [mailto:perrin@...]
          >>Sent: Monday, June 02, 2003 2:41 PM
          >>To: thecap@...
          >>Cc: modperl
          >>Subject: Re: Apache::Cookie
          >>
          >>
          >>On Mon, 2003-06-02 at 09:05, cap wrote:
          >>
          >>>i have an application that uses CGI and sets the cookie values
          >>
          >>as a hashref.
          >>
          >>>im then attempting to retreive the values with Apache::Cookie with:
          >>>
          >>>$cookies = Apache::Cookie->fetch;
          >>>
          >>>$ccokies is a hashref so i should be able to get the individual
          >>
          >>values with:
          >>
          >>>$cookies->{uid};
          >>>
          >>>right? however, this doesn't appear to work.
          >>
          >>I see the problem. There is mistake in the Apache::Cookie
          >>documentation, but the correct way to do this is shown in the mod_perl
          >>guide:
          >>http://perl.apache.org/docs/1.0/guide/porting.html#Converting_to_us
          >>e_Apache_Perl_Modules
          >>
          >>Change your last line to this:
          >>
          >>my $uid = defined $cookies->{'uid'} ? $cookies->{'uid'}->value() :
          >>undef;
          >>
          >>- Perrin
          >>
          >


          --


          __________________________________________________________________
          Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
          http://stason.org/ mod_perl Guide ---> http://perl.apache.org
          mailto:stas@... http://use.perl.org http://apacheweek.com
          http://modperlbook.org http://apache.org http://ticketmaster.com
        • cap
          it works just fine in my app, and just fine maybe all that i need. do you have a better solution, or are you just pointing out the error?
          Message 4 of 17 , Jun 3, 2003
          • 0 Attachment
            it works just fine in my app, and 'just fine' maybe all that i need. do you
            have a better solution, or are you just pointing out the error?



            >-----Original Message-----
            >From: Stas Bekman [mailto:stas@...]
            >Sent: Monday, June 02, 2003 10:08 PM
            >To: thecap@...
            >Cc: Perrin Harkins; modperl
            >Subject: Re: Apache::Cookie
            >
            >
            >cap wrote:
            >> Well, here's what I have to do to get direct access to values from the
            >> original cookie hash:
            >>
            >> my $cookies = Apache::Cookie->fetch;
            >> my %hash = defined $cookies->{'session'} ? $cookies->{'session'}->value :
            >> undef;
            >>
            >> Strange. Thanks for the lead.
            >
            >That's a bogus code. Obviously you are running without warnings
            >mode on. Add:
            >
            >use warnings;
            >
            >and you will see why it is bogus. Perhaps your cookie was always
            >valid so you
            >didn't notice it. Howerer:
            >
            >perl -lwe '%h = undef'
            >Name "main::h" used only once: possible typo at -e line 1.
            >Odd number of elements in hash assignment at -e line 1.
            >Use of uninitialized value in list assignment at -e line 1.
            >
            >
            >
            >
            >>>-----Original Message-----
            >>>From: Perrin Harkins [mailto:perrin@...]
            >>>Sent: Monday, June 02, 2003 2:41 PM
            >>>To: thecap@...
            >>>Cc: modperl
            >>>Subject: Re: Apache::Cookie
            >>>
            >>>
            >>>On Mon, 2003-06-02 at 09:05, cap wrote:
            >>>
            >>>>i have an application that uses CGI and sets the cookie values
            >>>
            >>>as a hashref.
            >>>
            >>>>im then attempting to retreive the values with Apache::Cookie with:
            >>>>
            >>>>$cookies = Apache::Cookie->fetch;
            >>>>
            >>>>$ccokies is a hashref so i should be able to get the individual
            >>>
            >>>values with:
            >>>
            >>>>$cookies->{uid};
            >>>>
            >>>>right? however, this doesn't appear to work.
            >>>
            >>>I see the problem. There is mistake in the Apache::Cookie
            >>>documentation, but the correct way to do this is shown in the mod_perl
            >>>guide:
            >>>http://perl.apache.org/docs/1.0/guide/porting.html#Converting_to_us
            >>>e_Apache_Perl_Modules
            >>>
            >>>Change your last line to this:
            >>>
            >>>my $uid = defined $cookies->{'uid'} ? $cookies->{'uid'}->value() :
            >>>undef;
            >>>
            >>>- Perrin
            >>>
            >>
            >
            >
            >--
            >
            >
            >__________________________________________________________________
            >Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
            >http://stason.org/ mod_perl Guide ---> http://perl.apache.org
            >mailto:stas@... http://use.perl.org http://apacheweek.com
            >http://modperlbook.org http://apache.org http://ticketmaster.com
            >
            >
          • Perrin Harkins
            ... The point is, it shouldn t work. You should not be getting a hash. What should work is this: my $session = defined $cookies- { session } ?
            Message 5 of 17 , Jun 3, 2003
            • 0 Attachment
              On Tue, 2003-06-03 at 13:08, cap wrote:
              > it works just fine in my app, and 'just fine' maybe all that i need.

              The point is, it shouldn't work. You should not be getting a hash.
              What should work is this:

              my $session = defined $cookies->{'session'} ?
              $cookies->{'session'}->value : undef;

              The larger issue is fixing the Apache::Cookie docs. I would attempt to
              patch it if I understood what it's doing. Does anyone know what the API
              is returning when you call fetch()? An Apache::Table? Some other kind
              of object? It looks pretty bizarre to me, and it certainly isn't doing
              what the docs show.

              - Perrin
            • cap
              Okay, I m obviously no expert but I see a problem ... I think? : my $cookie = Apache::Cookie- fetch; my $ref_cookie = ref $cookie; returns HASH but my
              Message 6 of 17 , Jun 3, 2003
              • 0 Attachment
                Okay, I'm obviously no expert but I see a problem ... I think? :

                my $cookie = Apache::Cookie->fetch;
                my $ref_cookie = ref $cookie;

                returns 'HASH'

                but

                my $session = $cookies->{'session'}->value;
                my $type = ref @session;

                doesn't return anything, '' or (undef?). strange?

                However:

                my @session = $cookies->{'session'}->value;

                returns the (almost) desired result as pairs and as they were originally
                inserted from the standard CGI cookie. so i thought it was acceptable to
                convert to a hash, knowing the list values are in pairs:

                my %hash = $cookies->{'session'}->value;

                will probably throw a warning or even an error without the defined
                statement, but it gets past the immediate issue.

                kirk







                >-----Original Message-----
                >From: Perrin Harkins [mailto:perrin@...]
                >Sent: Tuesday, June 03, 2003 10:57 AM
                >To: thecap@...
                >Cc: Stas Bekman; modperl
                >Subject: RE: Apache::Cookie
                >
                >
                >On Tue, 2003-06-03 at 13:08, cap wrote:
                >> it works just fine in my app, and 'just fine' maybe all that i need.
                >
                >The point is, it shouldn't work. You should not be getting a hash.
                >What should work is this:
                >
                >my $session = defined $cookies->{'session'} ?
                >$cookies->{'session'}->value : undef;
                >
                >The larger issue is fixing the Apache::Cookie docs. I would attempt to
                >patch it if I understood what it's doing. Does anyone know what the API
                >is returning when you call fetch()? An Apache::Table? Some other kind
                >of object? It looks pretty bizarre to me, and it certainly isn't doing
                >what the docs show.
                >
                >- Perrin
                >
              • Arshavir Grigorian
                Hi, I am using Apache::Cookie (libapreq2-2.04-dev) to generate cookies. However, for some reason, the bake() method does not work. # WORKS my $cookie =
                Message 7 of 17 , Nov 9, 2004
                • 0 Attachment
                  Hi,

                  I am using Apache::Cookie (libapreq2-2.04-dev) to generate cookies.
                  However, for some reason, the bake() method does not work.

                  # WORKS
                  my $cookie = $ticket->cookie()->as_string();
                  $r->err_headers_out->add('Set-Cookie' => $cookie);

                  # DOES NOT WORK
                  $ticket->cookie()->bake();


                  where $ticket->cookie() is an Apache::Cookie object. This is the first
                  thing in the response and is followed by: $r->headers_out->set(Location
                  => '/path/'); return Apache::REDIRECT;.

                  Beside the fact that libapreq2 is still in development, is there a
                  problem with how I am using the bake() method? Thanks in advance.



                  Arshavir



                  --
                  Report problems: http://perl.apache.org/bugs/
                  Mail list info: http://perl.apache.org/maillist/modperl.html
                  List etiquette: http://perl.apache.org/maillist/email-etiquette.html
                • Joe Schaefer
                  ... libapreq2 is currently using $r- headers_out instead of $r- err_headers_out, which is why you re not seeing the cookie on your redirect response. I think
                  Message 8 of 17 , Nov 11, 2004
                  • 0 Attachment
                    Arshavir Grigorian <ag@...> writes:

                    > # WORKS
                    > my $cookie = $ticket->cookie()->as_string();
                    > $r->err_headers_out->add('Set-Cookie' => $cookie);
                    >
                    > # DOES NOT WORK $ticket->cookie()->bake();
                    > where $ticket->cookie() is an Apache::Cookie object. This is
                    > the first thing in the response and is followed by:
                    > $r->headers_out->set(Location => '/path/');
                    > return Apache::REDIRECT;.
                    >
                    > Beside the fact that libapreq2 is still in development,
                    > is there a problem with how I am using the bake() method? Thanks in
                    > advance.

                    libapreq2 is currently using $r->headers_out instead
                    of $r->err_headers_out, which is why you're not seeing the
                    cookie on your redirect response. I think the consensus
                    is that this is a bug in libapreq2-2.04, but I haven't seen
                    any other apreq committers weigh in on the subject, so
                    I'm not sure.

                    --
                    Joe Schaefer


                    --
                    Report problems: http://perl.apache.org/bugs/
                    Mail list info: http://perl.apache.org/maillist/modperl.html
                    List etiquette: http://perl.apache.org/maillist/email-etiquette.html
                  • Geoffrey Young
                    ... libapreq1 uses error_headers_out, so I think it s proper to follow that well established tradition, fwiw. --Geoff -- Report problems:
                    Message 9 of 17 , Nov 11, 2004
                    • 0 Attachment
                      > libapreq2 is currently using $r->headers_out instead
                      > of $r->err_headers_out, which is why you're not seeing the
                      > cookie on your redirect response. I think the consensus
                      > is that this is a bug in libapreq2-2.04, but I haven't seen
                      > any other apreq committers weigh in on the subject, so
                      > I'm not sure.

                      libapreq1 uses error_headers_out, so I think it's proper to follow that well
                      established tradition, fwiw.

                      --Geoff

                      --
                      Report problems: http://perl.apache.org/bugs/
                      Mail list info: http://perl.apache.org/maillist/modperl.html
                      List etiquette: http://perl.apache.org/maillist/email-etiquette.html
                    • Arshavir Grigorian
                      ... Thanks for the feedback. I guess I am wondering who I would need to talk to in order to get this fixed. Just to understand, why does it need to use the
                      Message 10 of 17 , Nov 11, 2004
                      • 0 Attachment
                        Geoffrey Young wrote:

                        >>libapreq2 is currently using $r->headers_out instead
                        >>of $r->err_headers_out, which is why you're not seeing the
                        >>cookie on your redirect response. I think the consensus
                        >>is that this is a bug in libapreq2-2.04, but I haven't seen
                        >>any other apreq committers weigh in on the subject, so
                        >>I'm not sure.
                        >>
                        >>
                        >
                        >libapreq1 uses error_headers_out, so I think it's proper to follow that well
                        >established tradition, fwiw.
                        >
                        >--Geoff
                        >
                        >
                        >
                        Thanks for the feedback. I guess I am wondering who I would need to talk
                        to in order to get this fixed.

                        Just to understand, why does it need to use the err_headers_out instead
                        of headers_out? There does not seem to be any errors. Am I
                        misinterpreting the function name or is it a misnomer?
                        TIA.


                        Arshavir

                        --
                        Report problems: http://perl.apache.org/bugs/
                        Mail list info: http://perl.apache.org/maillist/modperl.html
                        List etiquette: http://perl.apache.org/maillist/email-etiquette.html
                      • ___cliff rayman___
                        ... I have run into this in the past, and just rediscovered it again last week. A redirect response is either generally 301 or 302. Since it is not a 200
                        Message 11 of 17 , Nov 11, 2004
                        • 0 Attachment
                          Arshavir Grigorian wrote:

                          > Geoffrey Young wrote:
                          >
                          >>> libapreq2 is currently using $r->headers_out instead
                          >>> of $r->err_headers_out, which is why you're not seeing the
                          >>> cookie on your redirect response. I think the consensus
                          >>> is that this is a bug in libapreq2-2.04, but I haven't seen
                          >>> any other apreq committers weigh in on the subject, so
                          >>> I'm not sure.
                          >>>
                          >>
                          >>
                          >> libapreq1 uses error_headers_out, so I think it's proper to follow
                          >> that well
                          >> established tradition, fwiw.
                          >>
                          > Thanks for the feedback. I guess I am wondering who I would need to
                          > talk to in order to get this fixed.
                          >
                          > Just to understand, why does it need to use the err_headers_out
                          > instead of headers_out? There does not seem to be any errors. Am I
                          > misinterpreting the function name or is it a misnomer?

                          I have run into this in the past, and just rediscovered it again last
                          week. A redirect response is either generally 301 or 302. Since it is
                          not a 200 level response, this could be the reason. that error headers
                          out needs to be set, instead of just the regular headers

                          --
                          _____cliff_rayman_____cliff_@_rayman_._com_____



                          --
                          Report problems: http://perl.apache.org/bugs/
                          Mail list info: http://perl.apache.org/maillist/modperl.html
                          List etiquette: http://perl.apache.org/maillist/email-etiquette.html
                        • Geoffrey Young
                          ... Joe is the man :) ... yes, it s something of a misnomer. over in Apache-land, returning anything other than OK, DECLINED, or DONE from a handler is
                          Message 12 of 17 , Nov 11, 2004
                          • 0 Attachment
                            > Thanks for the feedback. I guess I am wondering who I would need to talk
                            > to in order to get this fixed.

                            Joe is the man :)

                            >
                            > Just to understand, why does it need to use the err_headers_out instead
                            > of headers_out? There does not seem to be any errors. Am I
                            > misinterpreting the function name or is it a misnomer?

                            yes, it's something of a misnomer. over in Apache-land, returning anything
                            other than OK, DECLINED, or DONE from a handler is considered an "error."
                            and the err_headers_out table holds response (and entity :) headers that
                            will be sent _even_ (not only) on errors.

                            really, all three of the mod_perl books out there talk about this, so it is
                            probably worth picking one of them up to read up on the API a bit. that is,
                            if you're interested in this kind of thing.

                            --Geoff

                            --
                            Report problems: http://perl.apache.org/bugs/
                            Mail list info: http://perl.apache.org/maillist/modperl.html
                            List etiquette: http://perl.apache.org/maillist/email-etiquette.html
                          • Arshavir Grigorian
                            ... Thanks Geoff. Makes sense now. I hope there is a consensus on replacing headers_out() with err_headers_out() in bake() before too long. Arshavir -- Report
                            Message 13 of 17 , Nov 12, 2004
                            • 0 Attachment
                              Geoffrey Young wrote:

                              >>Thanks for the feedback. I guess I am wondering who I would need to talk
                              >>to in order to get this fixed.
                              >>
                              >>
                              >
                              >Joe is the man :)
                              >
                              >
                              >
                              >>Just to understand, why does it need to use the err_headers_out instead
                              >>of headers_out? There does not seem to be any errors. Am I
                              >>misinterpreting the function name or is it a misnomer?
                              >>
                              >>
                              >
                              >yes, it's something of a misnomer. over in Apache-land, returning anything
                              >other than OK, DECLINED, or DONE from a handler is considered an "error."
                              >and the err_headers_out table holds response (and entity :) headers that
                              >will be sent _even_ (not only) on errors.
                              >
                              >really, all three of the mod_perl books out there talk about this, so it is
                              >probably worth picking one of them up to read up on the API a bit. that is,
                              >if you're interested in this kind of thing.
                              >
                              >--Geoff
                              >
                              >
                              Thanks Geoff. Makes sense now.
                              I hope there is a consensus on replacing headers_out() with
                              err_headers_out() in bake() before too long.


                              Arshavir

                              --
                              Report problems: http://perl.apache.org/bugs/
                              Mail list info: http://perl.apache.org/maillist/modperl.html
                              List etiquette: http://perl.apache.org/maillist/email-etiquette.html
                            Your message has been successfully submitted and would be delivered to recipients shortly.