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

fix: implement fetch per spec #928

Merged
merged 56 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
fb9281e
fix: implement fetch per spec
ronag Aug 5, 2021
866cc90
fixup: strict null check
ronag Aug 11, 2021
217af2b
fixup: extractBody
ronag Aug 11, 2021
0d40f36
fixup: body used
ronag Aug 11, 2021
ca62f2a
fixup: use instanceof Blob
ronag Aug 11, 2021
2a6cdb1
fixup
ronag Aug 11, 2021
3113392
fixup
ronag Aug 11, 2021
ffeba7b
fixup: isBodyReadable
ronag Aug 11, 2021
7c288ea
fixup: localURLSOnly
ronag Aug 11, 2021
c03a784
fixup: timingAllow
ronag Aug 11, 2021
c611493
fixup: timingInfo
ronag Aug 11, 2021
360530b
fixup: disregard any enqueuing
ronag Aug 11, 2021
9c9fa53
fixup: strict cmp
ronag Aug 11, 2021
9172bec
fixup: clone
ronag Aug 11, 2021
362ef33
fixup: don't need to copy URL
ronag Aug 11, 2021
1c42102
fix: Response init
ronag Aug 11, 2021
883a56c
fixup: opaqueredirect
ronag Aug 11, 2021
4724d36
fixup: avoid new Response
ronag Aug 11, 2021
8647470
fixup: abort default err
ronag Aug 11, 2021
db693fc
fixup: url
ronag Aug 11, 2021
6c0d4bd
fixup: don't use body.source when writing request body
ronag Aug 11, 2021
f81577a
fixup
ronag Aug 11, 2021
515d6c1
fixup
ronag Aug 11, 2021
e475f5e
fixup: fixes from review
ronag Aug 12, 2021
866e64b
fixup: check valid reason phrase
ronag Aug 12, 2021
e16955e
fixup: error messages
ronag Aug 12, 2021
c2eeb96
fixup: isBuffer
ronag Aug 12, 2021
301dc8e
fixup: more error msg
ronag Aug 12, 2021
9122f57
fixup: forbidden methods
ronag Aug 12, 2021
74fbc20
fixup: node stream body does not violate spec
ronag Aug 12, 2021
25485a0
fixup: error msgs
ronag Aug 12, 2021
3344db1
fixup
ronag Aug 12, 2021
9f2fd14
fixup
ronag Aug 12, 2021
3bcf1a3
fixup
ronag Aug 12, 2021
b397500
fixup
ronag Aug 12, 2021
52f6f83
fixup: chrome compat
ronag Aug 12, 2021
a8a9b6a
fixup
ronag Aug 12, 2021
4ce55d3
fixup: error msgs
ronag Aug 12, 2021
af5866a
fixup
ronag Aug 12, 2021
9f6d2e0
fixup: timingInfo
ronag Aug 12, 2021
1e87e8d
fixup: comments
ronag Aug 12, 2021
7bd95d5
fixup: prettier + standard --fix
ronag Aug 12, 2021
f71abfe
fixup: bad port + missing cond
ronag Aug 12, 2021
41eae28
fixup: docs
ronag Aug 12, 2021
2cf7293
fixup: move fetch to new folder
ronag Aug 12, 2021
83adb4e
fixup: Dispatcher.fetch doesn't exist
ronag Aug 12, 2021
387919b
fixup: link MDN docs
ronag Aug 12, 2021
efddfc2
fixup
ronag Aug 12, 2021
c3822cf
fixup: node fetch in CI
ronag Aug 12, 2021
abe0c68
fixup: terminate on onError
ronag Aug 12, 2021
32aef9f
fixup
ronag Aug 12, 2021
6f005a6
fixup: transmit request body algorithm
ronag Aug 12, 2021
a901f6c
fixup
ronag Aug 12, 2021
b6cb85d
fixup
ronag Aug 12, 2021
53b3ab1
fixup
ronag Aug 12, 2021
260cf8f
fixup
ronag Aug 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,34 @@ jobs:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Install
run: |
npm install

- name: Unit test (no coverage)
- name: Test Tap
run: |
npm test
npm run test:tap

- name: Unit test (coverage)
- name: Test Jest
run: |
npm run coverage:ci
npm run test:jest

# How to run only for Node 16+?
# - name: Test node-fetch
# run: |
# npm run test:node-fetch
ronag marked this conversation as resolved.
Show resolved Hide resolved

- name: Test types
- name: Test Types
run: |
npm run test:typescript

- name: Coverage report
- name: Coverage
run: |
npm run coverage:ci

- name: Coverage Report
uses: codecov/codecov-action@v1
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ See [Dispatcher.connect](docs/api/Dispatcher.md#dispatcherconnect) for more deta

https://fetch.spec.whatwg.org/

### `undici.fetch([url, options]): Promise`
### `undici.fetch(input[, init]): Promise`

Implements [fetch](https://fetch.spec.whatwg.org/).

Expand All @@ -167,8 +167,8 @@ This is [experimental](https://nodejs.org/api/documentation.html#documentation_s

Arguments:

* **url** `string | URL | object`
* **options** `RequestInit`
* **input** `string | Request`
* **init** `RequestInit`

Returns: `Promise<Response>`

Expand Down
2 changes: 0 additions & 2 deletions docs/api/Dispatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ client.dispatch({

### `Dispatcher.fetch(options)`

Implements [fetch](https://fetch.spec.whatwg.org/).

Only supported on Node 16+.

This is [experimental](https://nodejs.org/api/documentation.html#documentation_stability_index) and is not yet fully compliant the Fetch Standard. We plan to ship breaking changes to this feature until it is out of experimental.
Expand Down
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,16 @@ function makeDispatcher (fn) {
module.exports.setGlobalDispatcher = setGlobalDispatcher
module.exports.getGlobalDispatcher = getGlobalDispatcher

module.exports.fetch = makeDispatcher(api.fetch)
if (api.fetch) {
module.exports.fetch = async function fetch (resource, init) {
const dispatcher = getGlobalDispatcher()
return api.fetch.call(dispatcher, resource, init)
}
module.exports.Headers = api.fetch.Headers
module.exports.Response = api.fetch.Response
module.exports.Request = api.fetch.Request
}

module.exports.request = makeDispatcher(api.request)
module.exports.stream = makeDispatcher(api.stream)
module.exports.pipeline = makeDispatcher(api.pipeline)
Expand Down
21 changes: 21 additions & 0 deletions lib/api/api-fetch/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Ethan Arrowood

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
ronag marked this conversation as resolved.
Show resolved Hide resolved
Loading