Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Represent non-stringified JSON request body as an [object Object] string
- Loading branch information
1 parent
b5c8bd0
commit 5c6b055
Showing
1 changed file
with
7 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,14 +246,20 @@ function Body() { | |
this._bodyText = body = Object.prototype.toString.call(body) | ||
} | ||
|
||
if (!this.headers.get('content-type')) { | ||
const contentType = this.headers.get('content-type') | ||
|
||
if (!contentType) { | ||
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.includes('json') && 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 | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
hans2520
|
||
} | ||
} | ||
|
||
|
2 comments
on commit 5c6b055
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Taranehpasha can you explain why you posted those links?
This line is causing empty body to be sent on POST in Electron 80 (https://www.electronjs.org/) used by Cypress 4.
Commenting this line out fixes things, another approach that works is to store the original body before the conditional branches, and assign that here, instead of the
this._bodyText
that has been modified by the branches. I tested that as well and it works.