vweb: add cookies with expire date
parent
7565fe595b
commit
616b07204d
|
@ -179,3 +179,11 @@ pub fn (t Time) get_fmt_str(fmt_dlmtr FormatDelimiter, fmt_time FormatTime, fmt_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is just a TEMPORARY function for cookies and their expire dates
|
||||||
|
pub fn (time Time) utc_string() string {
|
||||||
|
day_str := time.weekday_str()
|
||||||
|
month_str := time.smonth()
|
||||||
|
utc_string := '$day_str, $time.day $month_str $time.year ${time.hour:02d}:${time.minute:02d}:${time.second:02d} UTC'
|
||||||
|
return utc_string
|
||||||
|
}
|
||||||
|
|
|
@ -82,3 +82,7 @@ fn test_get_fmt_str() {
|
||||||
// combinations.
|
// combinations.
|
||||||
assert '11.07.1980 21:23:42' == time_to_test.get_fmt_str(.dot, .hhmmss24, .ddmmyyyy)
|
assert '11.07.1980 21:23:42' == time_to_test.get_fmt_str(.dot, .hhmmss24, .ddmmyyyy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_utc_string() {
|
||||||
|
assert 'Fri, 11 Jul 1980 21:23:42 UTC' == time_to_test.utc_string()
|
||||||
|
}
|
||||||
|
|
|
@ -115,6 +115,10 @@ pub fn (mut ctx Context) set_content_type(typ string) {
|
||||||
ctx.content_type = typ
|
ctx.content_type = typ
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn (mut ctx Context) set_cookie_with_expire_date(key, val string, expire_date time.Time) {
|
||||||
|
ctx.add_header('Set-Cookie', '$key=$val; Secure; HttpOnly; expires=${expire_date.utc_string()}')
|
||||||
|
}
|
||||||
|
|
||||||
pub fn (ctx &Context) get_cookie(key string) ?string { // TODO refactor
|
pub fn (ctx &Context) get_cookie(key string) ?string { // TODO refactor
|
||||||
mut cookie_header := ctx.get_header('cookie')
|
mut cookie_header := ctx.get_header('cookie')
|
||||||
if cookie_header == '' {
|
if cookie_header == '' {
|
||||||
|
|
Loading…
Reference in New Issue