-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Automatically marshal JS-object HTTP request bodies when content-type is application/json #878
Comments
A somewhat connected issue: #747 |
Ah, sorry @codebien, looks like I'd forgotten to remove the I'd also forgotten to mention why I added the
So, yeah, we're probably not going to merge #1903, sorry. We'll probably merge something like #1754 in k6 v0.32.0, so we have a sane default for nested objects and close #1713, though maybe not that specific fix PR. And longer term, we plan to add a new k6 HTTP API that would allow for separate HTTP clients and essentially extend and support what we're trying to do with |
Given the last comment by @na--, the team consensus is that we want to avoid automagic behavior, so we will not be changing this in the current HTTP API. We probably won't implement this exactly in the new API (initial design document) either, but will consider a different approach that avoids using |
If we have this example k6 script:
Most people will expect it to print something like
{"arr":[1,2,3,"a"],"str":"test","obj":{"a":"b","c":4}}
, or to print a warning, or even fail with an error.Instead, k6 will silently do a stupid thing and actually assume that the content-type is
application/x-www-form-urlencoded
, and thus try to urlencode the supplied object. Even that may have been fine, if there was a standard in for URL-encoding nested objects. But as far as I can see, there isn't an RFC for this, and and only PHP supports string keys in maps anyway. In the above example, k6 will actually printarr=%5B1+2+3+a%5D&obj=map%5Ba%3Ab+c%3A4%5D&str=test
. Basically converts JS arrays and objects to strings and then just tacks them on, which is pretty much useless to everyone. To get the expected result, users have to manually passJSON.stringify(data)
instead of simplydata
.So my suggestion is to specifically check if a request's body isn't a string or a binary payload and if its
content-type
isapplication/json
and just automatically marshal the request body to JSON.The text was updated successfully, but these errors were encountered: