Skip to content

Commit e97f615

Browse files
author
Ankit Saini
authored
Merge pull request #599 from postmanlabs/fix/xhr-misleading-code
Add warning comments before misleading code in JS-xhr
2 parents 2829cc5 + 3a09ca1 commit e97f615

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

codegens/js-xhr/lib/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ function parseHeaders (headers) {
150150
if (!_.isEmpty(headers)) {
151151
headers = _.reject(headers, 'disabled');
152152
_.forEach(headers, function (header) {
153+
if (_.capitalize(header.key) === 'Cookie') {
154+
headerSnippet += '// WARNING: Cookies will be stripped away by the browser before sending the request.\n';
155+
}
153156
headerSnippet += `xhr.setRequestHeader("${sanitize(header.key, true)}", "${sanitize(header.value)}");\n`;
154157
});
155158
}
@@ -263,6 +266,9 @@ function convert (request, options, callback) {
263266
bodySnippet = request.body && !_.isEmpty(request.body.toJSON()) ? parseBody(request.body.toJSON(), trim,
264267
indent, request.headers.get('Content-Type')) : '';
265268

269+
if (_.includes(['Get', 'Post'], _.capitalize(request.method))) {
270+
codeSnippet += `// WARNING: For ${request.method} requests, body is set to null by browsers.\n`;
271+
}
266272
codeSnippet += bodySnippet + '\n';
267273

268274
codeSnippet += 'var xhr = new XMLHttpRequest();\nxhr.withCredentials = true;\n\n';

0 commit comments

Comments
 (0)