Skip to content

Commit 2d1497e

Browse files
authored
Destroy request object after successful response (#2187)
1 parent 5e17bb7 commit 2d1497e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

source/as-promise/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export default function asPromise<T>(normalizedOptions: NormalizedOptions): Canc
131131
return;
132132
}
133133

134+
request.destroy();
134135
resolve(request.options.resolveBodyOnly ? response.body as T : response as unknown as T);
135136
});
136137

test/promise.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,14 @@ test('promise.json() does not fail when server returns an error and throwHttpErr
9595
const promise = got('', {throwHttpErrors: false});
9696
await t.notThrowsAsync(promise.json());
9797
});
98+
99+
test('the request is destroyed once the promise has resolved', withServer, async (t, server, got) => {
100+
server.get('/', (_request, response) => {
101+
response.statusCode = 200;
102+
response.end('null');
103+
});
104+
105+
const {request} = await got('');
106+
107+
t.true(request.destroyed);
108+
});

0 commit comments

Comments
 (0)