Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

sftp,ftp: add http proxy authentication support

Nicolas Dessarta64a8aad0e2d
diff --git a/backend/ftp/ftp.go b/backend/ftp/ftp.go
index fe666fb71..88ddc1008 100644
--- a/backend/ftp/ftp.go
+++ b/backend/ftp/ftp.go
@@ -204,6 +204,12 @@ Example:
Help: `URL for HTTP CONNECT proxy
Set this to a URL for an HTTP proxy which supports the HTTP CONNECT verb.
+
+Supports the format http://user:pass@host:port, http://host:port, http://host.
+
+Example:
+
+ http://myUser:[email protected]:8000
`,
Advanced: true,
}, {
diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.go
index e3d5242fb..f7eb2a1c3 100644
--- a/backend/sftp/sftp.go
+++ b/backend/sftp/sftp.go
@@ -519,6 +519,12 @@ Example:
Help: `URL for HTTP CONNECT proxy
Set this to a URL for an HTTP proxy which supports the HTTP CONNECT verb.
+
+Supports the format http://user:pass@host:port, http://host:port, http://host.
+
+Example:
+
+ http://myUser:[email protected]:8000
`,
Advanced: true,
}, {
diff --git a/docs/content/ftp.md b/docs/content/ftp.md
index 38b9bad0c..6e8495388 100644
--- a/docs/content/ftp.md
+++ b/docs/content/ftp.md
@@ -498,6 +498,12 @@ URL for HTTP CONNECT proxy
Set this to a URL for an HTTP proxy which supports the HTTP CONNECT verb.
+Supports the format http://user:pass@host:port, http://host:port, http://host.
+
+Example:
+
+ http://myUser:[email protected]:8000
+
Properties:
diff --git a/docs/content/sftp.md b/docs/content/sftp.md
index be7aa96ae..b747235de 100644
--- a/docs/content/sftp.md
+++ b/docs/content/sftp.md
@@ -1186,6 +1186,12 @@ URL for HTTP CONNECT proxy
Set this to a URL for an HTTP proxy which supports the HTTP CONNECT verb.
+Supports the format http://user:pass@host:port, http://host:port, http://host.
+
+Example:
+
+ http://myUser:[email protected]:8000
+
Properties:
diff --git a/lib/proxy/http.go b/lib/proxy/http.go
index 616d2c4c1..647a3c5a1 100644
--- a/lib/proxy/http.go
+++ b/lib/proxy/http.go
@@ -3,6 +3,7 @@ package proxy
import (
"bufio"
"crypto/tls"
+ "encoding/base64"
"fmt"
"net"
"net/http"
@@ -55,7 +56,13 @@ func HTTPConnectDial(network, addr string, proxyURL *url.URL, proxyDialer proxy.
}
// send CONNECT
- _, err = fmt.Fprintf(conn, "CONNECT %s HTTP/1.1\r\nHost: %s\r\n\r\n", addr, addr)
+ user := proxyURL.User
+ if user != nil {
+ credential := base64.StdEncoding.EncodeToString([]byte(user.String()))
+ _, err = fmt.Fprintf(conn, "CONNECT %s HTTP/1.1\r\nHost: %s\r\nProxy-Authorization: Basic %s\r\n\r\n", addr, addr, credential)
+ } else {
+ _, err = fmt.Fprintf(conn, "CONNECT %s HTTP/1.1\r\nHost: %s\r\n\r\n", addr, addr)
+ }
if err != nil {
_ = conn.Close()
return nil, fmt.Errorf("HTTP CONNECT proxy failed to send CONNECT: %q", err)