« Back to Index

Don’t follow 301 redirect

View original Gist on GitHub

Tags: #go #http

golang don’t follow 301 redirect.md

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

if CheckRedirect returns http.ErrUseLastResponse, then the most recent response is returned with its body unclosed, along with a nil error.