Skip to content

Commit f2f8cb2

Browse files
authoredOct 9, 2024··
Fix cache with HTTP2 (#2380)
1 parent 9ab4cf9 commit f2f8cb2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed
 

‎source/core/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1001,13 +1001,13 @@ export default class Request extends Duplex implements RequestEvents<Request> {
10011001
handler(error);
10021002
}
10031003
})();
1004-
} else if (event === 'abort') {
1004+
} else if (event === 'abort' || event === 'destroy') {
10051005
// The empty catch is needed here in case when
10061006
// it rejects before it's `await`ed in `_makeRequest`.
10071007
(async () => {
10081008
try {
10091009
const request = (await result) as ClientRequest;
1010-
request.once('abort', handler);
1010+
request.once(event, handler);
10111011
} catch {}
10121012
})();
10131013
} else {

‎test/cache.ts

+9
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ test('doesn\'t cache response when received HTTP error', withServer, async (t, s
179179
t.is(body, 'ok');
180180
});
181181

182+
test('cache should work with http2', async t => {
183+
const instance = got.extend({
184+
cache: true,
185+
http2: true,
186+
});
187+
188+
await t.notThrowsAsync(instance('https://example.com'));
189+
});
190+
182191
test('DNS cache works', async t => {
183192
const instance = got.extend({
184193
dnsCache: true,

0 commit comments

Comments
 (0)
Please sign in to comment.