Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

HTTP::Cookies -> CookieJar

by Anonymous Monk
on Mar 31, 2025 at 09:49 UTC ( [id://11164525]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

The use of HTTP::CookieJar is recommended over HTTP::Cookies, and the core module HTTP::Tiny only supports the former. There exists HTTP::CookieJar::LWP to allow using a HTTP::CookieJar with LWP::UserAgent, but I can't find anything going the other way- I want to use HTTP::Cookies::Mozilla with HTTP::Tiny. In fact, all the modules to read specific browser cookies use the HTTP::Cookies interface. The following seems to work, but I expected to find some minimal documentation or implementation:
use HTTP::Tiny; use HTTP::CookieJar; use HTTP::Cookies::Mozilla; my $cookies = HTTP::Cookies::Mozilla->new(file => $firefox_cookies_sql +ite_file); my @cookies = map { s/^Set-Cookie3:\s*//; $_ } split "\n", $cookies->as_string; my $cookie_jar = HTTP::CookieJar->new; $cookie_jar->load_cookies(@cookies); my $ua = HTTP::Tiny->new(cookie_jar => $cookie_jar);

Replies are listed 'Best First'.
Re: HTTP::Cookies -> CookieJar
by hippo (Archbishop) on Mar 31, 2025 at 11:21 UTC
    The use of HTTP::CookieJar is recommended over HTTP::Cookies

    Recommended by whom? Each of those modules has its own pros and cons and it is up to the user (coder) to choose between them given any particular scenario. They each have roughly 6,400 total dependents (according to MetaCPAN) so it isn't like one or other is dominating the scene.

    If you want to use HTTP::Tiny for whatever reason then you have to put up with the consequences of that choice such as the manual translation between formats which you have shown. Hopefully it isn't too brittle.


    🦛

        Something that got me confused here is this: you're concerned about recommendations from LWP::UserAgent docs when instead you picked HTTP::Tiny for the task. But anyway, HTTP::Tiny also mentions this:

        Cookie support requires HTTP::CookieJar or an equivalent class.

        return on_success() or die;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11164525]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2025-05-21 03:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.