Skip to content

Commit

Permalink
Revert "Represent non-stringified JSON request body as an [object Obj…
Browse files Browse the repository at this point in the history
…ect] string"

This reverts commit 5c6b055.
  • Loading branch information
JakeChampion committed Feb 27, 2021
1 parent 90fb680 commit e42f201
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,20 +246,14 @@ function Body() {
this._bodyText = body = Object.prototype.toString.call(body)
}

var contentType = this.headers.get('content-type')

if (!contentType) {
if (!this.headers.get('content-type')) {
if (typeof body === 'string') {
this.headers.set('content-type', 'text/plain;charset=UTF-8')
} else if (this._bodyBlob && this._bodyBlob.type) {
this.headers.set('content-type', this._bodyBlob.type)
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8')
}
} else if (contentType.indexOf('json') >= 0 && typeof this._bodyInit !== 'string') {
// Always pass a text representation of a non-stringified JSON body
// to `XMLHttpRequest.send` to retain a compatible behavior with the browser.
this._bodyInit = this._bodyText
}
}

Expand Down

5 comments on commit e42f201

@tomalexhughes
Copy link

@tomalexhughes tomalexhughes commented on e42f201 Apr 16, 2021

Choose a reason for hiding this comment

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

@JakeChampion Is it possible to re-introduce this code as it solves the issue in #856. Happy to make a new PR with this code refactored if it introduced a regression elsewhere?

@kettanaito
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be useful to learn why this was reverted, so we can come up with the proper solution. Thank you for your time with this!

@JakeChampion
Copy link
Owner Author

Choose a reason for hiding this comment

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

The reversion was to fix these reported issues -- #923 #922 #918

@kettanaito
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the clarification, @JakeChampion! Please, can we collaborate to still provide the fix but account for all the areas it previously broke?

@JakeChampion
Copy link
Owner Author

Choose a reason for hiding this comment

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

I don't have time to work on it myself, I'm happy to review a pull-request which does that 👍

Please sign in to comment.