-
-
Notifications
You must be signed in to change notification settings - Fork 17.2k
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
Added check to support Uint8Array in response sending #6285
base: master
Are you sure you want to change the base?
Conversation
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.
From that thread, just in case anyone else comes here and is wondering what folks can do in the mean time:
Current workaround is to do Buffer.from(uint8ArrayData) before passing to send method.
because of support to 0.10
We dont support that anymore, so see the one suggestion. 🎉
…isView function check Co-authored-by: Wes Todd <[email protected]>
@wesleytodd okay great! I referred to the compatibility table in the website, but I understood that only v5 was not supporting it anymore. If v4 is not updated anymore (but security fixes and maintenance), this is fine. I've committed the suggested changes. |
v4 is still supported, and we can back port this if you would like to open a PR against the |
I can that, sure! v4 is still widely used so I think it should receive such support. Thanks for the guidance |
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.
Sorry I should have said this in my previous review, but I would love to see a new test for this behavior before we merge. We should ideally use the same test here and in the backport.
I can try to do that in the next days (within the week). If I don't write here anymore, please ping me! 🙌 I have quite busy days upcoming... |
@wesleytodd I found a free moment. I created a test with Uint8Array encoding. Let me know if this works for you or if you had in mind any other ideas to test. |
Allow me to join your discussion. I only encountered UInt8Array issue when migrating from v4 to v5, so the previous version was sending it probably correctly. So before you jump into anything, I would double check. |
@mysuf thanks for joining. This fix actually started from the last version of v4, as I started debugging express as a dependency. Then, I compared the current code in master and I saw no differences. So I wonder how was it actually working for you... |
@alexandercerutti Looking at the v4 codebase and you are absolutely right. I have no clue how it could work, but I swear it did. Anyway thank you for this PR. |
In an attempt to convert
Buffer
toUint8Array
in my codebase, I found out that sending anUint8Array
to.send()
, makes it send as a JSON (which is wrong).This was also noted in a comment in #4807 and I didn't find any issue in the repo (except that answer) or in the documentation about the lack of support to
Uint8Array
.So I decided to look and test for a solution.
It seems to be enough to call
ArrayBuffer.isView()
when the kind of chunk is checked.Even if
ArrayBuffer.isView(chunk)
returnstrue
whenchunk
is aBuffer
, I kept theBuffer.isBuffer(chunk)
check, because of support to0.10
(ArrayBuffer.isView()
seems got introduced in Node v4.0.0, according to MDN).Let me know if you see anything I can improve.