Skip to content
Permalink
Browse files

Revert "Represent non-stringified JSON request body as an [object Obj…

…ect] string"

This reverts commit 5c6b055.
  • Loading branch information
JakeChampion committed Feb 27, 2021
1 parent 90fb680 commit e42f201b8b0af8b3f2615abe8161c8087f52f1b2
Showing with 1 addition and 7 deletions.
  1. +1 −7 fetch.js
@@ -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
}
}

0 comments on commit e42f201

Please sign in to comment.