mholt / curl-to-go

Convert curl commands to Go code in your browser

Home Page:https://mholt.github.io/curl-to-go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

orcaman opened this issue · 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

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

Documented with b9a94c3