diff --git a/client.go b/client.go index b5923d1..b5f259e 100644 --- a/client.go +++ b/client.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "net/http" netUrl "net/url" + "path" "strconv" ) @@ -102,10 +103,9 @@ func (c *Client) CreateUpload(u *Upload) (*Uploader, error) { return nil, ErrUrlNotRecognized } if newUrl.Scheme == "" { - newUrl.Scheme = baseUrl.Scheme - url = newUrl.String() + baseUrl.Path = path.Join(baseUrl.Path, url) + url = baseUrl.String() } - if c.Config.Resume { c.Config.Store.Set(u.Fingerprint, url) } diff --git a/client_test.go b/client_test.go index bf2108f..2ed41a3 100644 --- a/client_test.go +++ b/client_test.go @@ -325,6 +325,22 @@ func (s *UploadTestSuite) TestResumeUpload() { s.EqualValues(1048576*150, fi.Size) } +func (s *UploadTestSuite) TestCreateUploadRelativeURL() { + srv := httptest.NewServer(http.HandlerFunc( + func(rw http.ResponseWriter, r *http.Request) { + rw.Header().Add("Location", "xyz") + rw.WriteHeader(http.StatusCreated) + }, + )) + defer srv.Close() + + client, err := NewClient(srv.URL, DefaultConfig()) + s.NoError(err) + upload, err := client.CreateUpload(NewUploadFromBytes([]byte("test"))) + s.NoError(err) + s.Equal(srv.URL+"/xyz", upload.url) +} + func TestUploadTestSuite(t *testing.T) { suite.Run(t, new(UploadTestSuite)) }