From ea645bc4568ff0985e8f2211882073247cd7d7c9 Mon Sep 17 00:00:00 2001
From: Calin <clns@users.noreply.github.com>
Date: Wed, 13 Jul 2022 05:50:31 -0600
Subject: [PATCH] Set BasicAuth in http.go only if username and password are
 not empty (#914)

This prevents error "read/write on closed pipe".

Go's http.client::send() always closes req.Body, so if the first request attempt
is unsuccessful, any subsequent requests after calling the `CredentialsCallback`
will attempt to read/write on a closed pipe.

(cherry picked from commit 9db5de109c166aa802b85cfae2dced3c4728a00d)
---
 http.go | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/http.go b/http.go
index 0777c566..cb4c7d0e 100644
--- a/http.go
+++ b/http.go
@@ -203,7 +203,9 @@ func (self *httpSmartSubtransportStream) sendRequest() error {
 			req.ContentLength = -1
 		}
 
-		req.SetBasicAuth(userName, password)
+		if userName != "" && password != "" {
+			req.SetBasicAuth(userName, password)
+		}
 		resp, err = http.DefaultClient.Do(req)
 		if err != nil {
 			return err