From f3b9b66eb034f02a0de447887afe35377dcad5d2 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 13 Jan 2011 07:53:15 -0800 Subject: [PATCH] Follow 303 redirects in Go upload client. --- lib/go/client/upload.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/go/client/upload.go b/lib/go/client/upload.go index e719844de..7bec44865 100644 --- a/lib/go/client/upload.go +++ b/lib/go/client/upload.go @@ -133,9 +133,17 @@ func (c *Client) Upload(h *UploadHandle) (*PutResult, os.Error) { if !ok { return error("303 without a Location", nil) } - log.Printf("other location: %s", otherLocation) - // TODO - log.Exitf("TODO: handle 303? or does the Go http client do it already? how to enforce only 200 and 303 if so?") + relUrl, err := http.ParseURL(otherLocation) + if err != nil { + return error("303 Location URL parse error", err) + } + baseUrl, _ := http.ParseURL(uploadUrl) + absUrl := baseUrl.Add(relUrl) + otherLocation = absUrl.String() + resp, _, err = http.Get(otherLocation) + if err != nil { + return error("error following 303 redirect after upload", err) + } } ures, err := jsonFromResponse(resp)