mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* feat: operation: pass needle pairs through chunked uploads (#12997) * feat: s3: build Content-Location needle pair from the object path (#12997) * feat: s3: record object path in needles written by putToFiler (#12997) * feat: s3: record destination object path in copied chunks (#12997) * feat: s3: record destination object path in stream-copied chunks (#12997) * test: s3: pin Content-Location in putToFiler upload options (#12997) * s3: record no path on copies of volume-encrypted chunks A chunk written with -encryptVolumeData is copied as ciphertext through the plain upload path, so the copy sent the destination path in plaintext next to encrypted data, while PutObject's cipher upload sends no pairs at all. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
1.9 KiB
Go
58 lines
1.9 KiB
Go
package s3api
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
|
)
|
|
|
|
// contentLocationPairHeader is sent with every chunk upload. The volume server
|
|
// strips the "Seaweed-" prefix and keeps "Content-Location" in the needle's
|
|
// Pairs, so a needle can be traced back to the S3 object it belongs to.
|
|
const contentLocationPairHeader = "Seaweed-Content-Location"
|
|
|
|
// contentLocationPairMap returns the needle pairs that record filerPath, or nil
|
|
// when the path is unknown.
|
|
func contentLocationPairMap(filerPath string) map[string]string {
|
|
if filerPath == "" {
|
|
return nil
|
|
}
|
|
return map[string]string{contentLocationPairHeader: escapeFilerPath(filerPath)}
|
|
}
|
|
|
|
// copiedChunkContentLocation returns the path a copy of chunk records. A chunk
|
|
// encrypted for the volume server records none: its ciphertext is copied as
|
|
// is, and cipher uploads send no pairs.
|
|
func copiedChunkContentLocation(chunk *filer_pb.FileChunk, dstPath string) string {
|
|
if len(chunk.CipherKey) > 0 {
|
|
return ""
|
|
}
|
|
return dstPath
|
|
}
|
|
|
|
// objectContentLocation returns the filer path of the object a write belongs
|
|
// to. Callers that write to an internal path (UploadPart writes under
|
|
// .uploads/) pass object == "", and the key is taken from the request route.
|
|
func (s3a *S3ApiServer) objectContentLocation(r *http.Request, bucket, object string) string {
|
|
if object == "" {
|
|
_, object = s3_constants.GetBucketAndObject(r)
|
|
}
|
|
if object == "" {
|
|
return ""
|
|
}
|
|
return s3a.toFilerPath(bucket, object)
|
|
}
|
|
|
|
// escapeFilerPath percent-encodes each segment of a filer path, so keys with
|
|
// newlines, '%' or non-ASCII bytes stay valid in an HTTP header.
|
|
func escapeFilerPath(p string) string {
|
|
segments := strings.Split(p, "/")
|
|
for i, s := range segments {
|
|
segments[i] = url.PathEscape(s)
|
|
}
|
|
return strings.Join(segments, "/")
|
|
}
|