Skip to content

Commit

Permalink
only populate the body on RequestInit options
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Apr 13, 2018
1 parent 3e33d4b commit 5ffb22c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
20 changes: 12 additions & 8 deletions src/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/index.js.map

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions src/index.ts
Expand Up @@ -852,23 +852,27 @@ export class JsonServiceClient {
this.headers.delete("Cookie");
}

// Set `compress` false due to common error
// https://github.com/bitinn/node-fetch/issues/93#issuecomment-200791658
var reqOptions = {
var hasRequestBody = HttpMethods.hasRequestBody(method);
var reqOptions:RequestInit = {
method: method,
mode: this.mode,
credentials: this.credentials,
headers: this.headers,
compress: false
};
const req = new Request(url, reqOptions);

if (HttpMethods.hasRequestBody(method)) {
(req as any).body = body || JSON.stringify(request);
// Set `compress` false due to common error
// https://github.com/bitinn/node-fetch/issues/93#issuecomment-200791658
try {
(reqOptions as any).compress = false;
} catch(e){}

if (hasRequestBody) {
reqOptions.body = body || JSON.stringify(request);
}
const req = new Request(url, reqOptions);

if (typeof window != "undefined" && body instanceof FormData) {
req.headers.delete('Content-Type'); //set by FormData
}
if (hasRequestBody && typeof window != "undefined" && body instanceof FormData) {
req.headers.delete('Content-Type'); //set by FormData
}

var opt:IRequestFilterOptions = { url };
Expand Down

1 comment on commit 5ffb22c

@olibanjoli
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mythz this commit looks like the fix for the body property that changed to readonly in Safari browser.

Unfortunately it ends in the following error: NotSupportedError: ReadableStream uploading is not supported when sending a request with body.

Please sign in to comment.