+ if resp.StatusCode == http.StatusUnauthorized {
+ resp.Body.Close()
+ caches.HTTPAuthCacheM.Lock()
+ if unauthorized {
+ delete(caches.HTTPAuthCache, req.URL.Host)
+ } else {
+ unauthorized = true
+ }
+ fifos.LogVarious <- fmt.Sprintf(
+ "%s %s\tHTTP authorization required", req.Method, req.URL.Host,
+ )
+ user, pass, err := authDialog(host, resp.Header.Get("WWW-Authenticate"))
+ if err != nil {
+ caches.HTTPAuthCacheM.Unlock()
+ fifos.LogErr <- fmt.Sprintf("%s\t%s", req.URL.Host, err.Error())
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ caches.HTTPAuthCache[req.URL.Host] = [2]string{user, pass}
+ caches.HTTPAuthCacheM.Unlock()
+ req.SetBasicAuth(user, pass)
+ fifos.LogHTTPAuth <- fmt.Sprintf("%s %s\t%s", req.Method, req.URL, user)
+ goto Retry
+ }
+ if unauthorized {
+ reqFlags = append(reqFlags, "auth")
+ }
+ if resp.TLS != nil && resp.TLS.NegotiatedProtocol != "" {
+ reqFlags = append(reqFlags, resp.TLS.NegotiatedProtocol)
+ }
+