in reply to WWW::Mechanize::Firefox save_url doesn't send cookies

Thanks for the report! I had also assumed that the cookies are sent automatically, but if that's not the case, I think you will have to look at nsICookieService and ask it to tell you the cookie string that is to be sent as additional headers. If I get around to writing a self-contained testcase, I'll test this out and then add it to WWW::Mechanize::Firefox, but I don't see a quick workaround other than using ->get instead of ->save_url - and ->get may or may not save the target, depending on your Firefox setup.

Replies are listed 'Best First'.
Re^2: WWW::Mechanize::Firefox save_url doesn't send cookies
by tcordes (Novice) on Mar 08, 2011 at 22:41 UTC

    I played around some more. My last report was erroneous, adding nsIWBP.PERSIST_FLAGS_FORCE_ALLOW_COOKIES does fix the problem! I had thought it didn't as I was updating the old .pm file not the new version, so my changes weren't even executing (doh!).

    So the following lines in save_url fixes it and now it works great!!!! Thanks for the great perl module, opens up a whole new world of mech'ing.

    obj_Persist.persistFlags = flags | nsIWBP.PERSIST_FLAGS_FROM_CACHE;
    obj_Persist.persistFlags = obj_Persist.persistFlags | nsIWBP.PERSIST_FLAGS_FORCE_ALLOW_COOKIES;

      Great! Thanks for testing again and confirming that this works. I'll release a new version with the bugfix (and a privacy warning) some time in the next few days. The code will be changed to the following, to support earlier versions of Firefox 3 that don't have the flag yet:

      obj_Persist.persistFlags = flags | nsIWBP.PERSIST_FLAGS_FROM_CACHE | nsIWBP["PERSIST_FLAGS_FORCE_ALL +OW_COOKIES"] ;

      I just want to also ship a local test server to actually confirm locally that the appropriate cookies are sent.

        I double-checked the wireshark captures after the bugfix and it is sending (just) the proper cookies, and not any out-of-domain ones. So it seems to be working as you'd expect.

        PS: There's one other place in your .pm (save_content) where perhaps this PERSIST_FLAGS_FORCE_ALLOW_COOKIES should be added as well. Just search on the other instance of PERSIST_FLAGS_FROM_CACHE. I don't use that other function, so I haven't tested it.