http: remove finalURL from Client.Get; move to Response

This CL:

-- removes Response.RequestMethod string
-- adds Response.Request *Request
-- removes the finalURL result parameter from client.Get()
-- adds a gofix rule for callers of http.Get which assign
   the final url to the blank identifier; warning otherwise

Caller who did:

res, finalURL, err := http.Get(...)

now need to do:

res, err := http.Get(...)
if err != nil {
   ...
}
finalURL := res.Request.URL.String()

R=rsc
CC=golang-dev
https://golang.org/cl/4535056
This commit is contained in:
Brad Fitzpatrick 2011-05-13 07:31:24 -07:00
parent 4336116d3b
commit 05a1b7ec41
22 changed files with 203 additions and 100 deletions

View file

@ -26,7 +26,7 @@ func TestClient(t *testing.T) {
ts := httptest.NewServer(robotsTxtHandler)
defer ts.Close()
r, _, err := Get(ts.URL)
r, err := Get(ts.URL)
var b []byte
if err == nil {
b, err = ioutil.ReadAll(r.Body)
@ -96,7 +96,7 @@ func TestRedirects(t *testing.T) {
defer ts.Close()
c := &Client{}
_, _, err := c.Get(ts.URL)
_, 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)
}
@ -107,7 +107,8 @@ func TestRedirects(t *testing.T) {
lastVia = via
return checkErr
}}
_, finalUrl, err := c.Get(ts.URL)
res, err := c.Get(ts.URL)
finalUrl := res.Request.URL.String()
if e, g := "<nil>", fmt.Sprintf("%v", err); e != g {
t.Errorf("with custom client, expected error %q, got %q", e, g)
}
@ -119,7 +120,8 @@ func TestRedirects(t *testing.T) {
}
checkErr = os.NewError("no redirects allowed")
_, finalUrl, err = c.Get(ts.URL)
res, err = c.Get(ts.URL)
finalUrl = res.Request.URL.String()
if e, g := "Get /?n=1: no redirects allowed", fmt.Sprintf("%v", err); e != g {
t.Errorf("with redirects forbidden, expected error %q, got %q", e, g)
}