mislav/hub · error

stopped after 10 redirects

Error message

stopped after 10 redirects

What it means

hub installs a custom checkRedirect on its HTTP client. Inherited from the stdlib defaultCheckRedirect, it returns this error once a request has followed 10 or more redirects (the `via` slice tracks the redirect chain). It guards against redirect loops or misconfigured servers that keep redirecting.

Source

Thrown at github/http.go:231

	var recommendedCode int
	switch req.Response.StatusCode {
	case 301:
		recommendedCode = 308
	case 302:
		recommendedCode = 307
	}

	origMethod := via[len(via)-1].Method
	if recommendedCode != 0 && !strings.EqualFold(req.Method, origMethod) {
		return fmt.Errorf(
			"refusing to follow HTTP %d redirect for a %s request\n"+
				"Have your site admin use HTTP %d for this kind of redirect",
			req.Response.StatusCode, origMethod, recommendedCode)
	}

	// inherited from stdlib defaultCheckRedirect
	if len(via) >= 10 {
		return errors.New("stopped after 10 redirects")
	}
	return nil
}

func cloneRequest(req *http.Request) *http.Request {
	dup := new(http.Request)
	*dup = *req
	dup.URL, _ = url.Parse(req.URL.String())
	dup.Header = make(http.Header)
	for k, s := range req.Header {
		dup.Header[k] = s
	}
	return dup
}

var proxyFunc func(*url.URL) (*url.URL, error)

func proxyFromEnvironment(req *http.Request) (*url.URL, error) {

View on GitHub (pinned to 5c547ed804)

Solutions

  1. Switch your hub GitHub host config from http:// to https:// (or the scheme the server actually serves) to break the scheme-redirect loop.
  2. Check the server's redirect chain with `curl -IL <url>` and fix the proxy/load-balancer configuration causing the loop.
  3. If a proxy is involved, set NO_PROXY/correct proxy env vars so hub talks to the right endpoint directly.

Example fix

// before (~/.config/hub config)
github.com:
  - api_host: http://ghe.example.com
// after
github.com:
  - api_host: https://ghe.example.com
Defensive patterns

Strategy: validation

Validate before calling

// Check the endpoint's redirect chain before configuring hub:
// curl -sIL --max-redirs 15 https://ghe.example.com/api/v3 | grep -i location
// If it loops, fix the server config; if it bounces http->https, use https in hub config.

Try / catch

if err != nil {
    if strings.Contains(err.Error(), "stopped after 10 redirects") {
        // surface hint: likely http/https redirect loop on the GHE host
    }
    return err
}

Prevention

When it happens

Trigger: A GitHub Enterprise host (or proxy) responds with a chain of more than 10 HTTP redirects — typically a redirect loop, e.g. http->https misconfiguration where the server keeps 301/302-ing back to itself or cycling between URLs.

Common situations: GitHub Enterprise behind a reverse proxy with conflicting ssl termination; http:// URL configured for a server that forces https and the https endpoint redirects back; corporate proxy loops; a webhook/upload_url pointing at itself.

Related errors


AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01). Data as JSON: /api/errors/86dfd811e92c4b09. Report an issue: GitHub.