Skip to content

Commit f0ac859

Browse files
authored
Fixed incorrect adding of content-type json
Seems like I had some kind of brain lag when I wrote that, not Sure why I did that, but its fixed now.
1 parent 0c7f82a commit f0ac859

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

index.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,13 @@ class Scrappey {
378378

379379
// If Users forget to give that content-type but data is json, it will be added automatically.
380380
if (this.isJSON(options.postData)) {
381-
let jsonpostData = JSON.parse(options.postData)
382-
383-
if (!Object.keys(jsonpostData).map(key => key.toLowerCase()).includes("content-type")) {
384-
options.postData = JSON.stringify({ ...jsonpostData, "content-type": "application/json" })
381+
let headerKeys = Object.keys(options?.customHeaders || {});
382+
if (typeof options?.customHeaders === "undefined" || headerKeys.length === 0) {
383+
options.customHeaders = { "content-type": "application/json" };
384+
} else if (
385+
typeof options.customHeaders === "object" &&
386+
!headerKeys.map(key => key.toLowerCase()).includes("content-type")) {
387+
options.customHeaders = { ...options.customHeaders, "content-type": "application/json" };
385388
}
386389
}
387390

0 commit comments

Comments
 (0)