bung87 / scorper

scorper is a micro and elegant web framework written in Nim
Apache License 2.0
81 stars 5 forks source link

get cookie value #33

Closed sdmcallister closed 3 years ago

sdmcallister commented 3 years ago

Is there a proc that returns the value of a cookie? Something like:

proc getCookie(req: Request, val: string): string =
  let 
    c = req.headers.table.getOrDefault("Cookie", @[""])
    cookies = c[0].parseCookies()
  result = cookies.getOrDefault(val)

I did a search but didn't see a proc for this. I used the std lib for the parseCookies proc.

bung87 commented 3 years ago

yeah, haven't implement such a api , I think you can do let c:string = req.headers["Cookie"]; let cookies = c.parseCookies(), import std/cookies first.

bung87 commented 3 years ago

fixed in https://github.com/bung87/scorper/commit/25316365c7f70ee782d6a9b61ade07fba503eac7 v1.0.18