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;