1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vweb: secure HttpOnly cookies

This commit is contained in:
Alexander Medvednikov
2019-12-11 03:20:30 +03:00
parent cdfbb2978d
commit f286387647
3 changed files with 8 additions and 3 deletions

View File

@@ -74,11 +74,11 @@ pub fn (ctx Context) not_found(s string) {
pub fn (ctx mut Context) set_cookie(key, val string) { // TODO support directives, escape cookie value (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie)
//println('Set-Cookie $key=$val')
ctx.add_header('Set-Cookie', '$key=$val')
ctx.add_header('Set-Cookie', '$key=$val; Secure; HttpOnly')
}
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_header.find_between(' $key=', ';')
} else {