예제 #1
0
func httpGet(url string, digestHeaders *digestAuth.DigestHeaders) string {
	tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}

	client := &http.Client{Transport: tr}
	req, err := http.NewRequest("GET", url, nil)
	digestHeaders.ApplyAuth(req)

	check(err)

	resp, err := client.Do(req)

	check(err)

	//determine auth or not
	if resp.StatusCode == 401 {
		updateAuth(digestHeaders, user, pass, url)

		return httpGet(url, digestHeaders)
	} else {
		defer resp.Body.Close()
		body, err := ioutil.ReadAll(resp.Body)

		check(err)

		return string(body)
	}
}
예제 #2
0
func updateAuth(digestHeaders *digestAuth.DigestHeaders, _user string, _pass string, _url string) {
	log.Println("require auth")

	_digestHeaders, err := digestHeaders.Auth(_user, _pass, _url, true)

	check(err)

	//copy auth info into original one
	digestHeaders.Path = _digestHeaders.Path
	digestHeaders.Realm = _digestHeaders.Realm
	digestHeaders.Qop = _digestHeaders.Qop
	digestHeaders.Nonce = _digestHeaders.Nonce
	digestHeaders.Opaque = _digestHeaders.Opaque
	digestHeaders.Algorithm = _digestHeaders.Algorithm
	digestHeaders.Nc = _digestHeaders.Nc
	digestHeaders.Username = _digestHeaders.Username
	digestHeaders.Password = _digestHeaders.Password
}