From d743ff4db2267940a3f5de91d151977b5f6870fa Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Sat, 21 Mar 2015 11:28:33 -0600 Subject: [PATCH] Upload() looks for http 200, not 202 --- lfs/client.go | 3 ++- lfs/upload_test.go | 26 +++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lfs/client.go b/lfs/client.go index 6530edd5..9d762505 100644 --- a/lfs/client.go +++ b/lfs/client.go @@ -155,7 +155,7 @@ func Upload(oidPath, filename string, cb CopyCallback) *WrappedError { return wErr } - if res.StatusCode == 202 { + if res.StatusCode == 200 { return nil } @@ -168,6 +168,7 @@ func Upload(oidPath, filename string, cb CopyCallback) *WrappedError { req.Header.Set("Content-Type", "application/octet-stream") } req.Header.Set("Content-Length", strconv.FormatInt(reqObj.Size, 10)) + req.ContentLength = reqObj.Size reader := &CallbackReader{ C: cb, diff --git a/lfs/upload_test.go b/lfs/upload_test.go index ca6f37e1..a28424cd 100644 --- a/lfs/upload_test.go +++ b/lfs/upload_test.go @@ -81,7 +81,7 @@ func TestExistingUpload(t *testing.T) { head := w.Header() head.Set("Content-Type", mediaType) head.Set("Content-Length", strconv.Itoa(len(by))) - w.WriteHeader(202) + w.WriteHeader(200) w.Write(by) }) @@ -200,7 +200,7 @@ func TestSuccessfulUploadWithVerify(t *testing.T) { head := w.Header() head.Set("Content-Type", mediaType) head.Set("Content-Length", strconv.Itoa(len(by))) - w.WriteHeader(200) + w.WriteHeader(202) w.Write(by) }) @@ -220,6 +220,14 @@ func TestSuccessfulUploadWithVerify(t *testing.T) { t.Error("Invalid Content-Type") } + if r.Header.Get("Content-Length") != "4" { + t.Error("Invalid Content-Length") + } + + if r.Header.Get("Transfer-Encoding") != "" { + t.Fatal("Transfer-Encoding is set") + } + by, err := ioutil.ReadAll(r.Body) if err != nil { t.Error(err) @@ -379,7 +387,7 @@ func TestSuccessfulUploadWithoutVerify(t *testing.T) { head := w.Header() head.Set("Content-Type", mediaType) head.Set("Content-Length", strconv.Itoa(len(by))) - w.WriteHeader(200) + w.WriteHeader(202) w.Write(by) }) @@ -399,6 +407,14 @@ func TestSuccessfulUploadWithoutVerify(t *testing.T) { t.Error("Invalid Content-Type") } + if r.Header.Get("Content-Length") != "4" { + t.Error("Invalid Content-Length") + } + + if r.Header.Get("Transfer-Encoding") != "" { + t.Fatal("Transfer-Encoding is set") + } + by, err := ioutil.ReadAll(r.Body) if err != nil { t.Error(err) @@ -541,7 +557,7 @@ func TestUploadStorageError(t *testing.T) { head := w.Header() head.Set("Content-Type", mediaType) head.Set("Content-Length", strconv.Itoa(len(by))) - w.WriteHeader(200) + w.WriteHeader(202) w.Write(by) }) @@ -646,7 +662,7 @@ func TestUploadVerifyError(t *testing.T) { head := w.Header() head.Set("Content-Type", mediaType) head.Set("Content-Length", strconv.Itoa(len(by))) - w.WriteHeader(200) + w.WriteHeader(202) w.Write(by) })