Skip to content

Commit

Permalink
fix: 修复cookie在http协议下设置不生效的问题 weaigc#65
Browse files Browse the repository at this point in the history
  • Loading branch information
weaigc committed Sep 11, 2023
1 parent ecd32b3 commit 7f0cfde
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bingo",
"version": "0.6.2",
"version": "0.6.3",
"private": true,
"scripts": {
"dev": "cross-env DEBUG=bingo* next dev --hostname 0.0.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function parseHeadersFromCurl(content: string) {
const re = /-H '([^:]+):\s*([^']+)/mg
const headers: HeadersInit = {}
content = content.replaceAll('-H "', '-H \'').replaceAll('" ^', '\'\\').replaceAll('^\\^"', '"') // 将 cmd curl 转成 bash curl
content.split('curl ').shift()?.replace(re, (_: string, key: string, value: string) => {
content.split('curl ')[1]?.replace(re, (_: string, key: string, value: string) => {
headers[key] = value
return ''
})
Expand Down Expand Up @@ -113,7 +113,7 @@ export function parseCookie(cookie: string, cookieName: string) {

export function setCookie(key: string, value?: string) {
const cookie = value === undefined ? key : `${key}=${value || ''}`
const maxAge = cookie.endsWith('=') ? 0 : 86400 * 30
const maxAge = value === '' ? 0 : 86400 * 30
const cookieSuffix = location.protocol === 'http:' ? '' : 'SameSite=None; Secure'
document.cookie = `${cookie}; Path=/; Max-Age=${maxAge}; ${cookieSuffix}`
}
Expand Down

0 comments on commit 7f0cfde

Please sign in to comment.