mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
1d550bdedf
commit
4ffff35abd
2 changed files with 44 additions and 25 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue