it redirects with a status code and location header, it just also sends a
body
the comments in the code explains why
https://cs.opensource.google/go/go/+/refs/tags/go1.24.0:src/net/http/server.go;l=2410

- sean

On Sun, Feb 23, 2025, 19:10 Vladislav (wennerryle) <wennerr...@gmail.com>
wrote:

> 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
> <https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections> 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?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion visit
> https://groups.google.com/d/msgid/golang-nuts/e52f2809-8f53-42ad-af43-6239444827d8n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/e52f2809-8f53-42ad-af43-6239444827d8n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/CAGabyPru0f0vMUGDSM28ZBzPtDJTqwS%3DWNFz_LyZX0p9e1%2B7ow%40mail.gmail.com.

Reply via email to