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

Using http.file("something").data as request body is returning an error #2480

Closed
mstoykov opened this issue Apr 6, 2022 · 0 comments · Fixed by #2479
Closed

Using http.file("something").data as request body is returning an error #2480

mstoykov opened this issue Apr 6, 2022 · 0 comments · Fixed by #2479
Labels
Milestone

Comments

@mstoykov
Copy link
Contributor

mstoykov commented Apr 6, 2022

Brief summary

import http from "k6/http";

export default () => {
  let f = http.file("something", "file.bin")
  http.post("https://httpbin.test.k6.io", f.data)
}

After 3bcdabb it started to error with

WARN[0000] Request Failed                                error="unknown request body type int64"

This was because we no longer were using common.Bind to translate arguments of functions, and are now using the pure goja logic of it. And goja tried to translate arrays that will match variadic arguments by assigning element to a variadic argument instead of just as a whole ot the first variadic argument. (in pseudo code):

func s(args ... interface{}) {}
s([1,2,3,4]) // this will result in `args[0] being `1`, `args[1]` being `2` etc.

This was reported (with a kind of different problem) and fixed independently of this issue.

After this was pulled in k6 in 77b5ac8 the error changes to:

WARN[0000] Request Failed                                error="unknown request body type *[]uint8"

This was also reported and fixed.
The upstream issue explains it in more details, but the problem comes from the fact that we get a pointer to the underlying []byte that is http.file.data instead of just a slice.

Note: byte is basically alias for uint8 in go which is why the error says *[]uint8 instead of *[]byte

k6 version

0.36.0 and 0.37.0

OS

linux but applies to all

Docker version and image (if applicable)

No response

Steps to reproduce the problem

import http from "k6/http";

export default () => {
  let f = http.file("something", "file.bin")
  http.post("https://httpbin.test.k6.io", f.data)
}

Expected behaviour

Sending request with a body

Actual behaviour

Error with strange types

@mstoykov mstoykov added the bug label Apr 6, 2022
@mstoykov mstoykov added this to the v0.38.0 milestone Apr 6, 2022
mstoykov added a commit that referenced this issue Apr 6, 2022
mstoykov added a commit that referenced this issue Apr 6, 2022
mstoykov added a commit that referenced this issue Apr 6, 2022
@na-- na-- linked a pull request Apr 6, 2022 that will close this issue
mstoykov added a commit that referenced this issue Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant