func ResponseChallenges(resp *http.Response) []Challenge {
	if resp.StatusCode == http.StatusUnauthorized {
		return parseAuthHeader(resp.Header)
	}
	return nil
}
ResponseChallenges returns a list of authorization challenges
for the given http Response. Challenges are only checked if
the response status code was a 401.
package challenge
import (
	"fmt"
	"net/http"
	"net/url"
	"strings"
	"sync"
)
type Challenge struct {
	Scheme string
	Parameters map[string]string
}
type Manager interface {
	GetChallenges(endpoint url.URL) ([]Challenge, error)
	AddResponse(resp *http.Response) error
}
func NewSimpleManager() Manager {
	return &simpleManager{
		Challanges: make(map[string][]Challenge),
	}
}
type simpleManager struct {
	sync.RWMutex
	Challanges map[string][]Challenge
}
func normalizeURL(endpoint *url.URL) {
	endpoint.Host = strings.ToLower(endpoint.Host)
	endpoint.Host = canonicalAddr(endpoint)
}
func (m *simpleManager) GetChallenges(endpoint url.URL) ([]Challenge, error) {
	normalizeURL(&endpoint)
	m.RLock()
	defer m.RUnlock()
	challenges := m.Challanges[endpoint.String()]
	return challenges, nil
}
func (m *simpleManager) AddResponse(resp *http.Response) error {
	challenges := ResponseChallenges(resp)
	if resp.Request == nil {
		return fmt.Errorf("missing request reference")
	}
	urlCopy := url.URL{
		Path:   resp.Request.URL.Path,
		Host:   resp.Request.URL.Host,
		Scheme: resp.Request.URL.Scheme,
	}
	normalizeURL(&urlCopy)
	m.Lock()
	defer m.Unlock()
	m.Challanges[urlCopy.String()] = challenges
	return nil
}
type octetType byte
var octetTypes [256]octetType
const (
	isToken octetType = 1 << iota
	isSpace
)
func init() {
	for c := 0; c < 256; c++ {
		var t octetType
		isCtl := c <= 31 || c == 127
		isChar := 0 <= c && c <= 127
		isSeparator := strings.IndexRune(" \t\"(),/:;<=>?@[]\\{}", rune(c)) >= 0
		if strings.IndexRune(" \t\r\n", rune(c)) >= 0 {
			t |= isSpace
		}
		if isChar && !isCtl && !isSeparator {
			t |= isToken
		}
		octetTypes[c] = t
	}
}