-
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
Expand ArrayBuffer support #1800
Conversation
js/initcontext.go
Outdated
@@ -238,7 +240,8 @@ func (i *InitContext) Open(ctx context.Context, filename string, args ...string) | |||
} | |||
|
|||
if len(args) > 0 && args[0] == "b" { | |||
return i.runtime.ToValue(data), nil | |||
b := i.runtime.NewArrayBuffer(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm while returning the JS equivalent to []byte
from open()
is not ideal, it was somewhat usable. So I am not sure if we should break it, since some scripts probably depend on the current strange behavior. Why not just add another flag value for an ArrayBuffer
response?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I also wasn't sure if we should break it.
Why not just add another flag value for an
ArrayBuffer
response?
:-/ Sure, maybe ab
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, see c593025.
Technically, there's a JS wrapper around the And here (and in But yeah,
This is a viable workaround, but we have to benchmark it... I think it would probably involve copying the whole body, so not great about CPU and memory usage. Better than nothing, but I hope we could find something more efficient. |
Codecov Report
@@ Coverage Diff @@
## master #1800 +/- ##
==========================================
- Coverage 71.61% 71.58% -0.04%
==========================================
Files 181 180 -1
Lines 13939 13962 +23
==========================================
+ Hits 9982 9994 +12
- Misses 3324 3331 +7
- Partials 633 637 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
I added the response body |
I am fairly hard for this being post v0.30.0 I am also of the opinion that we should:
As far as I am concern having 2 binary formats, one of which( Also ... I have barely seen anyone use the |
@na-- @mstoykov I added the k6/crypto and k6/encoding changes to support ArrayBuffer, so I think that covers everything mentioned in #1020. I added a couple of new tests, but mostly edited existing ones to deal with ArrayBuffer properly. Let me know if more tests are missing. We should discuss the breaking changes here, if having |
c745d69
to
baa306e
Compare
I haven't looked at the latest code yet, but have some comments that I hope are not too uninformed...
I am coming around to On another topic, as you know I've gone through most of the old k6 issues, and here is a list of ones related to binary handling or request bodies that I found: #747, #843, #1375, #1382, #1571, #1770, #1784, #1798 I didn't spend a ton of time investigating each issue, but I think that after this PR and grafana/jslib.k6.io#21 are merged, we should go through all of them with a fine-toothed comb. If an issue could be solved by the |
you don't need to wrap it or anything - we should be taking
That will just work if we change to just returning
as long as users just pushed The breaking change comes from the fact that you can take the Given my experiments with My main concern actually is that I agree on the issues, I also would prefer if we go through the documentation of the current "magical" ways to use formdata and document that they are not great and possibly should be abandoned for the FormData polyfill. After some testing of the polyfill of course :) |
Also a relevant problem to some of the changes #1770 (comment) If we are taking So we might need to change this to always go to utf8 for now and add encoding argument, which will be more in line with what nodejs does |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am of the opinion that we should drop the changes where we add a way to return ArrayBuffer
And keep the rest where an ArrayBuffer
is now an appropriate argument for stuff.
This way we can see and test better if we can completely drop returning []byte
for returning ArrayBuffer
instead in it's place. This IMO will require some writing of scripts, possibly going through issues connected with it and trying them.
I myself went down the rabbit whole of what encoding is a string if we take it as []byte
vs as string
in argument which ate too much time.
So as I am of the opinion that taking ArrayBuffer is more important and "probably" backwards compatible it should be done first, and then we can figure out what we do next from there
@mstoykov Makes sense, I'll revert some of the changes then. |
baa306e
to
bfdf164
Compare
bfdf164
to
33815c0
Compare
Reverting got messy, so I reworked the commits and added some tests. Let me know. BTW, if we support passing The current string return value is unfortunate, but if we don't want to break compatibility, then we should add a new |
This doesn't work with ArrayBuffer yet, until grafana/k6#1800 is merged, so the current testSuiteBase will fail. Resolves #21 (review)
This doesn't work with ArrayBuffer yet, until grafana/k6#1800 is merged, so the current testSuiteBase will fail. Resolves #21 (review)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I would want to play with it more, but given #1770 (comment) my main concern is gone so I am fine with this getting merged and fixing it more later
@mstoykov @na-- What do you think about changing |
I think we should have an issue where we discuss those breaking changes. I am of the opinion it is the correct thing for them to return Do you want to try and make an issue for this with some code showing usage that will:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This addresses the backwards compatible changes of #1020, and showcases a workaround for better handling of multipart requests (ref. #747, #843, #1571).