Skip to content

Instantly share code, notes, and snippets.

@brnstz
Last active August 29, 2015 14:00
Show Gist options
  • Save brnstz/6da4de6e934201236850 to your computer and use it in GitHub Desktop.
Save brnstz/6da4de6e934201236850 to your computer and use it in GitHub Desktop.
HTTP client in Go that doesn't follow redirects
package main
import (
"errors"
"fmt"
"net/http"
)
var noRedirect = errors.New("no redirect")
func noRedirectPolicy(req *http.Request, via []*http.Request) error {
return noRedirect
}
func main() {
client := &http.Client{CheckRedirect: noRedirectPolicy}
// This should have a final slash, nytimes.com will tell us
resp, _ := client.Get("http://www.nytimes.com/pages/topics")
if resp != nil {
fmt.Println(resp.Header.Get("Location"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment