mholt/curl-to-go

Go's default http client follows redirection while curl does not

orcaman opened this issue · 3 comments

Hi,

The use of the default http client (resp, err := http.DefaultClient.Do(req) causes a bug: when the response returns a redirection, go's default http client follows that redirection by default, while curl does not.

The client in use here should be changed from the default client to this:

client := &http.Client{
    CheckRedirect: func(req *http.Request, via []*http.Request) error {
        return http.ErrUseLastResponse
    },
}

This will fix this incolcnsistany with curl.

Cheers

mholt commented

I'm glad you pointed out this inconsistency... I need to decide if we want to make http.Client values automatically here or just stick with http.DefaultClient, since clients are supposed to be reused...

this needs then alignment with the --location command which is very important with curl usage, so then, following a redirect should be done

mholt commented

Documented with b9a94c3