Merge pull request #1103 from ElvizLai/patch-1
Update output.go
Showing
1 changed file
with
6 additions
and
3 deletions
| ... | @@ -29,6 +29,7 @@ import ( | ... | @@ -29,6 +29,7 @@ import ( |
| 29 | "path/filepath" | 29 | "path/filepath" |
| 30 | "strconv" | 30 | "strconv" |
| 31 | "strings" | 31 | "strings" |
| 32 | "time" | ||
| 32 | ) | 33 | ) |
| 33 | 34 | ||
| 34 | // BeegoOutput does work for sending response header. | 35 | // BeegoOutput does work for sending response header. |
| ... | @@ -98,23 +99,25 @@ func (output *BeegoOutput) Body(content []byte) { | ... | @@ -98,23 +99,25 @@ func (output *BeegoOutput) Body(content []byte) { |
| 98 | func (output *BeegoOutput) Cookie(name string, value string, others ...interface{}) { | 99 | func (output *BeegoOutput) Cookie(name string, value string, others ...interface{}) { |
| 99 | var b bytes.Buffer | 100 | var b bytes.Buffer |
| 100 | fmt.Fprintf(&b, "%s=%s", sanitizeName(name), sanitizeValue(value)) | 101 | fmt.Fprintf(&b, "%s=%s", sanitizeName(name), sanitizeValue(value)) |
| 102 | |||
| 103 | //fix cookie not work in IE | ||
| 101 | if len(others) > 0 { | 104 | if len(others) > 0 { |
| 102 | switch v := others[0].(type) { | 105 | switch v := others[0].(type) { |
| 103 | case int: | 106 | case int: |
| 104 | if v > 0 { | 107 | if v > 0 { |
| 105 | fmt.Fprintf(&b, "; Max-Age=%d", v) | 108 | 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 { | 109 | } else if v < 0 { |
| 107 | fmt.Fprintf(&b, "; Max-Age=0") | 110 | fmt.Fprintf(&b, "; Max-Age=0") |
| 108 | } | 111 | } |
| 109 | case int64: | 112 | case int64: |
| 110 | if v > 0 { | 113 | if v > 0 { |
| 111 | fmt.Fprintf(&b, "; Max-Age=%d", v) | 114 | 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 { | 115 | } else if v < 0 { |
| 113 | fmt.Fprintf(&b, "; Max-Age=0") | 116 | fmt.Fprintf(&b, "; Max-Age=0") |
| 114 | } | 117 | } |
| 115 | case int32: | 118 | case int32: |
| 116 | if v > 0 { | 119 | if v > 0 { |
| 117 | fmt.Fprintf(&b, "; Max-Age=%d", v) | 120 | 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 { | 121 | } else if v < 0 { |
| 119 | fmt.Fprintf(&b, "; Max-Age=0") | 122 | fmt.Fprintf(&b, "; Max-Age=0") |
| 120 | } | 123 | } | ... | ... |
-
Please register or sign in to post a comment