From 8f8289976a2845c77b194fa3eaaa9fb4ea293677 Mon Sep 17 00:00:00 2001 From: calin Date: Wed, 20 Apr 2022 21:38:04 -0600 Subject: [PATCH] Set BasicAuth in http.go only if username and password are not empty 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. --- 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