Skip to content

Commit

Permalink
Fix http/https issues with old no package so tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish committed Mar 7, 2024
1 parent bf052f6 commit 7c6fffd
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@types/cookie": "0.5.2",
"@types/express": "^4.17.14",
"@types/lru-cache": "^5.1.0",
"@types/node": "~10.17.0",
"@types/node": "14.18.63",
"express": "^4.17.1",
"nock": "^13.0.5",
"undici": "^5.21.0"
Expand Down
2 changes: 2 additions & 0 deletions packages/node/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ export function requestHandler(
if (options && options.flushTimeout && options.flushTimeout > 0) {
// eslint-disable-next-line @typescript-eslint/unbound-method
const _end = res.end;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore I've only updated the node types and this package will soon be removed
res.end = function (chunk?: any | (() => void), encoding?: string | (() => void), cb?: () => void): void {
void flush(options.flushTimeout)
.then(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/integrations/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class Http implements Integration {
// It has been changed in Node 9, so for all versions equal and above, we patch `https` separately.
if (NODE_VERSION.major > 8) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const httpsModule = require('https');
const httpsModule = require('node:https');
const wrappedHttpsHandlerMaker = _createWrappedRequestMethodFactory(
httpsModule,
this._breadcrumbs,
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/integrations/utils/errorhandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function logAndExitProcess(error: Error): void {
if (client === undefined) {
DEBUG_BUILD && logger.warn('No NodeClient was defined, we are exiting the process now.');
global.process.exit(1);
return;
}

const options = client.getOptions();
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/integrations/utils/http.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as http from 'http';
import type * as https from 'https';
import type * as http from 'node:http';
import type * as https from 'node:https';
import { URL } from 'url';

import { NODE_VERSION } from '../../nodeVersion';
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/proxy/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
*/

/* eslint-disable jsdoc/require-jsdoc */
import * as http from 'http';
import * as https from 'https';
import * as http from 'node:http';
import * as https from 'node:https';
import type { Readable } from 'stream';
// TODO (v8): Remove this when Node < 12 is no longer supported
import type { URL } from 'url';
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/transports/http.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as http from 'http';
import * as https from 'https';
import * as http from 'node:http';
import * as https from 'node:https';
import { Readable } from 'stream';
import { URL } from 'url';
import { createGzip } from 'zlib';
Expand Down
5 changes: 4 additions & 1 deletion packages/node/test/transports/http.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable deprecation/deprecation */
import * as http from 'http';

import { createGunzip } from 'zlib';
Expand Down Expand Up @@ -50,7 +51,9 @@ function setupTestServer(
res.end();

// also terminate socket because keepalive hangs connection a bit
res.connection.end();
if (res.connection) {
res.connection.end();
}
});

testServer.listen(18099);
Expand Down
5 changes: 4 additions & 1 deletion packages/node/test/transports/https.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable deprecation/deprecation */
import * as http from 'http';
import * as https from 'https';
import { createTransport } from '@sentry/core';
Expand Down Expand Up @@ -49,7 +50,9 @@ function setupTestServer(
res.end();

// also terminate socket because keepalive hangs connection a bit
res.connection.end();
if (res.connection) {
res.connection.end();
}
});

testServer.listen(8099);
Expand Down

0 comments on commit 7c6fffd

Please sign in to comment.