Skip to content

Instantly share code, notes, and snippets.

@s-aska
Created March 3, 2016 10:17
Show Gist options
  • Save s-aska/0badbf1d7c3e49b9790f to your computer and use it in GitHub Desktop.
Save s-aska/0badbf1d7c3e49b9790f to your computer and use it in GitHub Desktop.
🔫 Don't redirect !!!
package main
import(
"errors"
"fmt"
"net/http"
)
var RedirectAttemptedError = errors.New("redirect")
var nopasteClient = func() (*http.Client) {
var client = &http.Client{}
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
return RedirectAttemptedError
}
return client
}()
func main() {
resp, _ := nopasteClient.Get("https://goo.gl/xqt7hT")
url, _ := resp.Location()
if url != nil {
fmt.Println(url.String())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment