Update output.go
fix cookie not work in IE
Showing
1 changed file
with
5 additions
and
3 deletions
| ... | @@ -98,23 +98,25 @@ func (output *BeegoOutput) Body(content []byte) { | ... | @@ -98,23 +98,25 @@ func (output *BeegoOutput) Body(content []byte) { |
| 98 | func (output *BeegoOutput) Cookie(name string, value string, others ...interface{}) { | 98 | func (output *BeegoOutput) Cookie(name string, value string, others ...interface{}) { |
| 99 | var b bytes.Buffer | 99 | var b bytes.Buffer |
| 100 | fmt.Fprintf(&b, "%s=%s", sanitizeName(name), sanitizeValue(value)) | 100 | fmt.Fprintf(&b, "%s=%s", sanitizeName(name), sanitizeValue(value)) |
| 101 | |||
| 102 | //fix cookie not work in IE | ||
| 101 | if len(others) > 0 { | 103 | if len(others) > 0 { |
| 102 | switch v := others[0].(type) { | 104 | switch v := others[0].(type) { |
| 103 | case int: | 105 | case int: |
| 104 | if v > 0 { | 106 | if v > 0 { |
| 105 | fmt.Fprintf(&b, "; Max-Age=%d", v) | 107 | fmt.Fprintf(&b, "; Expires=%s; Max-Age=%d", time.Now().Add(time.Duration(v) * time.Second).UTC().Format(time.RFC1123), v) |
| 106 | } else if v < 0 { | 108 | } else if v < 0 { |
| 107 | fmt.Fprintf(&b, "; Max-Age=0") | 109 | fmt.Fprintf(&b, "; Max-Age=0") |
| 108 | } | 110 | } |
| 109 | case int64: | 111 | case int64: |
| 110 | if v > 0 { | 112 | if v > 0 { |
| 111 | fmt.Fprintf(&b, "; Max-Age=%d", v) | 113 | fmt.Fprintf(&b, "; Expires=%s; Max-Age=%d", time.Now().Add(time.Duration(v) * time.Second).UTC().Format(time.RFC1123), v) |
| 112 | } else if v < 0 { | 114 | } else if v < 0 { |
| 113 | fmt.Fprintf(&b, "; Max-Age=0") | 115 | fmt.Fprintf(&b, "; Max-Age=0") |
| 114 | } | 116 | } |
| 115 | case int32: | 117 | case int32: |
| 116 | if v > 0 { | 118 | if v > 0 { |
| 117 | fmt.Fprintf(&b, "; Max-Age=%d", v) | 119 | fmt.Fprintf(&b, "; Expires=%s; Max-Age=%d", time.Now().Add(time.Duration(v) * time.Second).UTC().Format(time.RFC1123), v) |
| 118 | } else if v < 0 { | 120 | } else if v < 0 { |
| 119 | fmt.Fprintf(&b, "; Max-Age=0") | 121 | fmt.Fprintf(&b, "; Max-Age=0") |
| 120 | } | 122 | } | ... | ... |
-
Please register or sign in to post a comment