Skip to content

Commit

Permalink
vweb: secure HttpOnly cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Dec 11, 2019
1 parent cdfbb29 commit f286387
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions vlib/builtin/string_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ fn test_replace_each() {
'[code]', '<code>',
'[/code]', '</code>'
]) == '<b>bold</b> <code>code</code>'
bb2 := '[b]cool[/b]'
assert bb2.replace_each([
'[b]', '<b>',
'[/b]', '</b>',
]) == '<b>cool</b>'
}

fn test_itoa() {
Expand Down
2 changes: 1 addition & 1 deletion vlib/vweb/tmpl/tmpl.v
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ _ = header
}
// HTML, may include `@var`
else {
s.writeln(line.replace('@', '\x24').replace('\'', '"') )
s.writeln(line.replace('@', '\x24').replace("'", '"') )
}
}
s.writeln(STR_END)
Expand Down
4 changes: 2 additions & 2 deletions vlib/vweb/vweb.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f286387

Please sign in to comment.