http: Client.Do should follow redirects for GET and HEAD

It's documented as such, but it was never wired up
after Transport went in and Head was fixed.

If people don't want redirects, that's what RoundTripper/
Transport are for.  Or a custom redirect policy.

R=golang-dev, kevlar
CC=golang-dev
https://golang.org/cl/4526065
This commit is contained in:
Brad Fitzpatrick 2011-05-18 17:17:26 -07:00
parent 1d550bdedf
commit 4ffff35abd
2 changed files with 44 additions and 25 deletions

View file

@ -98,13 +98,20 @@ func TestRedirects(t *testing.T) {
c := &Client{}
_, err := c.Get(ts.URL)
if e, g := "Get /?n=10: stopped after 10 redirects", fmt.Sprintf("%v", err); e != g {
t.Errorf("with default client, expected error %q, got %q", e, g)
t.Errorf("with default client Get, expected error %q, got %q", e, g)
}
// HEAD request should also have the ability to follow redirects.
_, err = c.Head(ts.URL)
if e, g := "Head /?n=10: stopped after 10 redirects", fmt.Sprintf("%v", err); e != g {
t.Errorf("with default client, expected error %q, got %q", e, g)
t.Errorf("with default client Head, expected error %q, got %q", e, g)
}
// Do should also follow redirects.
greq, _ := NewRequest("GET", ts.URL, nil)
_, err = c.Do(greq)
if e, g := "Get /?n=10: stopped after 10 redirects", fmt.Sprintf("%v", err); e != g {
t.Errorf("with default client Do, expected error %q, got %q", e, g)
}
var checkErr os.Error