Skip to content

Commit d83c1e2

Browse files
authored
fix(fetch): allow custom implementation of AbortSignal (#1608)
1 parent 5890e16 commit d83c1e2

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

lib/fetch/request.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -835,10 +835,6 @@ webidl.converters.RequestInfo = function (V) {
835835
return webidl.converters.USVString(V)
836836
}
837837

838-
webidl.converters.AbortSignal = webidl.interfaceConverter(
839-
AbortSignal
840-
)
841-
842838
// https://fetch.spec.whatwg.org/#requestinit
843839
webidl.converters.RequestInit = webidl.dictionaryConverter([
844840
{
@@ -913,9 +909,7 @@ webidl.converters.RequestInit = webidl.dictionaryConverter([
913909
},
914910
{
915911
key: 'signal',
916-
converter: webidl.nullableConverter(
917-
webidl.converters.AbortSignal
918-
)
912+
converter: webidl.converters.any
919913
},
920914
{
921915
key: 'window',

test/fetch/abort.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const { once } = require('events')
77
const { ReadableStream } = require('stream/web')
88
const { DOMException } = require('../../lib/fetch/constants')
99

10+
const { AbortController: NPMAbortController } = require('abort-controller')
11+
1012
/* global AbortController */
1113

1214
test('parallel fetch with the same AbortController works as expected', async (t) => {
@@ -106,3 +108,31 @@ test('Readable stream synchronously cancels with AbortError if aborted before re
106108

107109
t.end()
108110
})
111+
112+
test('Allow the usage of custom implementation of AbortController', async (t) => {
113+
const body = {
114+
fixes: 1605
115+
}
116+
117+
const server = createServer((req, res) => {
118+
res.statusCode = 200
119+
res.end(JSON.stringify(body))
120+
})
121+
122+
t.teardown(server.close.bind(server))
123+
124+
server.listen(0)
125+
await once(server, 'listening')
126+
127+
const controller = new NPMAbortController()
128+
const signal = controller.signal
129+
controller.abort()
130+
131+
try {
132+
await fetch(`http://localhost:${server.address().port}`, {
133+
signal
134+
})
135+
} catch (e) {
136+
t.equal(e.code, DOMException.ABORT_ERR)
137+
}
138+
})

0 commit comments

Comments
 (0)