On Fri, Jul 31, 2015 at 10:36 AM, tandalat wrote:
[...]
Yes, indeed. Is there a reason why cookie objects returned by
cookiejar.Cookies() do not have other fields set other than Name and Value?
In the source code for cookiejar.cookies(...):
225 for _, e := range selected {
226 cookies = append(cookies, &http.Cookie{Name: e.Name, Value: e.Value})
227 }
My proposal is simply filling up other fields like so,
for _, e := range selected {
c := &http.Cookie{
Name: e.Name,
Value: e.Value,
Path: e.Path,
Domain: e.Domain,
Expires: e.Expires,
Secure: e.Secure,
HttpOnly: e.HttpOnly,
}
cookies = append(cookies, c)
}
What's the catch here?
1. This would break the Go API compatibility guaranty.
2. Cookies() returns http.Cookies suitable for generating
a Cookie header. If all fields would be filled up you would
get a cookie which would serialize to a Set-Cookie header.
(package http could clear the other fields).
3. How would you differentiate between a domain and a
host cookie?
4. You lose the creation and last access time, so you
cannot use this for properly persisting and re-loading
the cookies.
Based on this API a user of package cookiejar could extract all
stored cookies and persist them herself. Probably loading them
back into a Jar would require some help to safeguard against subtle
errors and PSL changes.
Won't keying the urls (used to retrieve cookies) for serialized cookies on
disk or database and later using them to load the cookies back into the jar
keep things consistent? For example,
store[u.String()] = jar.Cookies(u)
... serialize to some storage ...
... load from storage
for k, v := range store {
jar.SetCookies(url.MustParse(k), v)
}
....
Basically yes, but there might be some ugly corner cases like
domain cookies which are no longer allowed because the
domain is now considered a ETLD (because the PSL used
to re-load the cookies differs from the one used during storing).
And possible more if I thought about it longer.
The main problem with keying by _URL_ is the Path field:
You cannot know which URLs (i.e. which paths) you have
to request as Cookies() returns only cookies which match
the path of the URL. How would you know that the jar
contains a cookie with Path="/some/obscure/deep/path"?
V.
[...]