Skip to content

Commit 721cd23

Browse files
fix(interceptor/dump): reject aborted requests when response is smaller than maxSize (#5685)
Co-authored-by: Cursor <cursoragent@cursor.com> Signed-off-by: codeAnqiang-ma <273298913+codeAnqiang-ma@users.noreply.github.com>
1 parent f2e02f6 commit 721cd23

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎lib/interceptor/dump.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class DumpHandler extends DecoratorHandler {
8484
return
8585
}
8686

87-
if (this.#controller.aborted === true) {
87+
if (this.aborted === true) {
8888
super.onResponseError(controller, this.reason)
8989
return
9090
}

‎test/interceptors/dump-interceptor.js‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,47 @@ test('Should dump on already aborted request', { skip }, async t => {
199199
await t.completed
200200
})
201201

202+
test('Should reject aborted request when response is smaller than maxSize', { skip }, async t => {
203+
t = tspl(t, { plan: 2 })
204+
const server = createServer({ joinDuplicateHeaders: true }, (req, res) => {
205+
res.writeHead(200, {
206+
'Content-Type': 'application/octet-stream'
207+
})
208+
res.end(Buffer.alloc(256))
209+
})
210+
211+
const abc = new AbortController()
212+
213+
const requestOptions = {
214+
method: 'GET',
215+
path: '/',
216+
signal: abc.signal
217+
}
218+
219+
server.listen(0)
220+
221+
await once(server, 'listening')
222+
223+
const client = new Client(
224+
`http://localhost:${server.address().port}`
225+
).compose(dump({ maxSize: 512 }))
226+
227+
after(async () => {
228+
await client.close()
229+
230+
server.close()
231+
await once(server, 'close')
232+
})
233+
234+
abc.abort()
235+
client.request(requestOptions).catch(err => {
236+
t.equal(err.name, 'AbortError')
237+
t.equal(err.message, 'This operation was aborted')
238+
})
239+
240+
await t.completed
241+
})
242+
202243
test('Should dump response body up to limit (default)', { skip }, async t => {
203244
t = tspl(t, { plan: 3 })
204245
const server = createServer({ joinDuplicateHeaders: true }, (req, res) => {

0 commit comments

Comments
 (0)