Skip to content

Commit

Permalink
Use transfer encoding header (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
konraddysput authored May 8, 2024
1 parent 39e449a commit 9046b0b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/browser/src/BacktraceBrowserRequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ export class BacktraceBrowserRequestHandler implements BacktraceRequestHandler {
private readonly _timeout: number;
private readonly JSON_HEADERS = {
'Content-type': 'application/json',
'Transfer-Encoding': 'chunked',
};

private readonly MULTIPART_HEADERS = {
'Transfer-Encoding': 'chunked',
};
constructor(
private readonly _options: {
url: string;
Expand Down Expand Up @@ -45,7 +49,7 @@ export class BacktraceBrowserRequestHandler implements BacktraceRequestHandler {
const response = await fetch(submissionUrl, {
method: 'POST',
body: payload,
headers: typeof payload === 'string' ? this.JSON_HEADERS : {},
headers: typeof payload === 'string' ? this.JSON_HEADERS : this.MULTIPART_HEADERS,
signal: anySignal(abortSignal, controller.signal),
});

Expand Down
10 changes: 9 additions & 1 deletion packages/node/src/BacktraceNodeRequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export class BacktraceNodeRequestHandler implements BacktraceRequestHandler {

private readonly JSON_HEADERS = {
'Content-type': 'application/json',
'Transfer-Encoding': 'chunked',
};

private readonly MULTIPART_HEADERS = {
'Transfer-Encoding': 'chunked',
};

constructor(
Expand Down Expand Up @@ -63,7 +68,10 @@ export class BacktraceNodeRequestHandler implements BacktraceRequestHandler {
rejectUnauthorized: this._options.ignoreSslCertificate === true,
timeout: this._timeout,
method: 'POST',
headers: typeof payload === 'string' ? this.JSON_HEADERS : payload.getHeaders(),
headers:
typeof payload === 'string'
? this.JSON_HEADERS
: { ...payload.getHeaders(), ...this.MULTIPART_HEADERS },
},
(response) => {
let result = '';
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/src/ReactNativeRequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class ReactNativeRequestHandler implements BacktraceRequestHandler {
private readonly _timeout: number;
private readonly JSON_HEADERS = {
'Content-type': 'application/json',
'Transfer-Encoding': 'chunked',
};
private readonly MULTIPART_HEADERS = {
'Transfer-Encoding': 'chunked',
Expand Down

0 comments on commit 9046b0b

Please sign in to comment.