I solved gophercises and on the second exercise I wrote this code:
func mapHandler(
provider func(string) (string, error),
w http.ResponseWriter,
r *http.Request) {
longUrl, err := provider(r.URL.Path)
if err != nil {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintln(w, err.Error())
return
}
w.Header().Add("Location", longUrl)
w.WriteHeader(http.StatusTemporaryRedirect)
}
But on the solution of exercise I see this method:
http.Redirect(...)
So, I looked into implementation of that method, and discovered that it do redirection via html, but
Mozilla write it about redirection:
HTTP redirects are the best way to create redirections, but sometimes you don't have control over the server.
And redirection in that case, is the case where I have control over the server, so what's the reason of redirection via html?