Example #1
0
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
}
Example #2
0
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)
}