示例#1
0
文件: acme.go 项目: giantswarm/mayu
func fetchNonce(ctx context.Context, client *http.Client, url string) (string, error) {
	resp, err := ctxhttp.Head(ctx, client, url)
	if err != nil {
		return "", nil
	}
	defer resp.Body.Close()
	enc := resp.Header.Get("replay-nonce")
	if enc == "" {
		return "", errors.New("acme: nonce not found")
	}
	return enc, nil
}
示例#2
0
文件: fetcher.go 项目: vmware/vic
func (u *URLFetcher) head(ctx context.Context, url *url.URL) (http.Header, error) {
	res, err := ctxhttp.Head(ctx, u.client, url.String())
	if err != nil {
		return nil, err
	}
	defer res.Body.Close()

	u.StatusCode = res.StatusCode

	if u.IsStatusUnauthorized() || u.IsStatusOK() {
		return res.Header, nil
	}
	return nil, fmt.Errorf("Unexpected http code: %d, URL: %s", u.StatusCode, url)
}