mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
filer: copy chunks for cp.from through the shared HTTP client
The copy built a bare client and plain http:// chunk URLs, so with
[https.client] on it could not read from or write to HTTPS volume servers
("source returned status 400"). Use the global client's transport and
redirect policy, and normalize the source and destination URLs to its
scheme.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e15aa250e9
commit
64d5fb5613
1 file changed
+20
-2
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/security"
|
||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||
util_http "github.com/seaweedfs/seaweedfs/weed/util/http"
|
||||
)
|
||||
|
||||
const recentCopyRequestTTL = 2 * time.Minute
|
||||
@@ -262,7 +263,12 @@ func (fs *FilerServer) copyEntry(ctx context.Context, srcEntry *filer.Entry, dst
|
||||
srcChunks := srcEntry.GetChunks()
|
||||
|
||||
// Create HTTP client once for reuse across all chunk operations
|
||||
client := &http.Client{Timeout: 60 * time.Second}
|
||||
globalClient := util_http.GetGlobalHttpClient()
|
||||
client := &http.Client{
|
||||
Timeout: 60 * time.Second,
|
||||
Transport: globalClient.GetClientTransport(),
|
||||
CheckRedirect: globalClient.Client.CheckRedirect,
|
||||
}
|
||||
|
||||
// Check if any chunks are manifest chunks - these require special handling
|
||||
if filer.HasChunkManifest(srcChunks) {
|
||||
@@ -684,7 +690,11 @@ func (fs *FilerServer) createManifestChunk(ctx context.Context, dataChunks []*fi
|
||||
|
||||
// uploadData uploads data to a volume server
|
||||
func (fs *FilerServer) uploadData(ctx context.Context, reader io.Reader, urlLocation, auth string, client *http.Client) error {
|
||||
req, err := http.NewRequestWithContext(ctx, "PUT", urlLocation, reader)
|
||||
target, err := util_http.NormalizeUrl(urlLocation)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid upload url %s: %w", urlLocation, err)
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, "PUT", target, reader)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create upload request: %w", err)
|
||||
}
|
||||
@@ -790,6 +800,14 @@ func (fs *FilerServer) streamCopyChunk(ctx context.Context, srcChunk *filer_pb.F
|
||||
|
||||
// performStreamCopy performs the actual streaming copy from source URL to destination URL
|
||||
func (fs *FilerServer) performStreamCopy(ctx context.Context, srcUrl, dstUrl, auth string, expectedSize uint64, client *http.Client) error {
|
||||
srcUrl, err := util_http.NormalizeUrl(srcUrl)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid source url: %v", err)
|
||||
}
|
||||
if dstUrl, err = util_http.NormalizeUrl(dstUrl); err != nil {
|
||||
return fmt.Errorf("invalid destination url: %v", err)
|
||||
}
|
||||
|
||||
// Create HTTP request to read from source
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", srcUrl, nil)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user