develooper Front page | perl.libwww | Postings from October 2001

HTTP::Cookies rejects cookies from host a.b for domain .a.b

Thread Next
From:
Alexandre Duret-Lutz
Date:
October 11, 2001 14:33
Subject:
HTTP::Cookies rejects cookies from host a.b for domain .a.b
Message ID:
87u1x5rifn.fsf@lrde.epita.fr
Hi people,

I'm writing an HTTP client for SourceForge using LWP (libwww-perl 5.53).

I need to login to SourceForge by POSTing a form, to get an
identification cookie before further processing.

The trouble is that the (queried) host 'sourceforge.net' sends me a
cookie as follow:

Set-Cookie: username=BLABLABLA; expires=Wed, 17-Oct-01 22:37:23 GMT; path=/; domain=.sourceforge.net

and HTTP::Cookies reject it with the this debug output:

HTTP::Cookies::extract_cookies: Domain .sourceforge.net does not match host sourceforge.net

I have no idea who is right, it's the first time I work with
cookies.  (Reading RFC 2109 I'd vote for HTTP::Cookies, however
other browsers seems to accept these cookies just fine.)

I've modified my copy of Cookies.pm as follow to get around this.

--- Cookies.pm
+++ Cookies.pm
@@ -322,7 +322,8 @@
 
 	# Check domain
 	my $domain  = delete $hash{domain};
-	if (defined($domain) && $domain ne $req_host) {
+	if (defined($domain)
+	    && $domain ne $req_host && $domain ne ".$req_host") {
 	    if ($domain !~ /\./ && $domain ne "local") {
 	        LWP::Debug::debug("Domain $domain contains no dot");
 		next SET_COOKIE;



For completeness, the code I am using is as follow (it's a reconstruction):

    &LWP::Debug::level ('+debug');
    my $ua = new LWP::UserAgent;
    $ua->cookie_jar (new HTTP::Cookies 
                     file => $cookie_jar, 
                     autosave => 1);
    my $req = POST ("https://sourceforge.net/account/login.php",
                    [form_loginname => $login,
                     form_pw        => $passwd,
                     stay_in_ssl    => 1,
                     login          => "Login With SSL"]);
    my $res = $agent->request ($req);

-- 
Alexandre Duret-Lutz

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About