router-for-me/CLIProxyAPI · warning

parse redirect location: %w

Error message

parse redirect location: %w

What it means

After parsing the base, pluginStoreRedirectURL resolves the Location value against it with base.Parse(location). 'parse redirect location: %w' wraps that failure — the Location header value itself is not parseable as a URI reference (for example it contains control characters or an invalid escape sequence).

Source

Thrown at internal/pluginstore/github.go:254

	case http.StatusMovedPermanently, http.StatusFound, http.StatusSeeOther, http.StatusTemporaryRedirect, http.StatusPermanentRedirect:
		return true
	default:
		return false
	}
}

func pluginStoreRedirectURL(resp *http.Response, requestURL string) (string, error) {
	location := strings.TrimSpace(resp.Header.Get("Location"))
	if location == "" {
		return "", fmt.Errorf("redirect missing Location header")
	}
	base, errBase := url.Parse(requestURL)
	if errBase != nil {
		return "", fmt.Errorf("parse redirect base: %w", errBase)
	}
	next, errNext := base.Parse(location)
	if errNext != nil {
		return "", fmt.Errorf("parse redirect location: %w", errNext)
	}
	if next.Scheme == "" || next.Host == "" {
		return "", fmt.Errorf("redirect location is not absolute")
	}
	return next.String(), nil
}

func readPluginStoreResponse(resp *http.Response, maxSize int64, authenticated bool) ([]byte, error) {
	defer func() {
		if errClose := resp.Body.Close(); errClose != nil {
			log.WithError(errClose).Debug("failed to close plugin store response body")
		}
	}()
	if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
		if authenticated {
			return nil, fmt.Errorf("unexpected status %d", resp.StatusCode)
		}
		body, _ := io.ReadAll(io.LimitReader(resp.Body, 4096))

View on GitHub (pinned to 78f0c4079e)

Solutions

  1. Capture the raw Location header (curl -I) and fix the encoding on the server that emits it.
  2. Percent-encode dynamic path segments in redirect targets if you control the redirecting service.
  3. Pin direct artifact URLs in the manifest to avoid the broken redirector altogether.
Defensive patterns

Strategy: validation

Try / catch

if err := fetch(); err != nil {
    if strings.Contains(err.Error(), "parse redirect location") {
        // malformed Location from server — pin a direct URL; do not retry the same hop
    }
}

Prevention

When it happens

Trigger: A Location header with malformed percent-encodings (e.g. '%zz') or embedded control characters/CR-LF, causing url.URL reference resolution to fail.

Common situations: Buggy servers or middleboxes emitting unescaped characters in Location; crafted or corrupted responses; rarely, GitHub API edge cases after token-redemption redirects.

Related errors


AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15). Data as JSON: /api/errors/b3d7a8152e013b79. Report an issue: GitHub.