@@ -13,7 +13,6 @@ pub type SameSitePolicy {
13
13
14
14
pub type Attributes {
15
15
Attributes (
16
- // Expires is deprecated, we can still serialize a value for max compatibility
17
16
max_age : Option ( Int ) ,
18
17
domain : Option ( String ) ,
19
18
path : Option ( String ) ,
@@ -47,34 +46,33 @@ pub fn default_attributes() {
47
46
}
48
47
49
48
fn same_site_to_string ( policy ) {
50
- case policy {
51
- Lax -> "Lax"
52
- Strict -> "Strict"
53
- None -> "None"
54
- }
49
+ case policy {
50
+ Lax -> "Lax"
51
+ Strict -> "Strict"
52
+ None -> "None"
53
+ }
55
54
}
56
55
57
56
pub fn expire_attributes ( attributes ) {
58
- let Attributes (
59
- max_age : _max_age ,
60
- domain : domain ,
61
- path : path ,
62
- secure : secure ,
63
- http_only : http_only ,
64
- same_site : same_site ,
65
- ) = attributes
66
- Attributes (
67
- max_age : Some ( 0 ) ,
68
- domain : domain ,
69
- path : path ,
70
- secure : secure ,
71
- http_only : http_only ,
72
- same_site : same_site ,
73
- )
57
+ let Attributes (
58
+ max_age : _max_age ,
59
+ domain : domain ,
60
+ path : path ,
61
+ secure : secure ,
62
+ http_only : http_only ,
63
+ same_site : same_site ,
64
+ ) = attributes
65
+ Attributes (
66
+ max_age : Some ( 0 ) ,
67
+ domain : domain ,
68
+ path : path ,
69
+ secure : secure ,
70
+ http_only : http_only ,
71
+ same_site : same_site ,
72
+ )
74
73
}
75
74
76
-
77
- pub fn attributes_to_list ( attributes ) {
75
+ fn attributes_to_list ( attributes ) {
78
76
let Attributes (
79
77
max_age : max_age ,
80
78
domain : domain ,
@@ -84,9 +82,13 @@ pub fn attributes_to_list(attributes) {
84
82
same_site : same_site ,
85
83
) = attributes
86
84
[
85
+ // Expires is a deprecated attribute for cookies, it has been replaced with MaxAge
86
+ // MaxAge is widely supported and so Expires values are not set.
87
+ // Only when deleting cookies is the exception made to use the old format,
88
+ // to ensure complete clearup of cookies if required by an application.
87
89
case max_age {
88
- Some ( 0 ) -> Some ( [ "expires =Thu, 01 Jan 1970 00:00:00 GMT" ] )
89
- _ -> option . None
90
+ Some ( 0 ) -> Some ( [ "Expires =Thu, 01 Jan 1970 00:00:00 GMT" ] )
91
+ _ -> option . None
90
92
} ,
91
93
option . map ( max_age , fn ( max_age ) { [ "MaxAge=" , int . to_string ( max_age ) ] } ) ,
92
94
option . map ( domain , fn ( domain ) { [ "Domain=" , domain ] } ) ,
@@ -112,5 +114,3 @@ pub fn set_cookie_string(key, value, attributes) {
112
114
|> list . map ( string . join ( _, "" ) )
113
115
|> string . join ( "; " )
114
116
}
115
- // // Plug sets secure true automatically if request/conn is https
116
- // // https://github.com/elixir-plug/plug/blob/v1.10.3/lib/plug/conn.ex#L1464
0 commit comments