Add functionality to make a url signed for a HEAD request to S4 driver
This commit is contained in:
parent
6b18639eac
commit
bdd5d35622
2 changed files with 20 additions and 1 deletions
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue