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

lib: implement fetch's Headers class #37355

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
468 changes: 468 additions & 0 deletions lib/internal/fetch/headers.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
'lib/internal/errors.js',
'lib/internal/error_serdes.js',
'lib/internal/event_target.js',
'lib/internal/fetch/headers.js',
'lib/internal/fixed_queue.js',
'lib/internal/freelist.js',
'lib/internal/freeze_intrinsics.js',
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Last update:
- common: https://github.com/web-platform-tests/wpt/tree/841a51412f/common
- dom/abort: https://github.com/web-platform-tests/wpt/tree/7caa3de747/dom/abort
- FileAPI: https://github.com/web-platform-tests/wpt/tree/d9d921b8f9/FileAPI
- fetch: https://github.com/web-platform-tests/wpt/tree/5c46bbe8d0/fetch

[Web Platform Tests]: https://github.com/web-platform-tests/wpt
[`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/master/docs/git-node.md#git-node-wpt
8 changes: 8 additions & 0 deletions test/fixtures/wpt/fetch/META.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
spec: https://fetch.spec.whatwg.org/
suggested_reviewers:
- jdm
- youennf
- annevk
- mnot
- yutakahirano
- domfarolino
6 changes: 6 additions & 0 deletions test/fixtures/wpt/fetch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Tests for the [Fetch Standard](https://fetch.spec.whatwg.org/).

More Fetch tests can be found in

* /cors
* /xhr
47 changes: 47 additions & 0 deletions test/fixtures/wpt/fetch/api/abort/cache.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// META: title=Request signals & the cache API
// META: global=window,worker

promise_test(async () => {
await caches.delete('test');
const controller = new AbortController();
const signal = controller.signal;
const request = new Request('../resources/data.json', { signal });

const cache = await caches.open('test');
await cache.put(request, new Response(''));

const requests = await cache.keys();

assert_equals(requests.length, 1, 'Ensuring cleanup worked');

const [cachedRequest] = requests;

controller.abort();

assert_false(cachedRequest.signal.aborted, "Request from cache shouldn't be aborted");

const data = await fetch(cachedRequest).then(r => r.json());
assert_equals(data.key, 'value', 'Fetch fully completes');
}, "Signals are not stored in the cache API");

promise_test(async () => {
await caches.delete('test');
const controller = new AbortController();
const signal = controller.signal;
const request = new Request('../resources/data.json', { signal });
controller.abort();

const cache = await caches.open('test');
await cache.put(request, new Response(''));

const requests = await cache.keys();

assert_equals(requests.length, 1, 'Ensuring cleanup worked');

const [cachedRequest] = requests;

assert_false(cachedRequest.signal.aborted, "Request from cache shouldn't be aborted");

const data = await fetch(cachedRequest).then(r => r.json());
assert_equals(data.key, 'value', 'Fetch fully completes');
}, "Signals are not stored in the cache API, even if they're already aborted");
27 changes: 27 additions & 0 deletions test/fixtures/wpt/fetch/api/abort/destroyed-context.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// This is a regression test for crbug.com/860063.
window.controller = new AbortController();
async_test(t => {
onmessage = t.step_func(event => {
assert_equals(event.data, 'started');
const iframe = document.querySelector('iframe');
document.body.removeChild(iframe);
controller.abort();
t.done();
});
}, 'aborting a fetch in a destroyed context should not crash');
</script>
<iframe srcdoc="
<!DOCTYPE html>
<meta charset=utf-8>
<script>
fetch('../resources/infinite-slow-response.py', { signal: parent.controller.signal }).then(() => {
parent.postMessage('started', '*');
});
</script>
">
</iframe>
Loading