vweb: fix get_cookie()

pull/3009/head
Alexander Medvednikov 2019-12-08 01:48:49 +03:00
parent 5330859034
commit 7adda3b71a
1 changed files with 4 additions and 5 deletions

View File

@ -70,15 +70,14 @@ pub fn (ctx mut Context) set_cookie(key, val string) { // TODO support directive
} }
pub fn (ctx &Context) get_cookie(key string) ?string { // TODO refactor pub fn (ctx &Context) get_cookie(key string) ?string { // TODO refactor
cookie_header := ctx.get_header('Cookie') cookie_header := ' ' + ctx.get_header('Cookie')
cookie := if cookie_header.contains(';') { cookie := if cookie_header.contains(';') {
cookie_header.find_between('$key=', ';') cookie_header.find_between(' $key=', ';')
} else { } else {
cookie_header.find_between('$key=', '\r') cookie_header.find_between(' $key=', '\r')
//cookie_header
} }
if cookie != '' { if cookie != '' {
return cookie return cookie.trim_space()
} }
return error('Cookie not found') return error('Cookie not found')
} }