mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 20:20:45 +08:00
change log in
This commit is contained in:
parent
9cf026f605
commit
8ca42dd973
211 changed files with 48417 additions and 109 deletions
40
uds-auth/lib/utils/cookie-helpers.js
Normal file
40
uds-auth/lib/utils/cookie-helpers.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* Cookie helper utilities
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get a specific cookie value from a cookie string
|
||||
* @param {string} cookieString - The full cookie header value
|
||||
* @param {string} name - The cookie name to extract
|
||||
* @returns {string|null} The cookie value or null
|
||||
*/
|
||||
export function getCookie(cookieString, name) {
|
||||
if (!cookieString) return null
|
||||
|
||||
const match = cookieString.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`))
|
||||
if (match && match[1]) {
|
||||
return decodeURIComponent(match[1])
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse all cookies from a cookie string
|
||||
* @param {string} cookieString - The full cookie header value
|
||||
* @returns {object} Object with cookie names as keys
|
||||
*/
|
||||
export function parseCookies(cookieString) {
|
||||
if (!cookieString) return {}
|
||||
|
||||
const cookies = {}
|
||||
const pairs = cookieString.split(/;\\s*/)
|
||||
|
||||
for (const pair of pairs) {
|
||||
const [name, ...valueParts] = pair.split('=')
|
||||
if (name) {
|
||||
cookies[name.trim()] = decodeURIComponent(valueParts.join('='))
|
||||
}
|
||||
}
|
||||
|
||||
return cookies
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue