XTLS/Xray-core · error

invalid scheme: %s

Error message

invalid scheme: %s

What it means

fetchHTTPContent (used by xray CLI api/geo resource fetching) parses the target URL and requires the scheme, lowercased, to be exactly http or https. Any other scheme — or a relative URL whose parsed Scheme is empty — is rejected before any request is made.

Source

Thrown at main/commands/all/api/shared.go:83

		data, err = os.ReadFile(arg)
	}

	if err != nil {
		return
	}
	out = bytes.NewBuffer(data)
	return
}

// fetchHTTPContent dials https for remote content
func fetchHTTPContent(target string) ([]byte, error) {
	parsedTarget, err := url.Parse(target)
	if err != nil {
		return nil, err
	}

	if s := strings.ToLower(parsedTarget.Scheme); s != "http" && s != "https" {
		return nil, fmt.Errorf("invalid scheme: %s", parsedTarget.Scheme)
	}

	client := &http.Client{
		Timeout: 30 * time.Second,
	}
	resp, err := client.Do(&http.Request{
		Method: "GET",
		URL:    parsedTarget,
		Close:  true,
	})
	if err != nil {
		return nil, fmt.Errorf("failed to dial to %s", target)
	}
	defer resp.Body.Close()

	if resp.StatusCode != 200 {
		return nil, fmt.Errorf("unexpected HTTP status code: %d", resp.StatusCode)
	}

View on GitHub (pinned to 7d214f8b09)

Solutions

  1. Prefix the URL with https:// (preferred) or http://
  2. For local files, use the local file mechanisms instead of the HTTP fetcher
  3. Double-check scheme spelling

Example fix

// before
"downloadUrl": "github.com/v2fly/geoip/releases/latest" 

// after
"downloadUrl": "https://github.com/v2fly/geoip/releases/latest"
Defensive patterns

Strategy: type-guard

Type guard

function isHTTPURL(s) {
  try {
    const u = new URL(s);
    return u.protocol === "http:" || u.protocol === "https:";
  } catch { return false; }
}
// assert isHTTPURL(downloadUrl) before handing it to xray config

Prevention

When it happens

Trigger: Passing a target like "example.com/geoip.dat" (no scheme → empty), "file:///path", "data:...", or "tls://..." to a command that fetches remote content (e.g. geodata download paths in config or CLI flags).

Common situations: Omitting https:// when setting geoip/geosite download URLs; using a local file path where a URL is expected; scheme typos like "htps://".

Related errors


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/a50fca9e09424911. Report an issue: GitHub.