Skip to content

Commit

Permalink
Context redirect uses the built-in redirect facility
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Apr 7, 2015
1 parent c0e8ced commit 3abeba8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ func (c *Context) HTMLString(code int, format string, values ...interface{}) {
// Returns a HTTP redirect to the specific location.
func (c *Context) Redirect(code int, location string) {
if code >= 300 && code <= 308 {
c.Render(code, render.Redirect, location)
c.Render(code, render.Redirect, c.Request, location)
} else {
log.Panicf("Cannot send a redirect with status code %d", code)
log.Panicf("Cannot redirect with status code %d", code)
}
}

Expand Down
5 changes: 3 additions & 2 deletions render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ var (
)

func (_ redirectRender) Render(w http.ResponseWriter, code int, data ...interface{}) error {
w.Header().Set("Location", data[0].(string))
w.WriteHeader(code)
req := data[0].(*http.Request)
location := data[1].(string)
http.Redirect(w, req, location, code)
return nil
}

Expand Down

0 comments on commit 3abeba8

Please sign in to comment.