Skip to content

fix: --multipart silently drops := / :=@ JSON fields - #1957

Closed
harsh-thakkar7 wants to merge 1 commit into
httpie:masterfrom
harsh-thakkar7:fix/multipart-raw-json-fields
Closed

harsh-thakkar7 wants to merge 1 commit into
httpie:masterfrom
harsh-thakkar7:fix/multipart-raw-json-fields

Conversation

@harsh-thakkar7

Copy link
Copy Markdown

--multipart silently dropped := and :=@ JSON fields, even though the same syntax is documented (and implemented) for --form:

$ echo '{"a": "b"}' | http --multipart POST example.com/x key:=true
# request body contained only file-upload style fields β€” `key` vanished entirely

SEPARATORS_GROUP_MULTIPART in httpie/cli/constants.py was missing SEPARATOR_DATA_RAW_JSON (:=) and SEPARATOR_DATA_EMBED_RAW_JSON_FILE (:=@). Request items are routed in requestitems.py's ProcessMultiItemArgs by that constant, so :=/:=@ fields were pushed into args.data β€” which the multipart encoder never reads:

# client.py
data, headers['Content-Type'] = get_multipart_data_and_content_type(
    data=args.multipart_data,   # ← args.data is ignored here
    boundary=...
)

The value vanished without an error, contradicting the changelog claim that JSON field syntax works with --form/--multipart.

Fix

Add both separators to SEPARATORS_GROUP_MULTIPART. The existing per-value conversion (convert_json_value_to_form_if_needed) already serializes primitives to strings and raises Cannot use complex JSON value types with --form/--multipart. for complex ones β€” the same path --form uses β€” so no other code changes were needed.

Tests

  • Parametrized test_simple_json_arguments_with_non_json over ['--form', '--multipart'] β€” the --multipart cases fail before this change (key never reaches the server) and pass after.
  • New test_simple_json_arguments_with_non_json_and_multipart_embed covering :=@ (complex value raises the documented ParseError; scalar value is forwarded β€” also fails before the change).
pytest -q tests/test_json.py tests/test_uploads.py tests/test_cli.py   # 364 passed

SEPARATORS_GROUP_MULTIPART is missing SEPARATOR_DATA_RAW_JSON (:=) and
SEPARATOR_DATA_EMBED_RAW_JSON_FILE (:=@), so ProcessMultiItemArgs routed
those items only into args.data - which the multipart encoder never reads
(get_multipart_data_and_content_type only consumes args.multipart_data).
JSON primitive values in --multipart requests vanished silently, unlike
--form, whose advertised support for the JSON field syntax is shared in
the changelog. Add both separators; complex values still raise the
existing 'Cannot use complex JSON value types' ParseError.
@harsh-thakkar7

Copy link
Copy Markdown
Author

Closing this β€” I don't think this change is mature enough to land right now. Thanks for the project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant