d02e32fa by astaxie

Merge pull request #1103 from ElvizLai/patch-1

Update output.go
2 parents 49c0f890 9261c805
...@@ -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,28 +99,30 @@ func (output *BeegoOutput) Body(content []byte) { ...@@ -98,28 +99,30 @@ 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))
101 if len(others) > 0 { 102
102 switch v := others[0].(type) { 103 //fix cookie not work in IE
103 case int: 104 if len(others) > 0 {
104 if v > 0 { 105 switch v := others[0].(type) {
105 fmt.Fprintf(&b, "; Max-Age=%d", v) 106 case int:
106 } else if v < 0 { 107 if v > 0 {
107 fmt.Fprintf(&b, "; Max-Age=0") 108 fmt.Fprintf(&b, "; Expires=%s; Max-Age=%d", time.Now().Add(time.Duration(v) * time.Second).UTC().Format(time.RFC1123), v)
108 } 109 } else if v < 0 {
109 case int64: 110 fmt.Fprintf(&b, "; Max-Age=0")
110 if v > 0 { 111 }
111 fmt.Fprintf(&b, "; Max-Age=%d", v) 112 case int64:
112 } else if v < 0 { 113 if v > 0 {
113 fmt.Fprintf(&b, "; Max-Age=0") 114 fmt.Fprintf(&b, "; Expires=%s; Max-Age=%d", time.Now().Add(time.Duration(v) * time.Second).UTC().Format(time.RFC1123), v)
114 } 115 } else if v < 0 {
115 case int32: 116 fmt.Fprintf(&b, "; Max-Age=0")
116 if v > 0 { 117 }
117 fmt.Fprintf(&b, "; Max-Age=%d", v) 118 case int32:
118 } else if v < 0 { 119 if v > 0 {
119 fmt.Fprintf(&b, "; Max-Age=0") 120 fmt.Fprintf(&b, "; Expires=%s; Max-Age=%d", time.Now().Add(time.Duration(v) * time.Second).UTC().Format(time.RFC1123), v)
120 } 121 } else if v < 0 {
121 } 122 fmt.Fprintf(&b, "; Max-Age=0")
122 } 123 }
124 }
125 }
123 126
124 // the settings below 127 // the settings below
125 // Path, Domain, Secure, HttpOnly 128 // Path, Domain, Secure, HttpOnly
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!