mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
refactoring
This commit is contained in:
parent
006b4ec0f8
commit
f17fa400d5
|
@ -362,7 +362,7 @@ func (iama *IamApiServer) DeleteAccessKey(s3cfg *iam_pb.S3ApiConfiguration, valu
|
||||||
|
|
||||||
func (iama *IamApiServer) DoActions(w http.ResponseWriter, r *http.Request) {
|
func (iama *IamApiServer) DoActions(w http.ResponseWriter, r *http.Request) {
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidRequest, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
values := r.PostForm
|
values := r.PostForm
|
||||||
|
@ -370,7 +370,7 @@ func (iama *IamApiServer) DoActions(w http.ResponseWriter, r *http.Request) {
|
||||||
s3cfgLock.RLock()
|
s3cfgLock.RLock()
|
||||||
s3cfg := &iam_pb.S3ApiConfiguration{}
|
s3cfg := &iam_pb.S3ApiConfiguration{}
|
||||||
if err := iama.s3ApiConfig.GetS3ApiConfiguration(s3cfg); err != nil {
|
if err := iama.s3ApiConfig.GetS3ApiConfiguration(s3cfg); err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s3cfgLock.RUnlock()
|
s3cfgLock.RUnlock()
|
||||||
|
@ -411,14 +411,14 @@ func (iama *IamApiServer) DoActions(w http.ResponseWriter, r *http.Request) {
|
||||||
response, err = iama.CreatePolicy(s3cfg, values)
|
response, err = iama.CreatePolicy(s3cfg, values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("CreatePolicy: %+v", err)
|
glog.Errorf("CreatePolicy: %+v", err)
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidRequest, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "PutUserPolicy":
|
case "PutUserPolicy":
|
||||||
response, err = iama.PutUserPolicy(s3cfg, values)
|
response, err = iama.PutUserPolicy(s3cfg, values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("PutUserPolicy: %+v", err)
|
glog.Errorf("PutUserPolicy: %+v", err)
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidRequest, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "GetUserPolicy":
|
case "GetUserPolicy":
|
||||||
|
|
|
@ -182,7 +182,7 @@ func (iam *IdentityAccessManagement) Auth(f http.HandlerFunc, action Action) htt
|
||||||
f(w, r)
|
f(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s3err.WriteErrorResponse(w, errCode, r)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ func (s3a *S3ApiServer) ListBucketsHandler(w http.ResponseWriter, r *http.Reques
|
||||||
if s3a.iam.isEnabled() {
|
if s3a.iam.isEnabled() {
|
||||||
identity, s3Err = s3a.iam.authUser(r)
|
identity, s3Err = s3a.iam.authUser(r)
|
||||||
if s3Err != s3err.ErrNone {
|
if s3Err != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, s3Err, r)
|
s3err.WriteErrorResponse(w, r, s3Err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ func (s3a *S3ApiServer) ListBucketsHandler(w http.ResponseWriter, r *http.Reques
|
||||||
entries, _, err := s3a.list(s3a.option.BucketsPath, "", "", false, math.MaxInt32)
|
entries, _, err := s3a.list(s3a.option.BucketsPath, "", "", false, math.MaxInt32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,14 +100,14 @@ func (s3a *S3ApiServer) PutBucketHandler(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if exist, err := s3a.exists(s3a.option.BucketsPath, bucket, true); err == nil && exist {
|
if exist, err := s3a.exists(s3a.option.BucketsPath, bucket, true); err == nil && exist {
|
||||||
errCode = s3err.ErrBucketAlreadyExists
|
errCode = s3err.ErrBucketAlreadyExists
|
||||||
}
|
}
|
||||||
if errCode != s3err.ErrNone {
|
if errCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, errCode, r)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ func (s3a *S3ApiServer) PutBucketHandler(w http.ResponseWriter, r *http.Request)
|
||||||
// create the folder for bucket, but lazily create actual collection
|
// create the folder for bucket, but lazily create actual collection
|
||||||
if err := s3a.mkdir(s3a.option.BucketsPath, bucket, fn); err != nil {
|
if err := s3a.mkdir(s3a.option.BucketsPath, bucket, fn); err != nil {
|
||||||
glog.Errorf("PutBucketHandler mkdir: %v", err)
|
glog.Errorf("PutBucketHandler mkdir: %v", err)
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ func (s3a *S3ApiServer) DeleteBucketHandler(w http.ResponseWriter, r *http.Reque
|
||||||
glog.V(3).Infof("DeleteBucketHandler %s", bucket)
|
glog.V(3).Infof("DeleteBucketHandler %s", bucket)
|
||||||
|
|
||||||
if err := s3a.checkBucket(r, bucket); err != s3err.ErrNone {
|
if err := s3a.checkBucket(r, bucket); err != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, err, r)
|
s3err.WriteErrorResponse(w, r, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ func (s3a *S3ApiServer) DeleteBucketHandler(w http.ResponseWriter, r *http.Reque
|
||||||
err = s3a.rm(s3a.option.BucketsPath, bucket, false, true)
|
err = s3a.rm(s3a.option.BucketsPath, bucket, false, true)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ func (s3a *S3ApiServer) HeadBucketHandler(w http.ResponseWriter, r *http.Request
|
||||||
glog.V(3).Infof("HeadBucketHandler %s", bucket)
|
glog.V(3).Infof("HeadBucketHandler %s", bucket)
|
||||||
|
|
||||||
if err := s3a.checkBucket(r, bucket); err != s3err.ErrNone {
|
if err := s3a.checkBucket(r, bucket); err != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, err, r)
|
s3err.WriteErrorResponse(w, r, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ func (s3a *S3ApiServer) GetBucketAclHandler(w http.ResponseWriter, r *http.Reque
|
||||||
glog.V(3).Infof("GetBucketAclHandler %s", bucket)
|
glog.V(3).Infof("GetBucketAclHandler %s", bucket)
|
||||||
|
|
||||||
if err := s3a.checkBucket(r, bucket); err != s3err.ErrNone {
|
if err := s3a.checkBucket(r, bucket); err != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, err, r)
|
s3err.WriteErrorResponse(w, r, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,18 +256,18 @@ func (s3a *S3ApiServer) GetBucketLifecycleConfigurationHandler(w http.ResponseWr
|
||||||
glog.V(3).Infof("GetBucketAclHandler %s", bucket)
|
glog.V(3).Infof("GetBucketAclHandler %s", bucket)
|
||||||
|
|
||||||
if err := s3a.checkBucket(r, bucket); err != s3err.ErrNone {
|
if err := s3a.checkBucket(r, bucket); err != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, err, r)
|
s3err.WriteErrorResponse(w, r, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fc, err := filer.ReadFilerConf(s3a.option.Filer, s3a.option.GrpcDialOption, nil)
|
fc, err := filer.ReadFilerConf(s3a.option.Filer, s3a.option.GrpcDialOption, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("GetBucketLifecycleConfigurationHandler: %s", err)
|
glog.Errorf("GetBucketLifecycleConfigurationHandler: %s", err)
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ttls := fc.GetCollectionTtls(bucket)
|
ttls := fc.GetCollectionTtls(bucket)
|
||||||
if len(ttls) == 0 {
|
if len(ttls) == 0 {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrNoSuchLifecycleConfiguration, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchLifecycleConfiguration)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
response := Lifecycle{}
|
response := Lifecycle{}
|
||||||
|
@ -292,7 +292,7 @@ func (s3a *S3ApiServer) GetBucketLifecycleConfigurationHandler(w http.ResponseWr
|
||||||
// https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketLifecycleConfiguration.html
|
// https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketLifecycleConfiguration.html
|
||||||
func (s3a *S3ApiServer) PutBucketLifecycleConfigurationHandler(w http.ResponseWriter, r *http.Request) {
|
func (s3a *S3ApiServer) PutBucketLifecycleConfigurationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrNotImplemented, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrNotImplemented)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,13 +34,13 @@ func (s3a *S3ApiServer) CopyObjectHandler(w http.ResponseWriter, r *http.Request
|
||||||
dir, name := fullPath.DirAndName()
|
dir, name := fullPath.DirAndName()
|
||||||
entry, err := s3a.getEntry(dir, name)
|
entry, err := s3a.getEntry(dir, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopySource)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
entry.Extended = weed_server.SaveAmzMetaData(r, entry.Extended, isReplace(r))
|
entry.Extended = weed_server.SaveAmzMetaData(r, entry.Extended, isReplace(r))
|
||||||
err = s3a.touch(dir, name, entry)
|
err = s3a.touch(dir, name, entry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopySource)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeSuccessResponseXML(w, r, CopyObjectResult{
|
writeSuccessResponseXML(w, r, CopyObjectResult{
|
||||||
|
@ -52,19 +52,19 @@ func (s3a *S3ApiServer) CopyObjectHandler(w http.ResponseWriter, r *http.Request
|
||||||
|
|
||||||
// If source object is empty or bucket is empty, reply back invalid copy source.
|
// If source object is empty or bucket is empty, reply back invalid copy source.
|
||||||
if srcObject == "" || srcBucket == "" {
|
if srcObject == "" || srcBucket == "" {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopySource)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
srcPath := util.FullPath(fmt.Sprintf("%s/%s%s", s3a.option.BucketsPath, srcBucket, srcObject))
|
srcPath := util.FullPath(fmt.Sprintf("%s/%s%s", s3a.option.BucketsPath, srcBucket, srcObject))
|
||||||
dir, name := srcPath.DirAndName()
|
dir, name := srcPath.DirAndName()
|
||||||
_, err = s3a.getEntry(dir, name)
|
_, err = s3a.getEntry(dir, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopySource)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if srcBucket == dstBucket && srcObject == dstObject {
|
if srcBucket == dstBucket && srcObject == dstObject {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidCopyDest, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopyDest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ func (s3a *S3ApiServer) CopyObjectHandler(w http.ResponseWriter, r *http.Request
|
||||||
|
|
||||||
_, _, resp, err := util.DownloadFile(srcUrl, "")
|
_, _, resp, err := util.DownloadFile(srcUrl, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopySource)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer util.CloseResponse(resp)
|
defer util.CloseResponse(resp)
|
||||||
|
@ -84,7 +84,7 @@ func (s3a *S3ApiServer) CopyObjectHandler(w http.ResponseWriter, r *http.Request
|
||||||
etag, errCode := s3a.putToFiler(r, dstUrl, resp.Body)
|
etag, errCode := s3a.putToFiler(r, dstUrl, resp.Body)
|
||||||
|
|
||||||
if errCode != s3err.ErrNone {
|
if errCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, errCode, r)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Req
|
||||||
srcBucket, srcObject := pathToBucketAndObject(cpSrcPath)
|
srcBucket, srcObject := pathToBucketAndObject(cpSrcPath)
|
||||||
// If source object is empty or bucket is empty, reply back invalid copy source.
|
// If source object is empty or bucket is empty, reply back invalid copy source.
|
||||||
if srcObject == "" || srcBucket == "" {
|
if srcObject == "" || srcBucket == "" {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopySource)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Req
|
||||||
|
|
||||||
partID, err := strconv.Atoi(partIDString)
|
partID, err := strconv.Atoi(partIDString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidPart, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidPart)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Req
|
||||||
|
|
||||||
// check partID with maximum part ID for multipart objects
|
// check partID with maximum part ID for multipart objects
|
||||||
if partID > globalMaxPartID {
|
if partID > globalMaxPartID {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidMaxParts, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidMaxParts)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Req
|
||||||
|
|
||||||
dataReader, err := util.ReadUrlAsReaderCloser(srcUrl, rangeHeader)
|
dataReader, err := util.ReadUrlAsReaderCloser(srcUrl, rangeHeader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopySource)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer dataReader.Close()
|
defer dataReader.Close()
|
||||||
|
@ -167,7 +167,7 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Req
|
||||||
etag, errCode := s3a.putToFiler(r, dstUrl, dataReader)
|
etag, errCode := s3a.putToFiler(r, dstUrl, dataReader)
|
||||||
|
|
||||||
if errCode != s3err.ErrNone {
|
if errCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, errCode, r)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,20 +56,20 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
|
||||||
|
|
||||||
_, err := validateContentMd5(r.Header)
|
_, err := validateContentMd5(r.Header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidDigest, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidDigest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Header.Get("Cache-Control") != "" {
|
if r.Header.Get("Cache-Control") != "" {
|
||||||
if _, err = cacheobject.ParseRequestCacheControl(r.Header.Get("Cache-Control")); err != nil {
|
if _, err = cacheobject.ParseRequestCacheControl(r.Header.Get("Cache-Control")); err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidDigest, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidDigest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Header.Get("Expires") != "" {
|
if r.Header.Get("Expires") != "" {
|
||||||
if _, err = time.Parse(http.TimeFormat, r.Header.Get("Expires")); err != nil {
|
if _, err = time.Parse(http.TimeFormat, r.Header.Get("Expires")); err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidDigest, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidDigest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,12 +87,12 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
|
||||||
_, s3ErrCode = s3a.iam.reqSignatureV4Verify(r)
|
_, s3ErrCode = s3a.iam.reqSignatureV4Verify(r)
|
||||||
}
|
}
|
||||||
if s3ErrCode != s3err.ErrNone {
|
if s3ErrCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, s3ErrCode, r)
|
s3err.WriteErrorResponse(w, r, s3ErrCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if authTypeStreamingSigned == rAuthType {
|
if authTypeStreamingSigned == rAuthType {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrAuthNotSetup, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrAuthNotSetup)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
|
||||||
|
|
||||||
if strings.HasSuffix(object, "/") {
|
if strings.HasSuffix(object, "/") {
|
||||||
if err := s3a.mkdir(s3a.option.BucketsPath, bucket+object, nil); err != nil {
|
if err := s3a.mkdir(s3a.option.BucketsPath, bucket+object, nil); err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -113,7 +113,7 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
|
||||||
etag, errCode := s3a.putToFiler(r, uploadUrl, dataReader)
|
etag, errCode := s3a.putToFiler(r, uploadUrl, dataReader)
|
||||||
|
|
||||||
if errCode != s3err.ErrNone {
|
if errCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, errCode, r)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ func (s3a *S3ApiServer) GetObjectHandler(w http.ResponseWriter, r *http.Request)
|
||||||
glog.V(3).Infof("GetObjectHandler %s %s", bucket, object)
|
glog.V(3).Infof("GetObjectHandler %s %s", bucket, object)
|
||||||
|
|
||||||
if strings.HasSuffix(r.URL.Path, "/") {
|
if strings.HasSuffix(r.URL.Path, "/") {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrNotImplemented, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrNotImplemented)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,13 +215,13 @@ func (s3a *S3ApiServer) DeleteMultipleObjectsHandler(w http.ResponseWriter, r *h
|
||||||
|
|
||||||
deleteXMLBytes, err := io.ReadAll(r.Body)
|
deleteXMLBytes, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteObjects := &DeleteObjectsRequest{}
|
deleteObjects := &DeleteObjectsRequest{}
|
||||||
if err := xml.Unmarshal(deleteXMLBytes, deleteObjects); err != nil {
|
if err := xml.Unmarshal(deleteXMLBytes, deleteObjects); err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrMalformedXML, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrMalformedXML)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, des
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("NewRequest %s: %v", destUrl, err)
|
glog.Errorf("NewRequest %s: %v", destUrl, err)
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,19 +346,19 @@ func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, des
|
||||||
|
|
||||||
if postErr != nil {
|
if postErr != nil {
|
||||||
glog.Errorf("post to filer: %v", postErr)
|
glog.Errorf("post to filer: %v", postErr)
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer util.CloseResponse(resp)
|
defer util.CloseResponse(resp)
|
||||||
|
|
||||||
if resp.StatusCode == http.StatusPreconditionFailed {
|
if resp.StatusCode == http.StatusPreconditionFailed {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrPreconditionFailed, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrPreconditionFailed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.ContentLength == -1 || resp.StatusCode == 404) && resp.StatusCode != 304 {
|
if (resp.ContentLength == -1 || resp.StatusCode == 404) && resp.StatusCode != 304 {
|
||||||
if r.Method != "DELETE" {
|
if r.Method != "DELETE" {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrNoSuchKey, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchKey)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,23 +29,23 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
|
||||||
|
|
||||||
reader, err := r.MultipartReader()
|
reader, err := r.MultipartReader()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrMalformedPOSTRequest, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrMalformedPOSTRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
form, err := reader.ReadForm(int64(5 * humanize.MiByte))
|
form, err := reader.ReadForm(int64(5 * humanize.MiByte))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrMalformedPOSTRequest, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrMalformedPOSTRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer form.RemoveAll()
|
defer form.RemoveAll()
|
||||||
|
|
||||||
fileBody, fileName, fileSize, formValues, err := extractPostPolicyFormValues(form)
|
fileBody, fileName, fileSize, formValues, err := extractPostPolicyFormValues(form)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrMalformedPOSTRequest, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrMalformedPOSTRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if fileBody == nil {
|
if fileBody == nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrPOSTFileRequired, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrPOSTFileRequired)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer fileBody.Close()
|
defer fileBody.Close()
|
||||||
|
@ -63,7 +63,7 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
|
||||||
if successRedirect != "" {
|
if successRedirect != "" {
|
||||||
redirectURL, err = url.Parse(successRedirect)
|
redirectURL, err = url.Parse(successRedirect)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrMalformedPOSTRequest, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrMalformedPOSTRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,13 +71,13 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
|
||||||
// Verify policy signature.
|
// Verify policy signature.
|
||||||
errCode := s3a.iam.doesPolicySignatureMatch(formValues)
|
errCode := s3a.iam.doesPolicySignatureMatch(formValues)
|
||||||
if errCode != s3err.ErrNone {
|
if errCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, errCode, r)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
policyBytes, err := base64.StdEncoding.DecodeString(formValues.Get("Policy"))
|
policyBytes, err := base64.StdEncoding.DecodeString(formValues.Get("Policy"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrMalformedPOSTRequest, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrMalformedPOSTRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
|
||||||
|
|
||||||
postPolicyForm, err := policy.ParsePostPolicyForm(string(policyBytes))
|
postPolicyForm, err := policy.ParsePostPolicyForm(string(policyBytes))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrPostPolicyConditionInvalidFormat, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrPostPolicyConditionInvalidFormat)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,12 +102,12 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
|
||||||
lengthRange := postPolicyForm.Conditions.ContentLengthRange
|
lengthRange := postPolicyForm.Conditions.ContentLengthRange
|
||||||
if lengthRange.Valid {
|
if lengthRange.Valid {
|
||||||
if fileSize < lengthRange.Min {
|
if fileSize < lengthRange.Min {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrEntityTooSmall, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrEntityTooSmall)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if fileSize > lengthRange.Max {
|
if fileSize > lengthRange.Max {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrEntityTooLarge, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrEntityTooLarge)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
|
||||||
etag, errCode := s3a.putToFiler(r, uploadUrl, fileBody)
|
etag, errCode := s3a.putToFiler(r, uploadUrl, fileBody)
|
||||||
|
|
||||||
if errCode != s3err.ErrNone {
|
if errCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, errCode, r)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ func (s3a *S3ApiServer) NewMultipartUploadHandler(w http.ResponseWriter, r *http
|
||||||
glog.V(2).Info("NewMultipartUploadHandler", string(s3err.EncodeXMLResponse(response)), errCode)
|
glog.V(2).Info("NewMultipartUploadHandler", string(s3err.EncodeXMLResponse(response)), errCode)
|
||||||
|
|
||||||
if errCode != s3err.ErrNone {
|
if errCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, errCode, r)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ func (s3a *S3ApiServer) CompleteMultipartUploadHandler(w http.ResponseWriter, r
|
||||||
glog.V(2).Info("CompleteMultipartUploadHandler", string(s3err.EncodeXMLResponse(response)), errCode)
|
glog.V(2).Info("CompleteMultipartUploadHandler", string(s3err.EncodeXMLResponse(response)), errCode)
|
||||||
|
|
||||||
if errCode != s3err.ErrNone {
|
if errCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, errCode, r)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ func (s3a *S3ApiServer) AbortMultipartUploadHandler(w http.ResponseWriter, r *ht
|
||||||
})
|
})
|
||||||
|
|
||||||
if errCode != s3err.ErrNone {
|
if errCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, errCode, r)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,13 +107,13 @@ func (s3a *S3ApiServer) ListMultipartUploadsHandler(w http.ResponseWriter, r *ht
|
||||||
|
|
||||||
prefix, keyMarker, uploadIDMarker, delimiter, maxUploads, encodingType := getBucketMultipartResources(r.URL.Query())
|
prefix, keyMarker, uploadIDMarker, delimiter, maxUploads, encodingType := getBucketMultipartResources(r.URL.Query())
|
||||||
if maxUploads < 0 {
|
if maxUploads < 0 {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidMaxUploads, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidMaxUploads)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if keyMarker != "" {
|
if keyMarker != "" {
|
||||||
// Marker not common with prefix is not implemented.
|
// Marker not common with prefix is not implemented.
|
||||||
if !strings.HasPrefix(keyMarker, prefix) {
|
if !strings.HasPrefix(keyMarker, prefix) {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrNotImplemented, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrNotImplemented)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ func (s3a *S3ApiServer) ListMultipartUploadsHandler(w http.ResponseWriter, r *ht
|
||||||
glog.V(2).Infof("ListMultipartUploadsHandler %s errCode=%d", string(s3err.EncodeXMLResponse(response)), errCode)
|
glog.V(2).Infof("ListMultipartUploadsHandler %s errCode=%d", string(s3err.EncodeXMLResponse(response)), errCode)
|
||||||
|
|
||||||
if errCode != s3err.ErrNone {
|
if errCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, errCode, r)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,11 +146,11 @@ func (s3a *S3ApiServer) ListObjectPartsHandler(w http.ResponseWriter, r *http.Re
|
||||||
|
|
||||||
uploadID, partNumberMarker, maxParts, _ := getObjectResources(r.URL.Query())
|
uploadID, partNumberMarker, maxParts, _ := getObjectResources(r.URL.Query())
|
||||||
if partNumberMarker < 0 {
|
if partNumberMarker < 0 {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidPartNumberMarker, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidPartNumberMarker)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if maxParts < 0 {
|
if maxParts < 0 {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidMaxParts, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidMaxParts)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ func (s3a *S3ApiServer) ListObjectPartsHandler(w http.ResponseWriter, r *http.Re
|
||||||
glog.V(2).Infof("ListObjectPartsHandler %s count=%d", string(s3err.EncodeXMLResponse(response)), len(response.Part))
|
glog.V(2).Infof("ListObjectPartsHandler %s count=%d", string(s3err.EncodeXMLResponse(response)), len(response.Part))
|
||||||
|
|
||||||
if errCode != s3err.ErrNone {
|
if errCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, errCode, r)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,18 +180,18 @@ func (s3a *S3ApiServer) PutObjectPartHandler(w http.ResponseWriter, r *http.Requ
|
||||||
uploadID := r.URL.Query().Get("uploadId")
|
uploadID := r.URL.Query().Get("uploadId")
|
||||||
exists, err := s3a.exists(s3a.genUploadsFolder(bucket), uploadID, true)
|
exists, err := s3a.exists(s3a.genUploadsFolder(bucket), uploadID, true)
|
||||||
if !exists {
|
if !exists {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrNoSuchUpload, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchUpload)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
partIDString := r.URL.Query().Get("partNumber")
|
partIDString := r.URL.Query().Get("partNumber")
|
||||||
partID, err := strconv.Atoi(partIDString)
|
partID, err := strconv.Atoi(partIDString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidPart, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidPart)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if partID > globalMaxPartID {
|
if partID > globalMaxPartID {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidMaxParts, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidMaxParts)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ func (s3a *S3ApiServer) PutObjectPartHandler(w http.ResponseWriter, r *http.Requ
|
||||||
_, s3ErrCode = s3a.iam.reqSignatureV4Verify(r)
|
_, s3ErrCode = s3a.iam.reqSignatureV4Verify(r)
|
||||||
}
|
}
|
||||||
if s3ErrCode != s3err.ErrNone {
|
if s3ErrCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, s3ErrCode, r)
|
s3err.WriteErrorResponse(w, r, s3ErrCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -225,7 +225,7 @@ func (s3a *S3ApiServer) PutObjectPartHandler(w http.ResponseWriter, r *http.Requ
|
||||||
|
|
||||||
etag, errCode := s3a.putToFiler(r, uploadUrl, dataReader)
|
etag, errCode := s3a.putToFiler(r, uploadUrl, dataReader)
|
||||||
if errCode != s3err.ErrNone {
|
if errCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, errCode, r)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,10 @@ func (s3a *S3ApiServer) GetObjectTaggingHandler(w http.ResponseWriter, r *http.R
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == filer_pb.ErrNotFound {
|
if err == filer_pb.ErrNotFound {
|
||||||
glog.Errorf("GetObjectTaggingHandler %s: %v", r.URL, err)
|
glog.Errorf("GetObjectTaggingHandler %s: %v", r.URL, err)
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrNoSuchKey, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchKey)
|
||||||
} else {
|
} else {
|
||||||
glog.Errorf("GetObjectTaggingHandler %s: %v", r.URL, err)
|
glog.Errorf("GetObjectTaggingHandler %s: %v", r.URL, err)
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -52,29 +52,29 @@ func (s3a *S3ApiServer) PutObjectTaggingHandler(w http.ResponseWriter, r *http.R
|
||||||
input, err := io.ReadAll(io.LimitReader(r.Body, r.ContentLength))
|
input, err := io.ReadAll(io.LimitReader(r.Body, r.ContentLength))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("PutObjectTaggingHandler read input %s: %v", r.URL, err)
|
glog.Errorf("PutObjectTaggingHandler read input %s: %v", r.URL, err)
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = xml.Unmarshal(input, tagging); err != nil {
|
if err = xml.Unmarshal(input, tagging); err != nil {
|
||||||
glog.Errorf("PutObjectTaggingHandler Unmarshal %s: %v", r.URL, err)
|
glog.Errorf("PutObjectTaggingHandler Unmarshal %s: %v", r.URL, err)
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrMalformedXML, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrMalformedXML)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tags := tagging.ToTags()
|
tags := tagging.ToTags()
|
||||||
if len(tags) > 10 {
|
if len(tags) > 10 {
|
||||||
glog.Errorf("PutObjectTaggingHandler tags %s: %d tags more than 10", r.URL, len(tags))
|
glog.Errorf("PutObjectTaggingHandler tags %s: %d tags more than 10", r.URL, len(tags))
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidTag, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidTag)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for k, v := range tags {
|
for k, v := range tags {
|
||||||
if len(k) > 128 {
|
if len(k) > 128 {
|
||||||
glog.Errorf("PutObjectTaggingHandler tags %s: tag key %s longer than 128", r.URL, k)
|
glog.Errorf("PutObjectTaggingHandler tags %s: tag key %s longer than 128", r.URL, k)
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidTag, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidTag)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(v) > 256 {
|
if len(v) > 256 {
|
||||||
glog.Errorf("PutObjectTaggingHandler tags %s: tag value %s longer than 256", r.URL, v)
|
glog.Errorf("PutObjectTaggingHandler tags %s: tag value %s longer than 256", r.URL, v)
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidTag, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidTag)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,10 +82,10 @@ func (s3a *S3ApiServer) PutObjectTaggingHandler(w http.ResponseWriter, r *http.R
|
||||||
if err = s3a.setTags(dir, name, tagging.ToTags()); err != nil {
|
if err = s3a.setTags(dir, name, tagging.ToTags()); err != nil {
|
||||||
if err == filer_pb.ErrNotFound {
|
if err == filer_pb.ErrNotFound {
|
||||||
glog.Errorf("PutObjectTaggingHandler setTags %s: %v", r.URL, err)
|
glog.Errorf("PutObjectTaggingHandler setTags %s: %v", r.URL, err)
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrNoSuchKey, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchKey)
|
||||||
} else {
|
} else {
|
||||||
glog.Errorf("PutObjectTaggingHandler setTags %s: %v", r.URL, err)
|
glog.Errorf("PutObjectTaggingHandler setTags %s: %v", r.URL, err)
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -108,10 +108,10 @@ func (s3a *S3ApiServer) DeleteObjectTaggingHandler(w http.ResponseWriter, r *htt
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == filer_pb.ErrNotFound {
|
if err == filer_pb.ErrNotFound {
|
||||||
glog.Errorf("DeleteObjectTaggingHandler %s: %v", r.URL, err)
|
glog.Errorf("DeleteObjectTaggingHandler %s: %v", r.URL, err)
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrNoSuchKey, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchKey)
|
||||||
} else {
|
} else {
|
||||||
glog.Errorf("DeleteObjectTaggingHandler %s: %v", r.URL, err)
|
glog.Errorf("DeleteObjectTaggingHandler %s: %v", r.URL, err)
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,11 +45,11 @@ func (s3a *S3ApiServer) ListObjectsV2Handler(w http.ResponseWriter, r *http.Requ
|
||||||
originalPrefix, continuationToken, startAfter, delimiter, _, maxKeys := getListObjectsV2Args(r.URL.Query())
|
originalPrefix, continuationToken, startAfter, delimiter, _, maxKeys := getListObjectsV2Args(r.URL.Query())
|
||||||
|
|
||||||
if maxKeys < 0 {
|
if maxKeys < 0 {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidMaxKeys, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidMaxKeys)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if delimiter != "" && delimiter != "/" {
|
if delimiter != "" && delimiter != "/" {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrNotImplemented, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrNotImplemented)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,13 +61,13 @@ func (s3a *S3ApiServer) ListObjectsV2Handler(w http.ResponseWriter, r *http.Requ
|
||||||
response, err := s3a.listFilerEntries(bucket, originalPrefix, maxKeys, marker, delimiter)
|
response, err := s3a.listFilerEntries(bucket, originalPrefix, maxKeys, marker, delimiter)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(response.Contents) == 0 {
|
if len(response.Contents) == 0 {
|
||||||
if exists, existErr := s3a.exists(s3a.option.BucketsPath, bucket, true); existErr == nil && !exists {
|
if exists, existErr := s3a.exists(s3a.option.BucketsPath, bucket, true); existErr == nil && !exists {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrNoSuchBucket, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchBucket)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,24 +101,24 @@ func (s3a *S3ApiServer) ListObjectsV1Handler(w http.ResponseWriter, r *http.Requ
|
||||||
originalPrefix, marker, delimiter, maxKeys := getListObjectsV1Args(r.URL.Query())
|
originalPrefix, marker, delimiter, maxKeys := getListObjectsV1Args(r.URL.Query())
|
||||||
|
|
||||||
if maxKeys < 0 {
|
if maxKeys < 0 {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInvalidMaxKeys, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidMaxKeys)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if delimiter != "" && delimiter != "/" {
|
if delimiter != "" && delimiter != "/" {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrNotImplemented, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrNotImplemented)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := s3a.listFilerEntries(bucket, originalPrefix, maxKeys, marker, delimiter)
|
response, err := s3a.listFilerEntries(bucket, originalPrefix, maxKeys, marker, delimiter)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(response.Contents) == 0 {
|
if len(response.Contents) == 0 {
|
||||||
if exists, existErr := s3a.exists(s3a.option.BucketsPath, bucket, true); existErr == nil && !exists {
|
if exists, existErr := s3a.exists(s3a.option.BucketsPath, bucket, true); existErr == nil && !exists {
|
||||||
s3err.WriteErrorResponse(w, s3err.ErrNoSuchBucket, r)
|
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchBucket)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ func WriteEmptyResponse(w http.ResponseWriter, r *http.Request, statusCode int)
|
||||||
WriteResponse(w, r, statusCode, []byte{}, mimeNone)
|
WriteResponse(w, r, statusCode, []byte{}, mimeNone)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteErrorResponse(w http.ResponseWriter, errorCode ErrorCode, r *http.Request) {
|
func WriteErrorResponse(w http.ResponseWriter, r *http.Request, errorCode ErrorCode) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
bucket := vars["bucket"]
|
bucket := vars["bucket"]
|
||||||
object := vars["object"]
|
object := vars["object"]
|
||||||
|
@ -88,5 +88,5 @@ func WriteResponse(w http.ResponseWriter, r *http.Request, statusCode int, respo
|
||||||
// If none of the http routes match respond with MethodNotAllowed
|
// If none of the http routes match respond with MethodNotAllowed
|
||||||
func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
|
func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
glog.V(0).Infof("unsupported %s %s", r.Method, r.RequestURI)
|
glog.V(0).Infof("unsupported %s %s", r.Method, r.RequestURI)
|
||||||
WriteErrorResponse(w, ErrMethodNotAllowed, r)
|
WriteErrorResponse(w, r, ErrMethodNotAllowed)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue