Subject: | In some cases the HTTP::Cookies module does not delete cookies |
Hi,
In some cases the HTTP::Cookies module does not delete cookies.
Here is the issue in detail:
- when the foo.com URL is requested the "Cookie_check=1" cookie is set
- then server redirects us to pass.foo.com
- while requesting pass.foo.com the "Cookie_check=" cookie is set
- then server redirects us to ok.foo.com
On each step the server displays the STDOUT cookie.
Please view the examples of requests for w3m browser and LWP client (client.pl):
Show quoted text
> tail -n 3 /etc/hosts
127.0.0.1 foo.com
127.0.0.1 pass.foo.com
127.0.0.1 ok.foo.com
Show quoted text> perl server.pl
Show quoted text> w3m -dump http://foo.com:8080
Received cookie: Cookie_check=1
Received cookie: Cookie_check=
Hello
Show quoted text> perl client.pl
Hello
Show quoted text> perl server.pl
undef at server.pl line 23.
Cookie_check=1 at server.pl line 29.
undef at server.pl line 35.
======
undef at server.pl line 23.
Cookie_check=1 at server.pl line 29.
Cookie_check=1 at server.pl line 35.
======
Sincerely,
Nick Kostyria
Subject: | client.pl |
$| = 1;
use strict;
use warnings;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new();
$ua->cookie_jar({});
print $ua->get('http://foo.com:8080')->content;
Subject: | server.pl |
$| = 1;
use strict;
use warnings;
use HTTP::Daemon;
use HTTP::Status;
use HTTP::Headers;
use HTTP::Response;
my $port = 8080;
my $d = HTTP::Daemon->new(
LocalPort => $port,
ReuseAddr => 1,
) or die;
while (my $c = $d->accept) {
while (my $r = $c->get_request) {
my $host = $r->headers->header('host');
my $cookie = $r->headers->header('cookie') || "undef";
if ($host eq "foo.com:$port") {
warn $cookie;
my $headers = HTTP::Headers->new('Location' => "http://pass.foo.com:$port");
$headers->header('Set-Cookie' => "Cookie_check=1; domain=.foo.com; path=/; expires=Thu, 31-Dec-2037 20:59:59 GMT");
my $res = HTTP::Response->new(302, undef, $headers);
$c->send_response($res);
} elsif ($host eq "pass.foo.com:$port") {
warn $cookie;
my $headers = HTTP::Headers->new('Location' => "http://ok.foo.com:$port");
$headers->header('Set-Cookie' => "Cookie_check=; domain=.foo.com; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT");
my $res = HTTP::Response->new(302, undef, $headers);
$c->send_response($res);
} elsif ($host eq "ok.foo.com:$port") {
warn $cookie;
warn "======\n";
my $headers = HTTP::Headers->new('Content-Type' => 'text/plain');
my $res = HTTP::Response->new(200, undef, $headers, "Hello\n");
$c->send_response($res);
} else {
$c->send_error(RC_NOT_FOUND);
}
$c->force_last_request;
}
$c->close;
undef($c);
}