Skip to content

Commit

Permalink
must set cookie before write http body
Browse files Browse the repository at this point in the history
  • Loading branch information
dworld committed Nov 8, 2014
1 parent 927b2dd commit c617d35
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* XSRF context and pipe handler OK
* change behaiver of default pipe handler OK
* context use ResponseWriter instead of http.ResponseWriter OK
* panic if write header after body
* add PipeHandler ErrorPage
* panic if write header after body OK
* add Session
* add PipeHandler ErrorPage
* Example
6 changes: 6 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,9 @@ func (ctx *Context) parseParams() {
ctx.Params[k] = v[0]
}
}

func (ctx *Context) checkHeaderWrite() {
if ctx.ResponseWriter.Written() {
panic(fmt.Errorf("must write header before body"))
}
}
1 change: 1 addition & 0 deletions context_cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func (ctx *Context) SetCookie(name string, value interface{}) {
}

func (ctx *Context) SetExpireCookie(name string, value interface{}, sec int64) {
ctx.checkHeaderWrite()
cookier := ctx.Server.SecureCookie
encoded, err := cookier.Encode(name, value)
if err != nil {
Expand Down

0 comments on commit c617d35

Please sign in to comment.