mirror of
https://github.com/minio/minio.git
synced 2025-05-21 09:33:50 -04:00
URL Encode X-Amz-Copy-Source as per the spec (#2114)
The documents for COPY state that the X-Amz-Copy-Source must be URL encoded. http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html
This commit is contained in:
parent
a51bb1d728
commit
8c767218a4
@ -48,7 +48,7 @@ func registerAPIRouter(mux *router.Router, api objectAPIHandlers) {
|
|||||||
// GetObject
|
// GetObject
|
||||||
bucket.Methods("GET").Path("/{object:.+}").HandlerFunc(api.GetObjectHandler)
|
bucket.Methods("GET").Path("/{object:.+}").HandlerFunc(api.GetObjectHandler)
|
||||||
// CopyObject
|
// CopyObject
|
||||||
bucket.Methods("PUT").Path("/{object:.+}").HeadersRegexp("X-Amz-Copy-Source", ".*?(\\/).*?").HandlerFunc(api.CopyObjectHandler)
|
bucket.Methods("PUT").Path("/{object:.+}").HeadersRegexp("X-Amz-Copy-Source", ".*?(\\/|%2F).*?").HandlerFunc(api.CopyObjectHandler)
|
||||||
// PutObject
|
// PutObject
|
||||||
bucket.Methods("PUT").Path("/{object:.+}").HandlerFunc(api.PutObjectHandler)
|
bucket.Methods("PUT").Path("/{object:.+}").HandlerFunc(api.PutObjectHandler)
|
||||||
// DeleteObject
|
// DeleteObject
|
||||||
|
@ -337,11 +337,14 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Reject requests where body/payload is present, for now we
|
// TODO: Reject requests where body/payload is present, for now we don't even read it.
|
||||||
// don't even read it.
|
|
||||||
|
|
||||||
// objectSource
|
// objectSource
|
||||||
objectSource := r.Header.Get("X-Amz-Copy-Source")
|
objectSource, err := url.QueryUnescape(r.Header.Get("X-Amz-Copy-Source"))
|
||||||
|
if err != nil {
|
||||||
|
// Save unescaped string as is.
|
||||||
|
objectSource = r.Header.Get("X-Amz-Copy-Source")
|
||||||
|
}
|
||||||
|
|
||||||
// Skip the first element if it is '/', split the rest.
|
// Skip the first element if it is '/', split the rest.
|
||||||
if strings.HasPrefix(objectSource, "/") {
|
if strings.HasPrefix(objectSource, "/") {
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -689,7 +690,7 @@ func (s *TestSuiteCommon) TestCopyObject(c *C) {
|
|||||||
request, err = newTestRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName2),
|
request, err = newTestRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName2),
|
||||||
0, nil, s.accessKey, s.secretKey)
|
0, nil, s.accessKey, s.secretKey)
|
||||||
// setting the "X-Amz-Copy-Source" to allow copying the content of previously uploaded object.
|
// setting the "X-Amz-Copy-Source" to allow copying the content of previously uploaded object.
|
||||||
request.Header.Set("X-Amz-Copy-Source", "/"+bucketName+"/"+objectName)
|
request.Header.Set("X-Amz-Copy-Source", url.QueryEscape("/"+bucketName+"/"+objectName))
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
// execute the HTTP request.
|
// execute the HTTP request.
|
||||||
// the content is expected to have the content of previous disk.
|
// the content is expected to have the content of previous disk.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user