{"record":{"id":"f8de2221cccca17b","repo":"ducaale/xh","slug":"inferred-port-number-in-resolve-from-request-url","errorCode":null,"errorMessage":"Inferred port number in --resolve from request URL.","messagePattern":"Inferred port number in --resolve from request URL\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/to_curl.rs","lineNumber":323,"sourceCode":"        _ => (),\n    };\n\n    if let Some(interface) = args.interface {\n        cmd.arg(\"--interface\");\n        cmd.arg(interface);\n    };\n\n    if let Some(unix_socket) = args.unix_socket {\n        cmd.arg(\"--unix-socket\");\n        cmd.arg(unix_socket);\n    }\n\n    if !args.resolve.is_empty() {\n        let port = url\n            .port_or_known_default()\n            .with_context(|| format!(\"Unsupported URL scheme: '{}'\", url.scheme()))?;\n\n        cmd.warn(\"Inferred port number in --resolve from request URL.\");\n        for resolve in args.resolve {\n            cmd.arg(\"--resolve\");\n            cmd.arg(format!(\"{}:{}:{}\", resolve.domain, port, resolve.addr));\n        }\n    }\n\n    // Payload\n    for (header, value) in headers.iter() {\n        cmd.opt(\"-H\", \"--header\");\n        if value.is_empty() {\n            cmd.arg(format!(\"{header};\"));\n        } else {\n            cmd.arg(format!(\"{}: {}\", header, value.to_utf8_str()?));\n        }\n    }\n    for header in headers_to_unset {\n        cmd.opt(\"-H\", \"--header\");\n        cmd.arg(format!(\"{header}:\"));","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/ducaale/xh/blob/2404aceecc08b0b2d100fedc96f57745cd5904dc/src/to_curl.rs#L305-L341","documentation":"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.","triggerScenarios":"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`.","commonSituations":"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.","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"],"exampleFix":"# before\nxh --curl --resolve=example.org:1.2.3.4 foo://example.org/\n\n# after (explicit port so --resolve can be built)\nxh --curl --resolve=example.org:1.2.3.4 https://example.org:8443/","handlingStrategy":"validation","validationCode":"// Ensure the URL can yield a port before using --resolve\nlet url = reqwest::Url::parse(target)?;\nlet ok = url.port_or_known_default().is_some();\nif !ok {\n    return Err(format!(\"cannot build --resolve: no default port for scheme '{}'\", url.scheme()));\n}","typeGuard":"fn resolve_supported(url: &reqwest::Url) -> bool {\n    url.port_or_known_default().is_some()\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["cli","curl","url","resolve","dns"],"backgroundTag":"invalid-url-format","analyzedSha":"2404aceecc08b0b2d100fedc96f57745cd5904dc","analyzedAt":"2026-09-13T19:13:33.814Z","contentChangedAt":"2026-09-13T19:13:33.814Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}