diff --git a/storagedriver/s3/s3.go b/storagedriver/s3/s3.go index 69f34877..991f2b00 100644 --- a/storagedriver/s3/s3.go +++ b/storagedriver/s3/s3.go @@ -642,6 +642,15 @@ func (d *Driver) URLFor(path string, options map[string]interface{}) (string, er return "", storagedriver.InvalidPathError{Path: path} } + methodString := "GET" + method, ok := options["method"] + if ok { + methodString, ok = method.(string) + if !ok || (methodString != "GET" && methodString != "HEAD") { + return "", storagedriver.ErrUnsupportedMethod + } + } + expiresTime := time.Now().Add(20 * time.Minute) expires, ok := options["expiry"] if ok { @@ -651,7 +660,7 @@ func (d *Driver) URLFor(path string, options map[string]interface{}) (string, er } } - return d.Bucket.SignedURL(d.s3Path(path), expiresTime), nil + return d.Bucket.SignedURLWithMethod(methodString, d.s3Path(path), expiresTime, nil, nil), nil } func (d *Driver) s3Path(path string) string { diff --git a/storagedriver/testsuites/testsuites.go b/storagedriver/testsuites/testsuites.go index 486640c4..c3229fcc 100644 --- a/storagedriver/testsuites/testsuites.go +++ b/storagedriver/testsuites/testsuites.go @@ -605,6 +605,16 @@ func (suite *DriverSuite) TestURLFor(c *check.C) { read, err := ioutil.ReadAll(response.Body) c.Assert(err, check.IsNil) c.Assert(read, check.DeepEquals, contents) + + url, err = suite.StorageDriver.URLFor(filename, map[string]interface{}{"method": "HEAD"}) + if err == storagedriver.ErrUnsupportedMethod { + return + } + c.Assert(err, check.IsNil) + + response, err = http.Head(url) + c.Assert(response.StatusCode, check.Equals, 200) + c.Assert(response.ContentLength, check.Equals, int64(32)) } // TestDeleteNonexistent checks that removing a nonexistent key fails.