Skip to content

Commit

Permalink
fix Content-Type bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fffguo committed Jul 29, 2022
1 parent d36989f commit ea1134b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ function curlString(
return curl;
}

function getHeader(options, headerKeyName) {
return options.headers[headerKeyName];
function getLowHeaders(headers) {
let lowHeaders = {}
Object.keys(headers).forEach(function (key) {
lowHeaders[key.toLowerCase()] = headers[key]
})
return lowHeaders
}

function hasHeader(options, headerKeyName) {
Expand All @@ -67,10 +71,11 @@ function bodyToDataString(options, curlStringOptions) {
// fall back to original body if it could not be parsed as JSON
parsedData = options.body;
}
const lowHeaders = getLowHeaders(options.headers)

// return an ampersand delimited string
if (hasHeader(options, 'content-type') &&
getHeader(options, 'content-type').toLowerCase() === 'application/x-www-form-urlencoded') {
lowHeaders['content-type'].toLowerCase() === 'application/x-www-form-urlencoded') {
if (typeof parsedData === 'string') {
return parsedData;
} else {
Expand Down

0 comments on commit ea1134b

Please sign in to comment.