Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support curl ;type magic string in multipart/form-data request #3219

Open
fenuks opened this issue Sep 6, 2024 · 0 comments
Open

Support curl ;type magic string in multipart/form-data request #3219

fenuks opened this issue Sep 6, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@fenuks
Copy link

fenuks commented Sep 6, 2024

Problem to solve

I want to send multipart/form-data request and set Content-Type for each part. curl allows that adding ;type=<content type> for each --form argument. Example from curl manual:
curl -F "name=daniel;type=text/foo" example.com

Proposal

# demo.hurl
POST http://localhost:8000
Content-Type: multipart/form-data
[MultipartFormData]
file: file,demo.hurl;
data: {"some": "json"};type=application/json
HTTP 200

Additional context and resources

Hurl already allows adding content type for files after ;, but only for files, and without type= keyword.

Support can be emulated saving JSON payload to separate file, but it's a bit tedious to have separate file for each JSON part.

Possibly one could also use multipart forms with a multiline string body, but that would work only for text payloads, and in my case, I want to send a binary file, and some JSON with appropriate content type.

If you save example above to demo.hurl, run netcat to listen on port nc -l -p 8000, and then hurl with hurl --verbose demo.hurl, you will see that hurl sends JSON bits as

Content-Disposition: form-data; name="data"

{"some": "json"};type=application/json

but hurl also informs that this request can be run with

curl --header 'Content-Type: multipart/form-data' --form '[email protected];type=application/octet-stream' --form 'data={"some": "json"};type=application/json' 'http://localhost:8000'

which sends

Content-Disposition: form-data; name="data"
Content-Type: application/json

{"some": "json"}

which is a quite funny discrepancy. Shame one cannot exploit it forcing hurl to invoke curl binary instead of using curl library.

@fenuks fenuks added the enhancement New feature or request label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant