{"record":{"id":"2dcfba63afeaf5fe","repo":"ducaale/xh","slug":"i-head-is-incompatible-with-sending-data-consider-omitting-h","errorCode":null,"errorMessage":"-I/--head is incompatible with sending data. Consider omitting -h/--headers.","messagePattern":"-I/--head is incompatible with sending data\\. Consider omitting -h/--headers\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/to_curl.rs","lineNumber":280,"sourceCode":"        cmd.opt(\"-i\", \"--include\");\n        cmd.opt(\"-X\", \"--request\");\n        cmd.arg(\"OPTIONS\");\n    } else if args.headers {\n        // The best option for printing just headers seems to be to use -I\n        // but with an explicit method as an override.\n        // But this is a hack that actually fails if data is sent.\n        // See discussion on https://lornajane.net/posts/2014/view-only-headers-with-curl\n\n        let method = match args.method {\n            Some(method) => method,\n            // unwrap_or_else causes borrowing issues\n            None => args.request_items.pick_method(),\n        };\n        cmd.opt(\"-I\", \"--head\");\n        cmd.opt(\"-X\", \"--request\");\n        cmd.arg(method.to_string());\n        if method != Method::GET {\n            cmd.warn(\n                \"-I/--head is incompatible with sending data. Consider omitting -h/--headers.\"\n                    .to_string(),\n            );\n        }\n    } else if let Some(method) = args.method {\n        cmd.opt(\"-X\", \"--request\");\n        cmd.arg(method.to_string());\n    } else {\n        // We assume that curl's automatic detection of when to do a POST matches\n        // ours so we can ignore the None case\n    }\n\n    let url = url_with_query(args.url, &args.request_items.query()?);\n\n    if url.as_str().contains(['[', ']', '{', '}']) {\n        cmd.opt(\"-g\", \"--globoff\")\n    }\n","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/ducaale/xh/blob/2404aceecc08b0b2d100fedc96f57745cd5904dc/src/to_curl.rs#L262-L298","documentation":"xh's to_curl translation emits `curl -I` (head request) when the request was constructed as a HEAD (typically via -h/--headers), but the request also carries a body or non-GET method that curl's -I cannot express alongside sent data. Rather than silently producing a wrong curl command, translate() warns that -I/--head is incompatible and suggests omitting -h/--headers.","triggerScenarios":"Running `xh -h/--headers` (or otherwise forcing a HEAD) on a request that also sends data (POST/PUT with a body) and passing --curl/--curl-long so translate() generates the curl command, where method != GET.","commonSituations":"Users combining -h (HEAD) with -d/--data or --raw payloads; scripts converting an xh invocation that accidentally had both -h and a request body into curl; confusion between -h/--headers in xh (HEAD) and -h (header) in curl.","solutions":["Omit -h/--headers so the request keeps its intended method and body","If you truly want a HEAD request, drop the body flags (-d/--data/--raw)","Replace -h with an explicit -X HEAD only if no data is being sent","If you meant to send a header in curl, remember xh uses -H for headers and -h means HEAD"],"exampleFix":"# before\nxh --curl -h POST example.org/api key=value\n\n# after (drop -h to send the POST body)\nxh --curl POST example.org/api key=value","handlingStrategy":"validation","validationCode":"# Reject the combination before running\nif echo \"$args\" | grep -qe '(^| )-h( |$)' && echo \"$args\" | grep -qe '(^| )-d( |$)'; then\n  echo \"error: -h/--headers (HEAD) cannot be combined with a request body\"; exit 1\nfi","typeGuard":"fn is_head_with_body(args: &XhArgs) -> bool {\n    args.headers && args.request_items.body_items().next().is_some()\n}","tryCatchPattern":null,"preventionTips":["Remember xh's -h means HEAD, not 'send header' (that is -H)","Never pair -h/--headers with -d/--data or --raw","Use explicit -X POST/PUT when you intend to send a body","Test generated curl commands with --curl before scripting around them"],"tags":["cli","curl","head-request","incompatible-flags"],"backgroundTag":"mutually-exclusive-flags","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"}