Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

sftpd: use global TLS-aware HTTP client for filer uploads (#8795)

Chris Lue52a94a3a77b
diff --git a/weed/sftpd/sftp_filer.go b/weed/sftpd/sftp_filer.go
index 93a1d09842..fa69e39f78 100644
--- a/weed/sftpd/sftp_filer.go
+++ b/weed/sftpd/sftp_filer.go
@@ -21,6 +21,7 @@ import (
weed_server "github.com/seaweedfs/seaweedfs/weed/server"
"github.com/seaweedfs/seaweedfs/weed/sftpd/user"
"github.com/seaweedfs/seaweedfs/weed/util"
+ util_http "github.com/seaweedfs/seaweedfs/weed/util/http"
"google.golang.org/grpc"
)
@@ -322,6 +323,12 @@ func (fs *SftpServer) removeDir(absPath string) error {
func (fs *SftpServer) putFile(filepath string, reader io.Reader, user *user.User) error {
dir, filename := util.FullPath(filepath).DirAndName()
uploadUrl := fmt.Sprintf("http://%s%s", fs.filerAddr, filepath)
+ // Let the global HTTP client normalize the scheme to https:// when TLS is configured
+ normalizedUrl, err := util_http.NormalizeUrl(uploadUrl)
+ if err != nil {
+ return fmt.Errorf("normalize upload url %q: %w", uploadUrl, err)
+ }
+ uploadUrl = normalizedUrl
// Compute MD5 while uploading
hash := md5.New()
@@ -342,7 +349,7 @@ func (fs *SftpServer) putFile(filepath string, reader io.Reader, user *user.User
}
}
- resp, err := http.DefaultClient.Do(req)
+ resp, err := util_http.Do(req)
if err != nil {
return fmt.Errorf("upload to filer: %w", err)
}