[dw-free] Add cookie support to DW::Request
[commit: http://hg.dwscoalition.org/dw-free/rev/eed9e65c3af3]
http://bugs.dwscoalition.org/show_bug.cgi?id=2446
Fix some issues with the cookie code just added; it was defaulting to
setting the domain which does not seem to be correct.
Patch by
mark.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=2446
Fix some issues with the cookie code just added; it was defaulting to
setting the domain which does not seem to be correct.
Patch by
![[staff profile]](https://www.dreamwidth.org/img/silk/identity/user_staff.png)
Files modified:
- cgi-bin/DW/Request/Base.pm
- cgi-bin/LJ/Session.pm
-------------------------------------------------------------------------------- diff -r 4964f14bf7ad -r eed9e65c3af3 cgi-bin/DW/Request/Base.pm --- a/cgi-bin/DW/Request/Base.pm Wed Apr 21 08:48:41 2010 +0000 +++ b/cgi-bin/DW/Request/Base.pm Wed Apr 21 09:44:29 2010 +0000 @@ -47,11 +47,10 @@ sub add_cookie { confess "Must provide name" unless $args{name}; confess "Must provide value (try delete_cookie if you really mean this)" unless exists $args{value}; - $args{domain} ||= ".$LJ::DOMAIN"; - # extraneous parenthesis inside map {} needed to force BLOCK mode map my $cookie = CGI::Cookie->new( map { ( "-$_" => $args{$_} ) } keys %args ); $self->err_header_out_add( 'Set-Cookie' => $cookie ); + return $cookie; } @@ -63,7 +62,6 @@ sub delete_cookie { $args{value} = ''; $args{expires} = "-1d"; - $args{domain} ||= ".$LJ::DOMAIN"; return $self->add_cookie( %args ); } diff -r 4964f14bf7ad -r eed9e65c3af3 cgi-bin/LJ/Session.pm --- a/cgi-bin/LJ/Session.pm Wed Apr 21 08:48:41 2010 +0000 +++ b/cgi-bin/LJ/Session.pm Wed Apr 21 09:44:29 2010 +0000 @@ -491,7 +491,7 @@ sub session_from_cookies { my $domain_cookie = LJ::Session->domain_cookie; if ($domain_cookie) { # journal domain - $sessobj = LJ::Session->session_from_domain_cookie(\%getopts, $r->cookie( $domain_cookie ) ); + $sessobj = LJ::Session->session_from_domain_cookie( \%getopts, $r->cookie( $domain_cookie ) ); } else { # this is the master cookie at "www.livejournal.com" or "livejournal.com"; my @cookies = $r->cookie( 'ljmastersession' ); @@ -521,10 +521,11 @@ sub session_from_domain_cookie { my $no_session = sub { my $reason = shift; + warn "No session found: $reason\n" if $LJ::IS_DEV_SERVER; + my $rr = $opts->{redirect_ref}; - if ($rr) { - $$rr = "$LJ::SITEROOT/misc/get_domain_session?return=" . LJ::eurl(_current_url()); - } + $$rr = "$LJ::SITEROOT/misc/get_domain_session?return=" . LJ::eurl(_current_url()) if $rr; + return undef; }; @@ -535,8 +536,7 @@ sub session_from_domain_cookie { foreach my $cookie (@cookies) { my $sess = valid_domain_cookie($domcook, $cookie, $li_cook); - next unless $sess; - return $sess; + return $sess if $sess; } return $no_session->("no valid cookie"); @@ -886,6 +886,8 @@ sub valid_domain_cookie { my $not_valid = sub { my $reason = shift; + warn "Invalid domain cookie: $reason\n" if $LJ::IS_DEV_SERVER; + return undef; }; --------------------------------------------------------------------------------