ducaale/xh · error
Inferred port number in --resolve from request URL.
Error message
Inferred port number in --resolve from request URL.
What it means
When translating to curl, --resolve entries need host:port:addr, but the user supplied only domain and address. xh infers the port from the request URL via port_or_known_default(); if the URL's scheme has no known default port (e.g. a custom or unsupported scheme), the port cannot be determined and the translation fails with this context error.
Solutions
- Use an http:// or https:// URL, which have known default ports
- Add the port explicitly to the request URL (e.g. https://example.org:8443/...)
- Drop --resolve if it is not needed for this request
- Check the URL scheme for typos before running
Example fix
# before xh --curl --resolve=example.org:1.2.3.4 foo://example.org/ # after (explicit port so --resolve can be built) xh --curl --resolve=example.org:1.2.3.4 https://example.org:8443/
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the URL can yield a port before using --resolve
let url = reqwest::Url::parse(target)?;
let ok = url.port_or_known_default().is_some();
if !ok {
return Err(format!("cannot build --resolve: no default port for scheme '{}'", url.scheme()));
} Type guard
fn resolve_supported(url: &reqwest::Url) -> bool {
url.port_or_known_default().is_some()
} Prevention
- Always use http/https URLs when passing --resolve
- Include an explicit port in the URL when targeting a non-default port
- Check the scheme for typos (https vs ftp vs custom schemes)
- Only pass --resolve when you actually need DNS pinning
When it happens
Trigger: Calling translate() with a non-empty args.resolve on a request whose URL has no explicit port and whose scheme is not http/https (no known default port), e.g. `xh --resolve=example.org:1.2.3.4 ftp://example.org/file`.
Common situations: Typing a URL with a typo'd or unusual scheme; forgetting to include the port in the URL when using --resolve with a non-http(s) scheme; testing exotic protocols through xh.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- Value should be formatted as
- couldn't extract host from url
- Invalid UTF-8
- JSON values are not supported in multipart fields
- -I/--head is incompatible with sending data. Consider…
AI-assisted analysis of ducaale/xh@2404aceecc (2026-09-13).
Data as JSON: /api/errors/f8de2221cccca17b.
Report an issue: GitHub.
Appendix: source
Thrown at src/to_curl.rs:323
_ => (),
};
if let Some(interface) = args.interface {
cmd.arg("--interface");
cmd.arg(interface);
};
if let Some(unix_socket) = args.unix_socket {
cmd.arg("--unix-socket");
cmd.arg(unix_socket);
}
if !args.resolve.is_empty() {
let port = url
.port_or_known_default()
.with_context(|| format!("Unsupported URL scheme: '{}'", url.scheme()))?;
cmd.warn("Inferred port number in --resolve from request URL.");
for resolve in args.resolve {
cmd.arg("--resolve");
cmd.arg(format!("{}:{}:{}", resolve.domain, port, resolve.addr));
}
}
// Payload
for (header, value) in headers.iter() {
cmd.opt("-H", "--header");
if value.is_empty() {
cmd.arg(format!("{header};"));
} else {
cmd.arg(format!("{}: {}", header, value.to_utf8_str()?));
}
}
for header in headers_to_unset {
cmd.opt("-H", "--header");
cmd.arg(format!("{header}:"));View on GitHub (pinned to 2404aceecc)