MCPcopy Index your code
hub / github.com/parse-community/parse-server / encodeBody

Function encodeBody

src/request.js:85–113  ·  view source on GitHub ↗
({ body, headers = {} })

Source from the content-addressed store, hash-verified

83}
84
85const 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
115function httpRequest(options) {
116 let url;

Callers 1

httpRequestFunction · 0.85

Calls 3

filterMethod · 0.80
matchMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected