@@ -55,7 +55,7 @@ func (w *readCloserWrapper) Close() error {
5555 return err
5656}
5757
58- func (rt * FTPRoundTripper ) getConnection (hostport string ) (conn * ftp.ServerConn , err error ) {
58+ func (rt * FTPRoundTripper ) getConnection (hostport , username , password string ) (conn * ftp.ServerConn , err error ) {
5959 rt .lock .Lock ()
6060 conns , ok := rt .idleConnections [hostport ]
6161 if ok && len (conns ) > 0 {
@@ -71,7 +71,7 @@ func (rt *FTPRoundTripper) getConnection(hostport string) (conn *ftp.ServerConn,
7171 return nil , err
7272 }
7373
74- err = conn .Login ("anonymous" , "anonymous" )
74+ err = conn .Login (username , password )
7575 if err != nil {
7676 conn .Quit ()
7777 return nil , err
@@ -107,7 +107,17 @@ func (rt *FTPRoundTripper) RoundTrip(request *http.Request) (*http.Response, err
107107 hostport = hostport + ":21"
108108 }
109109
110- connection , err := rt .getConnection (hostport )
110+ username , password := "anonymous" , "anonymous"
111+
112+ if requestUserName , requestPassword , valid := request .BasicAuth (); valid {
113+ username = requestUserName
114+ password = requestPassword
115+ } else if request .URL .User != nil {
116+ username = request .URL .User .Username ()
117+ password , _ = request .URL .User .Password ()
118+ }
119+
120+ connection , err := rt .getConnection (hostport , username , password )
111121 if err != nil {
112122 return nil , err
113123 }
0 commit comments