Skip to content

Commit

Permalink
match the style of this project
Browse files Browse the repository at this point in the history
  • Loading branch information
fffguo committed Jul 30, 2022
1 parent ea1134b commit c6b897e
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ function curlString(
return curl;
}

function getLowHeaders(headers) {
let lowHeaders = {}
Object.keys(headers).forEach(function (key) {
lowHeaders[key.toLowerCase()] = headers[key]
})
return lowHeaders
function getHeader(options, headerKeyName) {
// return header that matches case, but if not found fall back to header that does not match case
return options.headers[headerKeyName] || options.headers[Object.keys(options.headers).find(key => key.toLowerCase() === headerKeyName.toLowerCase())]
}

function hasHeader(options, headerKeyName) {
Expand All @@ -71,11 +68,10 @@ 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') &&
lowHeaders['content-type'].toLowerCase() === 'application/x-www-form-urlencoded') {
getHeader(options, 'content-type').toLowerCase() === 'application/x-www-form-urlencoded') {
if (typeof parsedData === 'string') {
return parsedData;
} else {
Expand Down

0 comments on commit c6b897e

Please sign in to comment.