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

Fetch with integrity option fails on "TypeError: response.arrayBuffer is not a function" #1594

Closed
jelmervdl opened this issue Aug 10, 2022 · 2 comments · Fixed by #1596
Closed
Labels
enhancement New feature or request fetch
Milestone

Comments

@jelmervdl
Copy link
Contributor

Version

18.4.0

Platform

Darwin MPB16.local 21.6.0 Darwin Kernel Version 21.6.0: Sat Jun 18 17:07:25 PDT 2022; root:xnu-8020.140.41~1/RELEASE_X86_64 x86_64

Subsystem

fetch

What steps will reproduce the bug?

Using fetch() with the integrity option seems to consistently fail, throwing from an internal library function.

Simplest example I could come up with:

async function test() {
	const response = await fetch('https://storage.googleapis.com/bergamot-models-sandbox/0.3.3/enes/qualityModel.enes.bin', {
		integrity: 'sha256-zhQfjp5Qpe9NjjJDonSxc03FMvaWN5Sohp3ONay1Q8I='
	})

	console.log(response);
}

test();

How often does it reproduce? Is there a required condition?

Seems to be consistent. Without the integrity option for the request, it succeeds. But with it, it throws. I have not tried it with different hosts.

What is the expected behavior?

The above script retuning and printing the Response object instead of throwing.

What do you see instead?

(node:22831) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/deps/undici/undici:5555
          p.reject(Object.assign(new TypeError("fetch failed"), { cause: response.error }));
                                 ^

TypeError: fetch failed
    at Object.processResponse (node:internal/deps/undici/undici:5555:34)
    at node:internal/deps/undici/undici:5877:42
    at node:internal/process/task_queues:140:7
    at AsyncResource.runInAsyncScope (node:async_hooks:203:9)
    at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  cause: TypeError: response.arrayBuffer is not a function
      at mainFetch (node:internal/deps/undici/undici:5773:38)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
}

Additional information

No response

@jelmervdl jelmervdl changed the title fetch(..., {integrity: "..."}) fails on TypeError: response.arrayBuffer Fetch with integrity option fails on "TypeError: response.arrayBuffer is not a function" Aug 10, 2022
@targos targos transferred this issue from nodejs/node Aug 10, 2022
@mcollina mcollina added enhancement New feature or request fetch labels Aug 10, 2022
@mcollina
Copy link
Member

Thanks for reoporting! I don't think integrity is implemented or tested at all:

undici/lib/fetch/util.js

Lines 342 to 344 in 2944587

function matchRequestIntegrity (request, bytes) {
return false
}

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@KhafraDev
Copy link
Member

The integrity option isn't supported, but the actual error stems from response not being an instance of the WHATWG Response class, but an internal, but separate, response object.

To fix the error, the fully read a body algorithm needs to be implemented.


Hopefully if integrity is implemented, it will encourage other platforms to add it as well. A Deno maintainer has previously stated that they didn't wish to implement any of the fields listed in wintercg/fetch#6 (see: comment), which happened to include integrity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fetch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants