mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
use final destination to resolve fs configuration
related to https://github.com/chrislusf/seaweedfs/issues/3075
This commit is contained in:
parent
8902fa6ff6
commit
596c3860ca
|
@ -6,4 +6,6 @@ const (
|
||||||
ACTION_ADMIN = "Admin"
|
ACTION_ADMIN = "Admin"
|
||||||
ACTION_TAGGING = "Tagging"
|
ACTION_TAGGING = "Tagging"
|
||||||
ACTION_LIST = "List"
|
ACTION_LIST = "List"
|
||||||
|
|
||||||
|
SeaweedStorageDestinationHeader = "x-seaweedfs-destination"
|
||||||
)
|
)
|
||||||
|
|
|
@ -94,7 +94,8 @@ func (s3a *S3ApiServer) CopyObjectHandler(w http.ResponseWriter, r *http.Request
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
glog.V(2).Infof("copy from %s to %s", srcUrl, dstUrl)
|
glog.V(2).Infof("copy from %s to %s", srcUrl, dstUrl)
|
||||||
etag, errCode := s3a.putToFiler(r, dstUrl, resp.Body)
|
destination := fmt.Sprintf("%s/%s%s", s3a.option.BucketsPath, dstBucket, dstObject)
|
||||||
|
etag, errCode := s3a.putToFiler(r, dstUrl, resp.Body, destination)
|
||||||
|
|
||||||
if errCode != s3err.ErrNone {
|
if errCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, r, errCode)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
|
@ -129,7 +130,7 @@ type CopyPartResult struct {
|
||||||
func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Request) {
|
func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// https://docs.aws.amazon.com/AmazonS3/latest/dev/CopyingObjctsUsingRESTMPUapi.html
|
// https://docs.aws.amazon.com/AmazonS3/latest/dev/CopyingObjctsUsingRESTMPUapi.html
|
||||||
// https://docs.aws.amazon.com/AmazonS3/latest/API/API_UploadPartCopy.html
|
// https://docs.aws.amazon.com/AmazonS3/latest/API/API_UploadPartCopy.html
|
||||||
dstBucket, _ := xhttp.GetBucketAndObject(r)
|
dstBucket, dstObject := xhttp.GetBucketAndObject(r)
|
||||||
|
|
||||||
// Copy source path.
|
// Copy source path.
|
||||||
cpSrcPath, err := url.QueryUnescape(r.Header.Get("X-Amz-Copy-Source"))
|
cpSrcPath, err := url.QueryUnescape(r.Header.Get("X-Amz-Copy-Source"))
|
||||||
|
@ -177,7 +178,8 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Req
|
||||||
defer dataReader.Close()
|
defer dataReader.Close()
|
||||||
|
|
||||||
glog.V(2).Infof("copy from %s to %s", srcUrl, dstUrl)
|
glog.V(2).Infof("copy from %s to %s", srcUrl, dstUrl)
|
||||||
etag, errCode := s3a.putToFiler(r, dstUrl, dataReader)
|
destination := fmt.Sprintf("%s/%s%s", s3a.option.BucketsPath, dstBucket, dstObject)
|
||||||
|
etag, errCode := s3a.putToFiler(r, dstUrl, dataReader, destination)
|
||||||
|
|
||||||
if errCode != s3err.ErrNone {
|
if errCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, r, errCode)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/s3api/s3_constants"
|
||||||
"github.com/chrislusf/seaweedfs/weed/security"
|
"github.com/chrislusf/seaweedfs/weed/security"
|
||||||
"github.com/chrislusf/seaweedfs/weed/util/mem"
|
"github.com/chrislusf/seaweedfs/weed/util/mem"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
|
@ -105,7 +106,7 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
|
||||||
dataReader = mimeDetect(r, dataReader)
|
dataReader = mimeDetect(r, dataReader)
|
||||||
}
|
}
|
||||||
|
|
||||||
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, r, errCode)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
|
@ -379,7 +380,7 @@ func passThroughResponse(proxyResponse *http.Response, w http.ResponseWriter) (s
|
||||||
return statusCode
|
return statusCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s3a *S3ApiServer) putToFiler(r *http.Request, uploadUrl string, dataReader io.Reader) (etag string, code s3err.ErrorCode) {
|
func (s3a *S3ApiServer) putToFiler(r *http.Request, uploadUrl string, dataReader io.Reader, destination string) (etag string, code s3err.ErrorCode) {
|
||||||
|
|
||||||
hash := md5.New()
|
hash := md5.New()
|
||||||
var body = io.TeeReader(dataReader, hash)
|
var body = io.TeeReader(dataReader, hash)
|
||||||
|
@ -392,6 +393,9 @@ func (s3a *S3ApiServer) putToFiler(r *http.Request, uploadUrl string, dataReader
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyReq.Header.Set("X-Forwarded-For", r.RemoteAddr)
|
proxyReq.Header.Set("X-Forwarded-For", r.RemoteAddr)
|
||||||
|
if destination != "" {
|
||||||
|
proxyReq.Header.Set(s3_constants.SeaweedStorageDestinationHeader, destination)
|
||||||
|
}
|
||||||
|
|
||||||
for header, values := range r.Header {
|
for header, values := range r.Header {
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
|
|
|
@ -115,7 +115,7 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
|
||||||
|
|
||||||
uploadUrl := fmt.Sprintf("http://%s%s/%s%s", s3a.option.Filer.ToHttpAddress(), s3a.option.BucketsPath, bucket, urlPathEscape(object))
|
uploadUrl := fmt.Sprintf("http://%s%s/%s%s", s3a.option.Filer.ToHttpAddress(), s3a.option.BucketsPath, bucket, urlPathEscape(object))
|
||||||
|
|
||||||
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, r, errCode)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
|
|
|
@ -250,8 +250,9 @@ func (s3a *S3ApiServer) PutObjectPartHandler(w http.ResponseWriter, r *http.Requ
|
||||||
if partID == 1 && r.Header.Get("Content-Type") == "" {
|
if partID == 1 && r.Header.Get("Content-Type") == "" {
|
||||||
dataReader = mimeDetect(r, dataReader)
|
dataReader = mimeDetect(r, dataReader)
|
||||||
}
|
}
|
||||||
|
destination := fmt.Sprintf("%s/%s%s", s3a.option.BucketsPath, bucket, object)
|
||||||
|
|
||||||
etag, errCode := s3a.putToFiler(r, uploadUrl, dataReader)
|
etag, errCode := s3a.putToFiler(r, uploadUrl, dataReader, destination)
|
||||||
if errCode != s3err.ErrNone {
|
if errCode != s3err.ErrNone {
|
||||||
s3err.WriteErrorResponse(w, r, errCode)
|
s3err.WriteErrorResponse(w, r, errCode)
|
||||||
return
|
return
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/s3api/s3_constants"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -58,8 +59,13 @@ func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request, conte
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
destination := r.RequestURI
|
||||||
|
if finalDestination := r.Header.Get(s3_constants.SeaweedStorageDestinationHeader); finalDestination != "" {
|
||||||
|
destination = finalDestination
|
||||||
|
}
|
||||||
|
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
so, err := fs.detectStorageOption0(r.RequestURI,
|
so, err := fs.detectStorageOption0(destination,
|
||||||
query.Get("collection"),
|
query.Get("collection"),
|
||||||
query.Get("replication"),
|
query.Get("replication"),
|
||||||
query.Get("ttl"),
|
query.Get("ttl"),
|
||||||
|
|
Loading…
Reference in a new issue