diff --git a/dist/index.js b/dist/index.js index 68c70ee..446c81b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3977,8 +3977,11 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) { if (headers['transfer-encoding'] === 'chunked' && !headers['content-length']) { response.once('close', function (hadError) { + // tests for socket presence, as in some situations the + // the 'socket' event is not triggered for the request + // (happens in deno), avoids `TypeError` // if a data listener is still present we didn't end cleanly - const hasDataListener = socket.listenerCount('data') > 0; + const hasDataListener = socket && socket.listenerCount('data') > 0; if (hasDataListener && !hadError) { const err = new Error('Premature close');