mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
refactoring
This commit is contained in:
parent
40a8cb9b0a
commit
33b87244ef
|
@ -7,7 +7,6 @@ import (
|
|||
"strconv"
|
||||
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
|
@ -40,12 +39,12 @@ func encodeResponse(response interface{}) []byte {
|
|||
// If none of the http routes match respond with MethodNotAllowed
|
||||
func notFoundHandler(w http.ResponseWriter, r *http.Request) {
|
||||
glog.V(0).Infof("unsupported %s %s", r.Method, r.RequestURI)
|
||||
writeErrorResponse(w, s3err.ErrMethodNotAllowed, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrMethodNotAllowed, r)
|
||||
}
|
||||
|
||||
func writeErrorResponse(w http.ResponseWriter, errorCode s3err.ErrorCode, reqURL *url.URL) {
|
||||
func writeErrorResponse(w http.ResponseWriter, errorCode s3err.ErrorCode, r *http.Request) {
|
||||
apiError := s3err.GetAPIError(errorCode)
|
||||
errorResponse := getRESTErrorResponse(apiError, reqURL.Path)
|
||||
errorResponse := getRESTErrorResponse(apiError, r.URL.Path)
|
||||
encodedErrorResponse := encodeResponse(errorResponse)
|
||||
writeResponse(w, apiError.HTTPStatusCode, encodedErrorResponse, mimeXML)
|
||||
}
|
||||
|
|
|
@ -362,7 +362,7 @@ func (iama *IamApiServer) DeleteAccessKey(s3cfg *iam_pb.S3ApiConfiguration, valu
|
|||
|
||||
func (iama *IamApiServer) DoActions(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInvalidRequest, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidRequest, r)
|
||||
return
|
||||
}
|
||||
values := r.PostForm
|
||||
|
@ -370,7 +370,7 @@ func (iama *IamApiServer) DoActions(w http.ResponseWriter, r *http.Request) {
|
|||
s3cfgLock.RLock()
|
||||
s3cfg := &iam_pb.S3ApiConfiguration{}
|
||||
if err := iama.s3ApiConfig.GetS3ApiConfiguration(s3cfg); err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r)
|
||||
return
|
||||
}
|
||||
s3cfgLock.RUnlock()
|
||||
|
@ -411,14 +411,14 @@ func (iama *IamApiServer) DoActions(w http.ResponseWriter, r *http.Request) {
|
|||
response, err = iama.CreatePolicy(s3cfg, values)
|
||||
if err != nil {
|
||||
glog.Errorf("CreatePolicy: %+v", err)
|
||||
writeErrorResponse(w, s3err.ErrInvalidRequest, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidRequest, r)
|
||||
return
|
||||
}
|
||||
case "PutUserPolicy":
|
||||
response, err = iama.PutUserPolicy(s3cfg, values)
|
||||
if err != nil {
|
||||
glog.Errorf("PutUserPolicy: %+v", err)
|
||||
writeErrorResponse(w, s3err.ErrInvalidRequest, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidRequest, r)
|
||||
return
|
||||
}
|
||||
case "GetUserPolicy":
|
||||
|
|
|
@ -150,7 +150,7 @@ func (iam *IdentityAccessManagement) Auth(f http.HandlerFunc, action Action) htt
|
|||
f(w, r)
|
||||
return
|
||||
}
|
||||
writeErrorResponse(w, errCode, r.URL)
|
||||
writeErrorResponse(w, errCode, r)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ func (s3a *S3ApiServer) ListBucketsHandler(w http.ResponseWriter, r *http.Reques
|
|||
if s3a.iam.isEnabled() {
|
||||
identity, s3Err = s3a.iam.authUser(r)
|
||||
if s3Err != s3err.ErrNone {
|
||||
writeErrorResponse(w, s3Err, r.URL)
|
||||
writeErrorResponse(w, s3Err, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ func (s3a *S3ApiServer) ListBucketsHandler(w http.ResponseWriter, r *http.Reques
|
|||
entries, _, err := s3a.list(s3a.option.BucketsPath, "", "", false, math.MaxInt32)
|
||||
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -95,14 +95,14 @@ func (s3a *S3ApiServer) PutBucketHandler(w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r)
|
||||
return
|
||||
}
|
||||
if exist, err := s3a.exists(s3a.option.BucketsPath, bucket, true); err == nil && exist {
|
||||
errCode = s3err.ErrBucketAlreadyExists
|
||||
}
|
||||
if errCode != s3err.ErrNone {
|
||||
writeErrorResponse(w, errCode, r.URL)
|
||||
writeErrorResponse(w, errCode, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ func (s3a *S3ApiServer) PutBucketHandler(w http.ResponseWriter, r *http.Request)
|
|||
// create the folder for bucket, but lazily create actual collection
|
||||
if err := s3a.mkdir(s3a.option.BucketsPath, bucket, fn); err != nil {
|
||||
glog.Errorf("PutBucketHandler mkdir: %v", err)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ func (s3a *S3ApiServer) DeleteBucketHandler(w http.ResponseWriter, r *http.Reque
|
|||
bucket, _ := getBucketAndObject(r)
|
||||
|
||||
if err := s3a.checkBucket(r, bucket); err != s3err.ErrNone {
|
||||
writeErrorResponse(w, err, r.URL)
|
||||
writeErrorResponse(w, err, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ func (s3a *S3ApiServer) DeleteBucketHandler(w http.ResponseWriter, r *http.Reque
|
|||
err = s3a.rm(s3a.option.BucketsPath, bucket, false, true)
|
||||
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ func (s3a *S3ApiServer) HeadBucketHandler(w http.ResponseWriter, r *http.Request
|
|||
bucket, _ := getBucketAndObject(r)
|
||||
|
||||
if err := s3a.checkBucket(r, bucket); err != s3err.ErrNone {
|
||||
writeErrorResponse(w, err, r.URL)
|
||||
writeErrorResponse(w, err, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"fmt"
|
||||
"github.com/chrislusf/seaweedfs/weed/s3api/s3err"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -57,12 +56,12 @@ func (s3a *S3ApiServer) AdjustedUrl(location *filer_pb.Location) string {
|
|||
// If none of the http routes match respond with MethodNotAllowed
|
||||
func notFoundHandler(w http.ResponseWriter, r *http.Request) {
|
||||
glog.V(0).Infof("unsupported %s %s", r.Method, r.RequestURI)
|
||||
writeErrorResponse(w, s3err.ErrMethodNotAllowed, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrMethodNotAllowed, r)
|
||||
}
|
||||
|
||||
func writeErrorResponse(w http.ResponseWriter, errorCode s3err.ErrorCode, reqURL *url.URL) {
|
||||
func writeErrorResponse(w http.ResponseWriter, errorCode s3err.ErrorCode, r *http.Request) {
|
||||
apiError := s3err.GetAPIError(errorCode)
|
||||
errorResponse := getRESTErrorResponse(apiError, reqURL.Path)
|
||||
errorResponse := getRESTErrorResponse(apiError, r.URL.Path)
|
||||
encodedErrorResponse := encodeResponse(errorResponse)
|
||||
writeResponse(w, apiError.HTTPStatusCode, encodedErrorResponse, mimeXML)
|
||||
}
|
||||
|
|
|
@ -32,12 +32,12 @@ func (s3a *S3ApiServer) CopyObjectHandler(w http.ResponseWriter, r *http.Request
|
|||
dir, name := fullPath.DirAndName()
|
||||
entry, err := s3a.getEntry(dir, name)
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInvalidCopySource, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidCopySource, r)
|
||||
}
|
||||
entry.Extended = weed_server.SaveAmzMetaData(r, entry.Extended, isReplace(r))
|
||||
err = s3a.touch(dir, name, entry)
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInvalidCopySource, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidCopySource, r)
|
||||
}
|
||||
writeSuccessResponseXML(w, encodeResponse(CopyObjectResult{
|
||||
ETag: fmt.Sprintf("%x", entry.Attributes.Md5),
|
||||
|
@ -48,12 +48,12 @@ 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 srcObject == "" || srcBucket == "" {
|
||||
writeErrorResponse(w, s3err.ErrInvalidCopySource, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidCopySource, r)
|
||||
return
|
||||
}
|
||||
|
||||
if srcBucket == dstBucket && srcObject == dstObject {
|
||||
writeErrorResponse(w, s3err.ErrInvalidCopyDest, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidCopyDest, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ func (s3a *S3ApiServer) CopyObjectHandler(w http.ResponseWriter, r *http.Request
|
|||
|
||||
_, _, resp, err := util.DownloadFile(srcUrl)
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInvalidCopySource, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidCopySource, r)
|
||||
return
|
||||
}
|
||||
defer util.CloseResponse(resp)
|
||||
|
@ -73,7 +73,7 @@ func (s3a *S3ApiServer) CopyObjectHandler(w http.ResponseWriter, r *http.Request
|
|||
etag, errCode := s3a.putToFiler(r, dstUrl, resp.Body)
|
||||
|
||||
if errCode != s3err.ErrNone {
|
||||
writeErrorResponse(w, errCode, r.URL)
|
||||
writeErrorResponse(w, errCode, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Req
|
|||
srcBucket, srcObject := pathToBucketAndObject(cpSrcPath)
|
||||
// If source object is empty or bucket is empty, reply back invalid copy source.
|
||||
if srcObject == "" || srcBucket == "" {
|
||||
writeErrorResponse(w, s3err.ErrInvalidCopySource, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidCopySource, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -126,13 +126,13 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Req
|
|||
|
||||
partID, err := strconv.Atoi(partIDString)
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInvalidPart, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidPart, r)
|
||||
return
|
||||
}
|
||||
|
||||
// check partID with maximum part ID for multipart objects
|
||||
if partID > globalMaxPartID {
|
||||
writeErrorResponse(w, s3err.ErrInvalidMaxParts, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidMaxParts, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Req
|
|||
|
||||
dataReader, err := util.ReadUrlAsReaderCloser(srcUrl, rangeHeader)
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInvalidCopySource, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidCopySource, r)
|
||||
return
|
||||
}
|
||||
defer dataReader.Close()
|
||||
|
@ -154,7 +154,7 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Req
|
|||
etag, errCode := s3a.putToFiler(r, dstUrl, dataReader)
|
||||
|
||||
if errCode != s3err.ErrNone {
|
||||
writeErrorResponse(w, errCode, r.URL)
|
||||
writeErrorResponse(w, errCode, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -44,20 +44,20 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
|
|||
|
||||
_, err := validateContentMd5(r.Header)
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInvalidDigest, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidDigest, r)
|
||||
return
|
||||
}
|
||||
|
||||
if r.Header.Get("Cache-Control") != "" {
|
||||
if _, err = cacheobject.ParseRequestCacheControl(r.Header.Get("Cache-Control")); err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInvalidDigest, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidDigest, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if r.Header.Get("Expires") != "" {
|
||||
if _, err = time.Parse(http.TimeFormat, r.Header.Get("Expires")); err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInvalidDigest, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidDigest, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -75,12 +75,12 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
|
|||
_, s3ErrCode = s3a.iam.reqSignatureV4Verify(r)
|
||||
}
|
||||
if s3ErrCode != s3err.ErrNone {
|
||||
writeErrorResponse(w, s3ErrCode, r.URL)
|
||||
writeErrorResponse(w, s3ErrCode, r)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if authTypeStreamingSigned == rAuthType {
|
||||
writeErrorResponse(w, s3err.ErrAuthNotSetup, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrAuthNotSetup, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
|
|||
|
||||
if strings.HasSuffix(object, "/") {
|
||||
if err := s3a.mkdir(s3a.option.BucketsPath, bucket+object, nil); err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
@ -97,7 +97,7 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
|
|||
etag, errCode := s3a.putToFiler(r, uploadUrl, dataReader)
|
||||
|
||||
if errCode != s3err.ErrNone {
|
||||
writeErrorResponse(w, errCode, r.URL)
|
||||
writeErrorResponse(w, errCode, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ func (s3a *S3ApiServer) GetObjectHandler(w http.ResponseWriter, r *http.Request)
|
|||
bucket, object := getBucketAndObject(r)
|
||||
|
||||
if strings.HasSuffix(r.URL.Path, "/") {
|
||||
writeErrorResponse(w, s3err.ErrNotImplemented, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrNotImplemented, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -195,13 +195,13 @@ func (s3a *S3ApiServer) DeleteMultipleObjectsHandler(w http.ResponseWriter, r *h
|
|||
|
||||
deleteXMLBytes, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r)
|
||||
return
|
||||
}
|
||||
|
||||
deleteObjects := &DeleteObjectsRequest{}
|
||||
if err := xml.Unmarshal(deleteXMLBytes, deleteObjects); err != nil {
|
||||
writeErrorResponse(w, s3err.ErrMalformedXML, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrMalformedXML, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -297,7 +297,7 @@ func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, des
|
|||
|
||||
if err != nil {
|
||||
glog.Errorf("NewRequest %s: %v", destUrl, err)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -327,19 +327,19 @@ func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, des
|
|||
|
||||
if postErr != nil {
|
||||
glog.Errorf("post to filer: %v", postErr)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r)
|
||||
return
|
||||
}
|
||||
defer util.CloseResponse(resp)
|
||||
|
||||
if resp.StatusCode == http.StatusPreconditionFailed {
|
||||
writeErrorResponse(w, s3err.ErrPreconditionFailed, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrPreconditionFailed, r)
|
||||
return
|
||||
}
|
||||
|
||||
if (resp.ContentLength == -1 || resp.StatusCode == 404) && resp.StatusCode != 304 {
|
||||
if r.Method != "DELETE" {
|
||||
writeErrorResponse(w, s3err.ErrNoSuchKey, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrNoSuchKey, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,23 +26,23 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
|
|||
|
||||
reader, err := r.MultipartReader()
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrMalformedPOSTRequest, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrMalformedPOSTRequest, r)
|
||||
return
|
||||
}
|
||||
form, err := reader.ReadForm(int64(5 * humanize.MiByte))
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrMalformedPOSTRequest, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrMalformedPOSTRequest, r)
|
||||
return
|
||||
}
|
||||
defer form.RemoveAll()
|
||||
|
||||
fileBody, fileName, fileSize, formValues, err := extractPostPolicyFormValues(form)
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrMalformedPOSTRequest, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrMalformedPOSTRequest, r)
|
||||
return
|
||||
}
|
||||
if fileBody == nil {
|
||||
writeErrorResponse(w, s3err.ErrPOSTFileRequired, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrPOSTFileRequired, r)
|
||||
return
|
||||
}
|
||||
defer fileBody.Close()
|
||||
|
@ -60,7 +60,7 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
|
|||
if successRedirect != "" {
|
||||
redirectURL, err = url.Parse(successRedirect)
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrMalformedPOSTRequest, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrMalformedPOSTRequest, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -68,13 +68,13 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
|
|||
// Verify policy signature.
|
||||
errCode := s3a.iam.doesPolicySignatureMatch(formValues)
|
||||
if errCode != s3err.ErrNone {
|
||||
writeErrorResponse(w, errCode, r.URL)
|
||||
writeErrorResponse(w, errCode, r)
|
||||
return
|
||||
}
|
||||
|
||||
policyBytes, err := base64.StdEncoding.DecodeString(formValues.Get("Policy"))
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrMalformedPOSTRequest, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrMalformedPOSTRequest, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
|
|||
|
||||
postPolicyForm, err := policy.ParsePostPolicyForm(string(policyBytes))
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrPostPolicyConditionInvalidFormat, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrPostPolicyConditionInvalidFormat, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -99,12 +99,12 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
|
|||
lengthRange := postPolicyForm.Conditions.ContentLengthRange
|
||||
if lengthRange.Valid {
|
||||
if fileSize < lengthRange.Min {
|
||||
writeErrorResponse(w, s3err.ErrEntityTooSmall, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrEntityTooSmall, r)
|
||||
return
|
||||
}
|
||||
|
||||
if fileSize > lengthRange.Max {
|
||||
writeErrorResponse(w, s3err.ErrEntityTooLarge, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrEntityTooLarge, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
|
|||
etag, errCode := s3a.putToFiler(r, uploadUrl, fileBody)
|
||||
|
||||
if errCode != s3err.ErrNone {
|
||||
writeErrorResponse(w, errCode, r.URL)
|
||||
writeErrorResponse(w, errCode, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ func (s3a *S3ApiServer) NewMultipartUploadHandler(w http.ResponseWriter, r *http
|
|||
glog.V(2).Info("NewMultipartUploadHandler", string(encodeResponse(response)), errCode)
|
||||
|
||||
if errCode != s3err.ErrNone {
|
||||
writeErrorResponse(w, errCode, r.URL)
|
||||
writeErrorResponse(w, errCode, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ func (s3a *S3ApiServer) CompleteMultipartUploadHandler(w http.ResponseWriter, r
|
|||
glog.V(2).Info("CompleteMultipartUploadHandler", string(encodeResponse(response)), errCode)
|
||||
|
||||
if errCode != s3err.ErrNone {
|
||||
writeErrorResponse(w, errCode, r.URL)
|
||||
writeErrorResponse(w, errCode, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ func (s3a *S3ApiServer) AbortMultipartUploadHandler(w http.ResponseWriter, r *ht
|
|||
})
|
||||
|
||||
if errCode != s3err.ErrNone {
|
||||
writeErrorResponse(w, errCode, r.URL)
|
||||
writeErrorResponse(w, errCode, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -94,13 +94,13 @@ func (s3a *S3ApiServer) ListMultipartUploadsHandler(w http.ResponseWriter, r *ht
|
|||
|
||||
prefix, keyMarker, uploadIDMarker, delimiter, maxUploads, encodingType := getBucketMultipartResources(r.URL.Query())
|
||||
if maxUploads < 0 {
|
||||
writeErrorResponse(w, s3err.ErrInvalidMaxUploads, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidMaxUploads, r)
|
||||
return
|
||||
}
|
||||
if keyMarker != "" {
|
||||
// Marker not common with prefix is not implemented.
|
||||
if !strings.HasPrefix(keyMarker, prefix) {
|
||||
writeErrorResponse(w, s3err.ErrNotImplemented, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrNotImplemented, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ func (s3a *S3ApiServer) ListMultipartUploadsHandler(w http.ResponseWriter, r *ht
|
|||
glog.V(2).Info("ListMultipartUploadsHandler", string(encodeResponse(response)), errCode)
|
||||
|
||||
if errCode != s3err.ErrNone {
|
||||
writeErrorResponse(w, errCode, r.URL)
|
||||
writeErrorResponse(w, errCode, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -133,11 +133,11 @@ func (s3a *S3ApiServer) ListObjectPartsHandler(w http.ResponseWriter, r *http.Re
|
|||
|
||||
uploadID, partNumberMarker, maxParts, _ := getObjectResources(r.URL.Query())
|
||||
if partNumberMarker < 0 {
|
||||
writeErrorResponse(w, s3err.ErrInvalidPartNumberMarker, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidPartNumberMarker, r)
|
||||
return
|
||||
}
|
||||
if maxParts < 0 {
|
||||
writeErrorResponse(w, s3err.ErrInvalidMaxParts, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidMaxParts, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ func (s3a *S3ApiServer) ListObjectPartsHandler(w http.ResponseWriter, r *http.Re
|
|||
glog.V(2).Info("ListObjectPartsHandler", string(encodeResponse(response)), errCode)
|
||||
|
||||
if errCode != s3err.ErrNone {
|
||||
writeErrorResponse(w, errCode, r.URL)
|
||||
writeErrorResponse(w, errCode, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -167,18 +167,18 @@ func (s3a *S3ApiServer) PutObjectPartHandler(w http.ResponseWriter, r *http.Requ
|
|||
uploadID := r.URL.Query().Get("uploadId")
|
||||
exists, err := s3a.exists(s3a.genUploadsFolder(bucket), uploadID, true)
|
||||
if !exists {
|
||||
writeErrorResponse(w, s3err.ErrNoSuchUpload, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrNoSuchUpload, r)
|
||||
return
|
||||
}
|
||||
|
||||
partIDString := r.URL.Query().Get("partNumber")
|
||||
partID, err := strconv.Atoi(partIDString)
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInvalidPart, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidPart, r)
|
||||
return
|
||||
}
|
||||
if partID > globalMaxPartID {
|
||||
writeErrorResponse(w, s3err.ErrInvalidMaxParts, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidMaxParts, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ func (s3a *S3ApiServer) PutObjectPartHandler(w http.ResponseWriter, r *http.Requ
|
|||
_, s3ErrCode = s3a.iam.reqSignatureV4Verify(r)
|
||||
}
|
||||
if s3ErrCode != s3err.ErrNone {
|
||||
writeErrorResponse(w, s3ErrCode, r.URL)
|
||||
writeErrorResponse(w, s3ErrCode, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ func (s3a *S3ApiServer) PutObjectPartHandler(w http.ResponseWriter, r *http.Requ
|
|||
etag, errCode := s3a.putToFiler(r, uploadUrl, dataReader)
|
||||
|
||||
if errCode != s3err.ErrNone {
|
||||
writeErrorResponse(w, errCode, r.URL)
|
||||
writeErrorResponse(w, errCode, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -25,10 +25,10 @@ func (s3a *S3ApiServer) GetObjectTaggingHandler(w http.ResponseWriter, r *http.R
|
|||
if err != nil {
|
||||
if err == filer_pb.ErrNotFound {
|
||||
glog.Errorf("GetObjectTaggingHandler %s: %v", r.URL, err)
|
||||
writeErrorResponse(w, s3err.ErrNoSuchKey, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrNoSuchKey, r)
|
||||
} else {
|
||||
glog.Errorf("GetObjectTaggingHandler %s: %v", r.URL, err)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -50,29 +50,29 @@ func (s3a *S3ApiServer) PutObjectTaggingHandler(w http.ResponseWriter, r *http.R
|
|||
input, err := ioutil.ReadAll(io.LimitReader(r.Body, r.ContentLength))
|
||||
if err != nil {
|
||||
glog.Errorf("PutObjectTaggingHandler read input %s: %v", r.URL, err)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r)
|
||||
return
|
||||
}
|
||||
if err = xml.Unmarshal(input, tagging); err != nil {
|
||||
glog.Errorf("PutObjectTaggingHandler Unmarshal %s: %v", r.URL, err)
|
||||
writeErrorResponse(w, s3err.ErrMalformedXML, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrMalformedXML, r)
|
||||
return
|
||||
}
|
||||
tags := tagging.ToTags()
|
||||
if len(tags) > 10 {
|
||||
glog.Errorf("PutObjectTaggingHandler tags %s: %d tags more than 10", r.URL, len(tags))
|
||||
writeErrorResponse(w, s3err.ErrInvalidTag, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidTag, r)
|
||||
return
|
||||
}
|
||||
for k, v := range tags {
|
||||
if len(k) > 128 {
|
||||
glog.Errorf("PutObjectTaggingHandler tags %s: tag key %s longer than 128", r.URL, k)
|
||||
writeErrorResponse(w, s3err.ErrInvalidTag, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidTag, r)
|
||||
return
|
||||
}
|
||||
if len(v) > 256 {
|
||||
glog.Errorf("PutObjectTaggingHandler tags %s: tag value %s longer than 256", r.URL, v)
|
||||
writeErrorResponse(w, s3err.ErrInvalidTag, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidTag, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -80,10 +80,10 @@ func (s3a *S3ApiServer) PutObjectTaggingHandler(w http.ResponseWriter, r *http.R
|
|||
if err = s3a.setTags(dir, name, tagging.ToTags()); err != nil {
|
||||
if err == filer_pb.ErrNotFound {
|
||||
glog.Errorf("PutObjectTaggingHandler setTags %s: %v", r.URL, err)
|
||||
writeErrorResponse(w, s3err.ErrNoSuchKey, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrNoSuchKey, r)
|
||||
} else {
|
||||
glog.Errorf("PutObjectTaggingHandler setTags %s: %v", r.URL, err)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -105,10 +105,10 @@ func (s3a *S3ApiServer) DeleteObjectTaggingHandler(w http.ResponseWriter, r *htt
|
|||
if err != nil {
|
||||
if err == filer_pb.ErrNotFound {
|
||||
glog.Errorf("DeleteObjectTaggingHandler %s: %v", r.URL, err)
|
||||
writeErrorResponse(w, s3err.ErrNoSuchKey, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrNoSuchKey, r)
|
||||
} else {
|
||||
glog.Errorf("DeleteObjectTaggingHandler %s: %v", r.URL, err)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -44,11 +44,11 @@ func (s3a *S3ApiServer) ListObjectsV2Handler(w http.ResponseWriter, r *http.Requ
|
|||
originalPrefix, continuationToken, startAfter, delimiter, _, maxKeys := getListObjectsV2Args(r.URL.Query())
|
||||
|
||||
if maxKeys < 0 {
|
||||
writeErrorResponse(w, s3err.ErrInvalidMaxKeys, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidMaxKeys, r)
|
||||
return
|
||||
}
|
||||
if delimiter != "" && delimiter != "/" {
|
||||
writeErrorResponse(w, s3err.ErrNotImplemented, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrNotImplemented, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -60,13 +60,13 @@ func (s3a *S3ApiServer) ListObjectsV2Handler(w http.ResponseWriter, r *http.Requ
|
|||
response, err := s3a.listFilerEntries(bucket, originalPrefix, maxKeys, marker, delimiter)
|
||||
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r)
|
||||
return
|
||||
}
|
||||
|
||||
if len(response.Contents) == 0 {
|
||||
if exists, existErr := s3a.exists(s3a.option.BucketsPath, bucket, true); existErr == nil && !exists {
|
||||
writeErrorResponse(w, s3err.ErrNoSuchBucket, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrNoSuchBucket, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -99,24 +99,24 @@ func (s3a *S3ApiServer) ListObjectsV1Handler(w http.ResponseWriter, r *http.Requ
|
|||
originalPrefix, marker, delimiter, maxKeys := getListObjectsV1Args(r.URL.Query())
|
||||
|
||||
if maxKeys < 0 {
|
||||
writeErrorResponse(w, s3err.ErrInvalidMaxKeys, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInvalidMaxKeys, r)
|
||||
return
|
||||
}
|
||||
if delimiter != "" && delimiter != "/" {
|
||||
writeErrorResponse(w, s3err.ErrNotImplemented, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrNotImplemented, r)
|
||||
return
|
||||
}
|
||||
|
||||
response, err := s3a.listFilerEntries(bucket, originalPrefix, maxKeys, marker, delimiter)
|
||||
|
||||
if err != nil {
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrInternalError, r)
|
||||
return
|
||||
}
|
||||
|
||||
if len(response.Contents) == 0 {
|
||||
if exists, existErr := s3a.exists(s3a.option.BucketsPath, bucket, true); existErr == nil && !exists {
|
||||
writeErrorResponse(w, s3err.ErrNoSuchBucket, r.URL)
|
||||
writeErrorResponse(w, s3err.ErrNoSuchBucket, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue