Reputation: 307
I know that in a PHP web app if you redirect using header('Location: http://somewhere.com') but you don't die() / exit(), the code after the header function is always executed and displayed. I would like to know if when using http.Redirect(w, r, "/somewhere", 302) in Go happens the same. And if yes how could avoid it.
Upvotes: 0
Views: 47
Reputation: 121199
The http.Redirect function writes a complete response. The program continues to execute after the call to http.Redirect. If the call to http.Redirect is not the last line of the function, then it is typical for applications to return from the handler immediately after the call.
func serveFoo(w http.ResponseWriter, r *http.Request) {
...
http.Redirect(w, r, "/somewhere", 302)
return
...
}
Upvotes: 2