Skip to content

fix #224 Unable to set multiple cookies in a single web request #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions jester.nim
Original file line number Diff line number Diff line change
Expand Up @@ -514,17 +514,22 @@ template setHeader(headers: var Option[RawHeaders], key, value: string): typed =
if isNone(headers):
headers = some(@({key: value}))
else:
block outer:
# Overwrite key if it exists.
var h = headers.get()
for i in 0 ..< h.len:
if h[i][0] == key:
h[i][1] = value
headers = some(h)
break outer

# Add key if it doesn't exist.
var h = headers.get()
var isContains = false
var n = 0
for i, row in h:
if toLowerAscii(row[0]) == toLowerAscii(key):
isContains = true
n = i
break

if not isContains or toLowerAscii(key) == "set-cookie":
# Add new key and value
headers = some(h & @({key: value}))
else:
# add to existing value
h[n][1] = h[n][1] & ", " & value
headers = some(h)

template resp*(code: HttpCode,
headers: openarray[tuple[key, val: string]],
Expand Down