Repository navigation
Conversation
In HTTPie syntax, field=value form items are text fields whose values are sent as literal strings. When forwarding to curl in form mode, curlie passed -F name=value. Under curl's -F syntax, values beginning with @ or < are interpreted as local file paths to be read and uploaded, rather than literal strings. If the referenced file exists, its contents are uploaded; if not, curl fails with an error (exit code 26). Curl provides --form-string specifically to pass field values literally without interpreting @ or < as file references. Using --form-string ensures consistent behavior with HTTPie and avoids unintended file reads. Reported-by: BS.ehlas.cz
|
This change would remove a useful existing capability: using field=@file or field=<file to upload files or their contents through curl’s -F syntax. I’m fine with aligning the behavior with HTTPie and treating field=value as a literal string, but I’d only accept this PR if it also introduces HTTPie’s field@file syntax for file uploads, so we don’t lose that functionality. |
Since form fields are now passed with --form-string, curl's field=@file / field=<file shortcuts no longer read local files. Add HTTPie's dedicated file upload item instead: with --form, field@path becomes -F field=@path, so the upload is explicit and a literal value starting with @ or < is never taken as a file name. An optional ;type=mime suffix is passed through to curl, matching HTTPie's field@path;type=mime. The @ separator follows HTTPie's first-found rule, so items such as email=me@example.com, From:me@example.com and q==a@b keep their current meaning. Like HTTPie, file fields are only valid with --form; in JSON mode curlie now exits with "invalid file fields (perhaps you meant --form?)" instead of passing the item to curl as an extra URL. Parse returns an error to report this. Reported-by: BS.ehlas.cz
|
Added support for HTTPie's When file upload fields are passed without Added test coverage for file fields, MIME types, literal |
Summary
In HTTPie syntax,
field=valuerequest items specify text form fields whose values are passed as literal strings. When forwarding to curl in form mode (--form), curlie previously translated these items into-F name=value.Under curl's
-Fsyntax, values beginning with@or<have special meaning and are interpreted as local file paths to be read and uploaded, rather than literal strings:curl: (26) Failed to open/read local data from file/application).Curl provides
--form-string name=valuespecifically to pass field values literally without interpreting@or<as file references.Changes
args/httpie.go, translatefieldArginPostModeFORMto--form-string name=valueinstead of-F name=value.main.go, update theisFormcheck to recognizeopts.Has("form-string")so that multipart form requests are properly handled without appending redundant JSON Content-Type headers.args/parse_test.go, add unit testTestParseFormverifying that form fields with@and<values are mapped to--form-string.Test Plan
go test -v ./...(passes with new test case).go vet ./...(clean).--form-stringproperly preserves@and<values in form payloads without attempting to access local files.