Skip to content

Commit 9194e85

Browse files
author
Luca Forstner
committed
Add documentation
1 parent 0f312ce commit 9194e85

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed

packages/node/src/transports/new.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,31 @@ import {
77
} from '@sentry/core';
88
import { TransportRequestExecutor } from '@sentry/core/dist/transports/base';
99
import { eventStatusFromHttpCode } from '@sentry/utils';
10-
import * as fs from 'fs';
1110
import * as http from 'http';
1211
import * as https from 'https';
1312

1413
import { HTTPModule } from './base/http-module';
1514

16-
interface HttpTransportOptions extends BaseTransportOptions {
17-
// Todo: doc
18-
headers?: Record<string, string>;
19-
// TODO: doc Set a HTTP proxy that should be used for outbound requests.
20-
proxy?: string;
21-
// TODO: doc HTTPS proxy certificates path
22-
caCerts?: string;
23-
// Todo: doc
24-
httpModule?: HTTPModule;
25-
}
26-
2715
// TODO(v7):
2816
// - Rename this file "transports.ts"
2917
// - Move this file one folder upwards
3018
// - Delete "transports" folder
3119
// OR
3220
// - Split this file up and leave it in the transports folder
3321

22+
export interface HttpTransportOptions extends BaseTransportOptions {
23+
/** Define custom headers */
24+
headers?: Record<string, string>;
25+
/** Set a proxy that should be used for outbound requests. */
26+
proxy?: string;
27+
/** HTTPS proxy CA certificates */
28+
caCerts?: string | Buffer | Array<string | Buffer>;
29+
/** Custom HTTP module */
30+
httpModule?: HTTPModule;
31+
}
32+
3433
/**
35-
* TODO Doc
34+
* Creates a Transport that uses http to send events to Sentry.
3635
*/
3736
export function makeNewHttpTransport(options: HttpTransportOptions): NewTransport {
3837
// Proxy prioritization: http => `options.proxy` | `process.env.http_proxy`
@@ -49,7 +48,7 @@ export function makeNewHttpTransport(options: HttpTransportOptions): NewTranspor
4948
}
5049

5150
/**
52-
* TODO Doc
51+
* Creates a Transport that uses https to send events to Sentry.
5352
*/
5453
export function makeNewHttpsTransport(options: HttpTransportOptions): NewTransport {
5554
// Proxy prioritization: https => `options.proxy` | `process.env.https_proxy` | `process.env.http_proxy`
@@ -91,7 +90,7 @@ function applyNoProxyOption(transportUrl: string, proxy: string | undefined): st
9190
}
9291

9392
/**
94-
* TODO Doc
93+
* Creates a RequestExecutor to be used with `createTransport`.
9594
*/
9695
function createRequestExecutor(
9796
options: HttpTransportOptions,
@@ -111,7 +110,7 @@ function createRequestExecutor(
111110
pathname,
112111
port,
113112
protocol,
114-
ca: options.caCerts ? fs.readFileSync(options.caCerts) : undefined,
113+
ca: options.caCerts,
115114
},
116115
res => {
117116
res.on('data', () => {

packages/node/test/transports/new/https.test.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import { createEnvelope, serializeEnvelope } from '@sentry/utils';
44
import * as http from 'http';
55
import * as https from 'https';
66

7-
import {
8-
HTTPModule,
9-
HTTPModuleRequestIncomingMessage,
10-
HTTPModuleRequestOptions,
11-
} from '../../../src/transports/base/http-module';
7+
import { HTTPModule, HTTPModuleRequestIncomingMessage } from '../../../src/transports/base/http-module';
128
import { makeNewHttpsTransport } from '../../../src/transports/new';
139
import testServerCerts from './test-server-certs';
1410

@@ -75,11 +71,9 @@ const SERIALIZED_EVENT_ENVELOPE = serializeEnvelope(EVENT_ENVELOPE);
7571
const unsafeHttpsModule: HTTPModule = {
7672
request: jest
7773
.fn()
78-
.mockImplementation(
79-
(options: HTTPModuleRequestOptions, callback?: (res: HTTPModuleRequestIncomingMessage) => void) => {
80-
return https.request({ ...options, rejectUnauthorized: false }, callback);
81-
},
82-
),
74+
.mockImplementation((options: https.RequestOptions, callback?: (res: HTTPModuleRequestIncomingMessage) => void) => {
75+
return https.request({ ...options, rejectUnauthorized: false }, callback);
76+
}),
8377
};
8478

8579
describe('makeNewHttpsTransport()', () => {
@@ -174,6 +168,26 @@ describe('makeNewHttpsTransport()', () => {
174168

175169
expect(transportResponse).toEqual(expect.objectContaining({ status: 'success' }));
176170
});
171+
172+
it('should use `caCerts` option', async () => {
173+
await setupTestServer({ statusCode: SUCCESS });
174+
175+
const transport = makeNewHttpsTransport({
176+
httpModule: unsafeHttpsModule,
177+
url: TEST_SERVER_URL,
178+
caCerts: 'some cert',
179+
});
180+
181+
await transport.send(EVENT_ENVELOPE);
182+
183+
// eslint-disable-next-line @typescript-eslint/unbound-method
184+
expect(unsafeHttpsModule.request).toHaveBeenCalledWith(
185+
expect.objectContaining({
186+
ca: 'some cert',
187+
}),
188+
expect.anything(),
189+
);
190+
});
177191
});
178192

179193
describe('proxy', () => {

0 commit comments

Comments
 (0)