From 64d5fb56134e4a9e6b7cf373643a172a67da101a Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 20 Nov 2026 03:42:22 -0800 Subject: [PATCH] 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 --- weed/server/filer_server_handlers_copy.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/weed/server/filer_server_handlers_copy.go b/weed/server/filer_server_handlers_copy.go index ed869dd617..93b96e5195 100644 --- a/weed/server/filer_server_handlers_copy.go +++ b/weed/server/filer_server_handlers_copy.go @@ -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 {