({ body, headers = {} })
| 83 | } |
| 84 | |
| 85 | const encodeBody = function ({ body, headers = {} }) { |
| 86 | if (typeof body !== 'object') { |
| 87 | return { body, headers }; |
| 88 | } |
| 89 | var contentTypeKeys = Object.keys(headers).filter(key => { |
| 90 | return key.match(/content-type/i) != null; |
| 91 | }); |
| 92 | |
| 93 | if (contentTypeKeys.length == 0) { |
| 94 | // no content type |
| 95 | // As per https://parse.com/docs/cloudcode/guide#cloud-code-advanced-sending-a-post-request the default encoding is supposedly x-www-form-urlencoded |
| 96 | |
| 97 | body = querystring.stringify(body); |
| 98 | headers['Content-Type'] = 'application/x-www-form-urlencoded'; |
| 99 | } else { |
| 100 | /* istanbul ignore next */ |
| 101 | if (contentTypeKeys.length > 1) { |
| 102 | log.error('Parse.Cloud.httpRequest', 'multiple content-type headers are set.'); |
| 103 | } |
| 104 | // There maybe many, we'll just take the 1st one |
| 105 | var contentType = contentTypeKeys[0]; |
| 106 | if (headers[contentType].match(/application\/json/i)) { |
| 107 | body = JSON.stringify(body); |
| 108 | } else if (headers[contentType].match(/application\/x-www-form-urlencoded/i)) { |
| 109 | body = querystring.stringify(body); |
| 110 | } |
| 111 | } |
| 112 | return { body, headers }; |
| 113 | }; |
| 114 | |
| 115 | function httpRequest(options) { |
| 116 | let url; |
no test coverage detected