use http consts for request methods

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2022-11-02 23:31:23 +01:00
parent 7f9f86c411
commit f9ccd2c6ea
33 changed files with 211 additions and 211 deletions

View File

@@ -321,7 +321,7 @@ func getObject(client *http.Client, bucket string, name string, offset int64) (*
Host: "storage.googleapis.com",
Path: fmt.Sprintf("/%s/%s", bucket, name),
}
req, err := http.NewRequest("GET", u.String(), nil)
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
return nil, err
}
@@ -808,11 +808,11 @@ func (d *driver) URLFor(context context.Context, path string, options map[string
}
name := d.pathToKey(path)
methodString := "GET"
methodString := http.MethodGet
method, ok := options["method"]
if ok {
methodString, ok = method.(string)
if !ok || (methodString != "GET" && methodString != "HEAD") {
if !ok || (methodString != http.MethodGet && methodString != http.MethodHead) {
return "", storagedriver.ErrUnsupportedMethod{}
}
}
@@ -849,7 +849,7 @@ func startSession(client *http.Client, bucket string, name string) (uri string,
RawQuery: fmt.Sprintf("uploadType=resumable&name=%v", name),
}
err = retry(func() error {
req, err := http.NewRequest("POST", u.String(), nil)
req, err := http.NewRequest(http.MethodPost, u.String(), nil)
if err != nil {
return err
}
@@ -873,7 +873,7 @@ func startSession(client *http.Client, bucket string, name string) (uri string,
func putChunk(client *http.Client, sessionURI string, chunk []byte, from int64, totalSize int64) (int64, error) {
bytesPut := int64(0)
err := retry(func() error {
req, err := http.NewRequest("PUT", sessionURI, bytes.NewReader(chunk))
req, err := http.NewRequest(http.MethodPut, sessionURI, bytes.NewReader(chunk))
if err != nil {
return err
}

View File

@@ -465,11 +465,11 @@ func (d *driver) Delete(ctx context.Context, path string) error {
// URLFor returns a URL which may be used to retrieve the content stored at the given path.
// May return an UnsupportedMethodErr in certain StorageDriver implementations.
func (d *driver) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) {
methodString := "GET"
methodString := http.MethodGet
method, ok := options["method"]
if ok {
methodString, ok = method.(string)
if !ok || (methodString != "GET") {
if !ok || (methodString != http.MethodGet) {
return "", storagedriver.ErrUnsupportedMethod{}
}
}

View File

@@ -1005,11 +1005,11 @@ ListLoop:
// URLFor returns a URL which may be used to retrieve the content stored at the given path.
// May return an UnsupportedMethodErr in certain StorageDriver implementations.
func (d *driver) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) {
methodString := "GET"
methodString := http.MethodGet
method, ok := options["method"]
if ok {
methodString, ok = method.(string)
if !ok || (methodString != "GET" && methodString != "HEAD") {
if !ok || (methodString != http.MethodGet && methodString != http.MethodHead) {
return "", storagedriver.ErrUnsupportedMethod{}
}
}
@@ -1026,12 +1026,12 @@ func (d *driver) URLFor(ctx context.Context, path string, options map[string]int
var req *request.Request
switch methodString {
case "GET":
case http.MethodGet:
req, _ = d.S3.GetObjectRequest(&s3.GetObjectInput{
Bucket: aws.String(d.Bucket),
Key: aws.String(d.s3Path(path)),
})
case "HEAD":
case http.MethodHead:
req, _ = d.S3.HeadObjectRequest(&s3.HeadObjectInput{
Bucket: aws.String(d.Bucket),
Key: aws.String(d.s3Path(path)),

View File

@@ -608,7 +608,7 @@ func (d *driver) URLFor(ctx context.Context, path string, options map[string]int
return "", storagedriver.ErrUnsupportedMethod{}
}
methodString := "GET"
methodString := http.MethodGet
method, ok := options["method"]
if ok {
if methodString, ok = method.(string); !ok {
@@ -616,10 +616,10 @@ func (d *driver) URLFor(ctx context.Context, path string, options map[string]int
}
}
if methodString == "HEAD" {
if methodString == http.MethodHead {
// A "HEAD" request on a temporary URL is allowed if the
// signature was generated with "GET", "POST" or "PUT"
methodString = "GET"
methodString = http.MethodGet
}
supported := false

View File

@@ -645,7 +645,7 @@ func (suite *DriverSuite) TestURLFor(c *check.C) {
c.Assert(err, check.IsNil)
c.Assert(read, check.DeepEquals, contents)
url, err = suite.StorageDriver.URLFor(suite.ctx, filename, map[string]interface{}{"method": "HEAD"})
url, err = suite.StorageDriver.URLFor(suite.ctx, filename, map[string]interface{}{"method": http.MethodHead})
if _, ok := err.(storagedriver.ErrUnsupportedMethod); ok {
return
}