]> Cypherpunks repositories - gostls13.git/commitdiff
test and fix http redirect handling
authorRuss Cox <rsc@golang.org>
Mon, 19 Oct 2009 19:10:14 +0000 (12:10 -0700)
committerRuss Cox <rsc@golang.org>
Mon, 19 Oct 2009 19:10:14 +0000 (12:10 -0700)
BUG=2197242
R=r
DELTA=16  (16 added, 0 deleted, 0 changed)
OCL=35878
CL=35882

src/pkg/http/client.go
src/pkg/http/request_test.go

index 6ac602f270c76834547b3b4c59af8f91113ab2b8..698c5c7f4fbf72d274d4645e14e76dcf6699f4c2 100644 (file)
@@ -198,6 +198,7 @@ func Get(url string) (r *Response, finalURL string, err os.Error) {
                                err = os.ErrorString(fmt.Sprintf("%d response missing Location header", r.StatusCode));
                                break;
                        }
+                       continue;
                }
                finalURL = url;
                return;
index 94da01521e9f31be3af6c8aec7195a4112698d27..7bddda3db05424d7d0911fb0de0961d58b27b7f2 100644 (file)
@@ -100,3 +100,18 @@ func TestPostContentTypeParsing(t *testing.T) {
                }
        }
 }
+
+func TestRedirect(t *testing.T) {
+       const (
+               start = "http://codesearch.google.com/";
+               end = "http://www.google.com/codesearch";
+       )
+       r, url, err := Get(start);
+       if err != nil {
+               t.Fatal(err);
+       }
+       r.Body.Close();
+       if r.StatusCode != 200 || url != end {
+               t.Fatalf("Get(%s) got status %d at %s, want 200 at %s", start, r.StatusCode, url, end)
+       }
+}