Skip to content

Commit 9c525ff

Browse files
HazATrhcarvalho
andauthored
fix: Send headers for node (#2637)
* fix: Send headers for node * fix: Don't send qs for node * fix: Node tests Co-authored-by: Rodolfo Carvalho <[email protected]>
1 parent e02a4c7 commit 9c525ff

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
66
- [react] feat: Add @sentry/react package (#2631)
77

8+
## 5.16.1
9+
10+
- [node] fix: Requests to old `/store` endpoint need the `x-sentry-auth` header in node (#2637)
11+
812
## 5.16.0
913

1014
*If you are a `@sentry/apm` and did manual instrumentation using `hub.startSpan` please be aware of the changes we did

packages/core/src/api.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ export class API {
8080

8181
/**
8282
* Returns an object that can be used in request headers.
83-
*
84-
* @deprecated in favor of `getStoreEndpointWithUrlEncodedAuth` and `getEnvelopeEndpointWithUrlEncodedAuth`.
83+
* This is needed for node and the old /store endpoint in sentry
8584
*/
8685
public getRequestHeaders(clientName: string, clientVersion: string): { [key: string]: string } {
8786
const dsn = this._dsnObject;

packages/node/src/transports/base.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as http from 'http';
66
import * as https from 'https';
77
import * as url from 'url';
88

9-
// import { SDK_NAME, SDK_VERSION } from '../version';
9+
import { SDK_NAME, SDK_VERSION } from '../version';
1010

1111
/**
1212
* Internal used interface for typescript.
@@ -59,14 +59,13 @@ export abstract class BaseTransport implements Transport {
5959
/** Returns a build request option object used by request */
6060
protected _getRequestOptions(uri: url.URL): http.RequestOptions | https.RequestOptions {
6161
const headers = {
62-
// The auth headers are not included because auth is done via query string to match @sentry/browser.
63-
//
64-
// ...this._api.getRequestHeaders(SDK_NAME, SDK_VERSION)
62+
...this._api.getRequestHeaders(SDK_NAME, SDK_VERSION),
6563
...this.options.headers,
6664
};
67-
const { hostname, pathname, port, protocol, search } = uri;
65+
const { hostname, pathname, port, protocol } = uri;
6866
// See https://github.com/nodejs/node/blob/38146e717fed2fabe3aacb6540d839475e0ce1c6/lib/internal/url.js#L1268-L1290
69-
const path = `${pathname}${search}`;
67+
// We ignore the query string on purpose
68+
const path = `${pathname}`;
7069

7170
return {
7271
agent: this.client,

packages/node/test/transports/http.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { HTTPTransport } from '../../src/transports/http';
66

77
const mockSetEncoding = jest.fn();
88
const dsn = 'http://[email protected]:8989/mysubpath/50622';
9-
const transportPath = '/mysubpath/api/50622/store/?sentry_key=9e9fd4523d784609a5fc0ebb1080592f&sentry_version=7';
9+
const transportPath = '/mysubpath/api/50622/store/';
1010
let mockReturnCode = 200;
1111
let mockHeaders = {};
1212

@@ -28,7 +28,7 @@ function createTransport(options: TransportOptions): HTTPTransport {
2828
}
2929

3030
function assertBasicOptions(options: any): void {
31-
expect(options.headers).not.toContain('X-Sentry-Auth'); // auth is part of the query string
31+
expect(options.headers['X-Sentry-Auth']).toBeTruthy();
3232
expect(options.port).toEqual('8989');
3333
expect(options.path).toEqual(transportPath);
3434
expect(options.hostname).toEqual('sentry.io');

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { HTTPSTransport } from '../../src/transports/https';
66

77
const mockSetEncoding = jest.fn();
88
const dsn = 'https://[email protected]:8989/mysubpath/50622';
9-
const transportPath = '/mysubpath/api/50622/store/?sentry_key=9e9fd4523d784609a5fc0ebb1080592f&sentry_version=7';
9+
const transportPath = '/mysubpath/api/50622/store/';
1010
let mockReturnCode = 200;
1111
let mockHeaders = {};
1212

@@ -34,7 +34,7 @@ function createTransport(options: TransportOptions): HTTPSTransport {
3434
}
3535

3636
function assertBasicOptions(options: any): void {
37-
expect(options.headers).not.toContain('X-Sentry-Auth'); // auth is part of the query string
37+
expect(options.headers['X-Sentry-Auth']).toBeTruthy();
3838
expect(options.port).toEqual('8989');
3939
expect(options.path).toEqual(transportPath);
4040
expect(options.hostname).toEqual('sentry.io');

0 commit comments

Comments
 (0)