Add cookie support
HTTP::Tiny has no support for cookies.
In order to support cookies, the Perl library punts to a user-defined cookie jar which is expected to implement something like the following interface:
role Cookie::Jar {
#| Takes a URL, returns a list of header values as strings
#| with the cookies set for that domain.
method cookie-header ( Str:D $url --> Array of Str ) { ... }
#| Takes a URL and a header value, and parses that header value
#| into a cookie that gets stored for that URL
method add ( Str:D $url, Str:D $header ) { ... }
}
There are some available cookie jars in the ecosystem:
HTTP::Cookies
Part of HTTP::UserAgent.
The equivalent methods to the above would be set-cookie
, which takes a whole header line (including the Set-Cookie
header key), and Str
, which the rendered header lines, ready to be sent down the wire.
Note that none of these supports domain-specific cookies.
Cro::HTTP::Client::CookieJar
Part of Cro::HTTP.
The equivalent methods would be add-cookie
(which requires previously calling Cro::HTTP::Cookie.from-set-cookie
to create a cookie object), and calling $jar.contents».to-set-cookie
to generate the header values.
So, no common interface means no easily pluggable cookie jar, and the interfaces provided by these modules does not make it easy to use them outside of the distributions that package them.
Although this cookie jar does support