Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F6164423
Cookies.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
Cookies.js
View Options
/**
* Collects cookies from HTTP responses and formats them into a Cookie header.
*/
export
class
Cookies
{
constructor
()
{
this
.
pairs
=
{};
}
/**
* Add cookies from Set-Cookie header lines.
*
* @param {Iterable<string>} setCookies - Iterable of `Set-Cookie` header lines.
*/
getCookiesFromHeaders
(
setCookies
)
{
for
(
const
line
of
setCookies
)
{
// Take the first part of the cookie so we can pass it on the next time
const
semi
=
line
.
indexOf
(
';'
);
const
pair
=
semi
===
-
1
?
line
:
line
.
slice
(
0
,
semi
);
const
equalSign
=
pair
.
indexOf
(
'='
);
const
name
=
pair
.
slice
(
0
,
equalSign
);
const
value
=
pair
.
slice
(
equalSign
+
1
);
this
.
pairs
[
name
]
=
value
;
}
}
/**
* Build the Cookie request header value.
*
* @return {string} e.g. "a=1; b=2" or "" if no cookies
*/
toHeader
()
{
const
entries
=
Object
.
entries
(
this
.
pairs
);
if
(
entries
.
length
===
0
)
{
return
''
;
}
return
entries
.
map
(
(
[
name
,
value
]
)
=>
`
${
name
}
=
${
value
}
`
).
join
(
'; '
);
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Oct 8 2026, 13:05 (7 w, 2 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
a4/4b/ce9a603c8b05cfa248f57a171bcb
Default Alt Text
Cookies.js (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment