Open VicarEscaped opened 1 month ago
This has been discussed on discord about a year ago, but there is no obvious solution that is good. Here is the extract from the Discord thread:
I see a couple of options: (1) add Set-Cookie to the list of "repeatable" headers and don't do anything else; the values will be folder in a comma-separated list; (2) implement (1), but also have a special process for it to fold the results into a table instead of a comma-separated list. Not ideal, because it breaks the existing code, but would follow the specs. The first option is the simplest and would work with the existing code as well as Fetch, but would not follow SHOULD NOT recommendation from RFC6265. it's probably recommended because Expires is the attribute that is clearly allowed to have commas, even though cookie-name/cookie-value can't include commas and Expires can probably be parsed to handle (may need to check path also).
I'm open to suggestions.
Thank you for pointing out that there is a discord server. somehow i missed that source of information.
Let’s fixes dont’s:
I’ve come up with two ideas.
Create Set-Cookie iterator. During creating headers table push found Set-Cookie with new name (e.g. Set-Cookie1, Set-Cookie2). After processing multiple Set-Cookie change first or last Set-Cookie new name back to original Set-Cookie. It depends on how now populates headers table. This prevents breaking backwards compatibility. At last, provider code snippet in help.txt, that merge multiple Set-Cookie headers into single table.
function mergeCookieHeaders(headers)
local c = {}
for k,v in pairs(headers) do
if k:find(“^Set%-Cookie”) ~= nil then
table.insert(c, v)
end
end
return c
end
Cons: messing around with not original server headers.
In various languages (e.g. java[1], python[2], go[3]) for cookies use concept of cookiejar. Fetch could extends config table with new optional key (e.g. jar, cookiejar). This key holds user defined table and populates it with found values of Set-Cookie headers.
>: local cookiejar = {}
>: s,h,b = Fetch(“https://google.com”, {method=“GET”, headers={[“Content-Type”]=“application/json”}, cookiejar=cookiejar})
>: print(cookiejar)
>: {“key=value; Domain=.some.com”, “key2=value2; Domain=.some.com”}
Pros: keep backwards compatibility. Cons: Questionable logic, that need/must be implemented. Should cookiejar be bi-directional (e.g. used for getting and setting cookies)? Should use of cookiejar disable setting Cookie header in Fetch’s config?
[1] https://github.com/rest-assured/rest-assured/wiki/Usage#cookies [2] https://requests.readthedocs.io/en/stable/_modules/requests/cookies/ [3] https://pkg.go.dev/net/http/cookiejar
Contact Details
No response
What happened?
When executing request with Fetch i expect too see multiple values of Set-Cookie header in header's table. Actually, there is only one value of Set-Cookie header. I suppose it happens because table's keys are uniq.
Version
redbean 3.0.0
What operating system are you seeing the problem on?
No response
Relevant log output