mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
refactoring
This commit is contained in:
parent
6d3db4445b
commit
0cb17b45b1
|
@ -105,8 +105,7 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uploadUrl := fmt.Sprintf("http://%s%s/%s%s", s3a.option.Filer.ToHttpAddress(), s3a.option.BucketsPath, bucket, urlPathEscape(object))
|
uploadUrl := s3a.toFilerUrl(bucket, object)
|
||||||
|
|
||||||
if r.Header.Get("Content-Type") == "" {
|
if r.Header.Get("Content-Type") == "" {
|
||||||
dataReader = mimeDetect(r, dataReader)
|
dataReader = mimeDetect(r, dataReader)
|
||||||
}
|
}
|
||||||
|
@ -132,6 +131,12 @@ func urlPathEscape(object string) string {
|
||||||
return strings.Join(escapedParts, "/")
|
return strings.Join(escapedParts, "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s3a *S3ApiServer) toFilerUrl(bucket, object string) string {
|
||||||
|
destUrl := fmt.Sprintf("http://%s%s/%s%s",
|
||||||
|
s3a.option.Filer.ToHttpAddress(), s3a.option.BucketsPath, bucket, urlPathEscape(object))
|
||||||
|
return destUrl
|
||||||
|
}
|
||||||
|
|
||||||
func (s3a *S3ApiServer) GetObjectHandler(w http.ResponseWriter, r *http.Request) {
|
func (s3a *S3ApiServer) GetObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
bucket, object := xhttp.GetBucketAndObject(r)
|
bucket, object := xhttp.GetBucketAndObject(r)
|
||||||
|
@ -142,8 +147,7 @@ func (s3a *S3ApiServer) GetObjectHandler(w http.ResponseWriter, r *http.Request)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
destUrl := fmt.Sprintf("http://%s%s/%s%s",
|
destUrl := s3a.toFilerUrl(bucket, object)
|
||||||
s3a.option.Filer.ToHttpAddress(), s3a.option.BucketsPath, bucket, urlPathEscape(object))
|
|
||||||
|
|
||||||
s3a.proxyToFiler(w, r, destUrl, false, passThroughResponse)
|
s3a.proxyToFiler(w, r, destUrl, false, passThroughResponse)
|
||||||
}
|
}
|
||||||
|
@ -153,8 +157,7 @@ func (s3a *S3ApiServer) HeadObjectHandler(w http.ResponseWriter, r *http.Request
|
||||||
bucket, object := xhttp.GetBucketAndObject(r)
|
bucket, object := xhttp.GetBucketAndObject(r)
|
||||||
glog.V(3).Infof("HeadObjectHandler %s %s", bucket, object)
|
glog.V(3).Infof("HeadObjectHandler %s %s", bucket, object)
|
||||||
|
|
||||||
destUrl := fmt.Sprintf("http://%s%s/%s%s",
|
destUrl := s3a.toFilerUrl(bucket, object)
|
||||||
s3a.option.Filer.ToHttpAddress(), s3a.option.BucketsPath, bucket, urlPathEscape(object))
|
|
||||||
|
|
||||||
s3a.proxyToFiler(w, r, destUrl, false, passThroughResponse)
|
s3a.proxyToFiler(w, r, destUrl, false, passThroughResponse)
|
||||||
}
|
}
|
||||||
|
@ -164,8 +167,7 @@ func (s3a *S3ApiServer) DeleteObjectHandler(w http.ResponseWriter, r *http.Reque
|
||||||
bucket, object := xhttp.GetBucketAndObject(r)
|
bucket, object := xhttp.GetBucketAndObject(r)
|
||||||
glog.V(3).Infof("DeleteObjectHandler %s %s", bucket, object)
|
glog.V(3).Infof("DeleteObjectHandler %s %s", bucket, object)
|
||||||
|
|
||||||
destUrl := fmt.Sprintf("http://%s%s/%s%s?recursive=true",
|
destUrl := s3a.toFilerUrl(bucket, object)
|
||||||
s3a.option.Filer.ToHttpAddress(), s3a.option.BucketsPath, bucket, urlPathEscape(object))
|
|
||||||
|
|
||||||
s3a.proxyToFiler(w, r, destUrl, true, func(proxyResponse *http.Response, w http.ResponseWriter) (statusCode int) {
|
s3a.proxyToFiler(w, r, destUrl, true, func(proxyResponse *http.Response, w http.ResponseWriter) (statusCode int) {
|
||||||
statusCode = http.StatusNoContent
|
statusCode = http.StatusNoContent
|
||||||
|
|
Loading…
Reference in a new issue