Skip to content
16 changes: 5 additions & 11 deletions codegens/http/lib/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let _ = require('./lodash'),
path = require('path');

const FORM_DATA_BOUNDARY = '----WebKitFormBoundary7MA4YWxkTrZu0gW',
const FORM_DATA_BOUNDARY = '--WebKitFormBoundary7MA4YWxkTrZu0gW',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saksham-postman It seems we have a reason to keep ---- here. Chrome dev tools uses ---- as starting sequence for boundary.

I think we should keep using ---- instead of just -- for better compatibility.

You can see this issue to see how the boundary can be seen in dev tools for reference. (postmanlabs/postman-app-support#11084).

RAW = 'raw',
GRAPHQL = 'graphql',
URL_ENCODED = 'urlencoded',
Expand Down Expand Up @@ -213,12 +213,11 @@ function getBody (request, trimRequestBody) {
return trimRequestBody ? requestBody.trim() : requestBody;

case FORM_DATA:
requestBody += `--${FORM_DATA_BOUNDARY}\n`;
/* istanbul ignore else */
if (!_.isEmpty(request.body[request.body.mode])) {
let properties = getMembersOfPropertyList(request.body[request.body.mode]),
numberOfProperties = properties.length;
_.forEach(properties, function (property, index) {
let properties = getMembersOfPropertyList(request.body[request.body.mode]);
_.forEach(properties, function (property) {
requestBody += `--${FORM_DATA_BOUNDARY}\n`;
/* istanbul ignore else */
if (property.type === 'text') {
requestBody += 'Content-Disposition: form-data; name="';
Expand All @@ -243,14 +242,9 @@ function getBody (request, trimRequestBody) {
}
requestBody += '(data)\n';
}
if (index === numberOfProperties - 1) {
requestBody += `--${FORM_DATA_BOUNDARY}--\n`;
}
else {
requestBody += `--${FORM_DATA_BOUNDARY}\n`;
}
});
}
requestBody += `--${FORM_DATA_BOUNDARY}--`;
return trimRequestBody ? requestBody.trim() : requestBody;

case FILE:
Expand Down
6 changes: 3 additions & 3 deletions codegens/http/test/resources/expected-http-messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"GET /headers HTTP/1.1\nHost: postman-echo.com\nmy-sample-header: Lorem ipsum dolor sit amet\nTEST: @#$%^&*()\nmore: ,./';[]}{\":?><|\\\\",
"GET /headers HTTP/1.1\nHost: postman-echo.com\nmy-sample-header: Lorem ipsum dolor sit amet\nnot-disabled-header: ENABLED",
"GET /get?test=123&anotherone=232 HTTP/1.1\nHost: postman-echo.com",
"POST /post HTTP/1.1\nHost: postman-echo.com\nContent-Length: 602\nContent-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW\n\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"pl\"\n\n'a'\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"qu\"\n\n\"b\"\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"hdjkljh\"\n\nc\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"sa\"\n\nd\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"Special\"\n\n!@#$%&*()^_+=`~ \n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"more\"\n\n,./';[]}{\":?><|\\\\\n------WebKitFormBoundary7MA4YWxkTrZu0gW--\n",
"POST /post HTTP/1.1\nHost: postman-echo.com\nContent-Length: 587\nContent-Type: multipart/form-data; boundary=--WebKitFormBoundary7MA4YWxkTrZu0gW\n\n----WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"pl\"\n\n'a'\n----WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"qu\"\n\n\"b\"\n----WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"hdjkljh\"\n\nc\n----WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"sa\"\n\nd\n----WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"Special\"\n\n!@#$%&*()^_+=`~ \n----WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"more\"\n\n,./';[]}{\":?><|\\\\\n----WebKitFormBoundary7MA4YWxkTrZu0gW--",
"POST /post?a=!@$^*()_-`%26&b=,./';[]}{\":/?><|| HTTP/1.1\nHost: postman-echo.com",
"POST /post HTTP/1.1\nHost: postman-echo.com\nContent-Type: application/x-www-form-urlencoded\nContent-Length: 284\n\nDuis posuere augue vel cursus pharetra. In luctus a ex nec pretium. Praesent neque quam, tincidunt nec leo eget, rutrum vehicula magna.\nMaecenas consequat elementum elit, id semper sem tristique et. Integer pulvinar enim quis consectetur interdum volutpat.!@#$%^&*()+POL:},'';,[;[;\n\n\n",
"POST /post HTTP/1.1\nHost: postman-echo.com\nContent-Type: application/x-www-form-urlencoded\nContent-Length: 147\n\n1='a'&2=%22b%22&'3'=c&%224%22=d&Special=!%40%23%24%25%26*()%5E_%3D%60~%20%20%20%20&more=%2C.%2F'%3B%5B%5D%7D%7B%22%3A%3F%3E%3C%7C%5C%5C%20%20%20%20",
Expand All @@ -25,14 +25,14 @@
"VIEW /request HTTP/1.1\nHost: postman-echo.com\nContent-Type: text/plain\nContent-Length: 256\n\nDuis posuere augue vel cursus pharetra. In luctus a ex nec pretium. Praesent neque quam, tincidunt nec leo eget, rutrum vehicula magna.\nMaecenas consequat elementum elit, id semper sem tristique et. Integer pulvinar enim quis consectetur interdum volutpat.",
"PURGE / HTTP/1.1\nHost: postman-echo.com",
"COPY / HTTP/1.1\nHost: postman-echo.com",
"POST /post HTTP/1.1\nHost: postman-echo.com\nContent-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Length: 180\n\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"file\"; filename=\"file.txt\"\nContent-Type: text/plain\n\n(data)\n------WebKitFormBoundary7MA4YWxkTrZu0gW--\n",
"POST /post HTTP/1.1\nHost: postman-echo.com\nContent-Type: multipart/form-data; boundary=--WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Length: 175\n\n----WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"file\"; filename=\"file.txt\"\nContent-Type: text/plain\n\n(data)\n----WebKitFormBoundary7MA4YWxkTrZu0gW--",
"POST /post HTTP/1.1\nHost: postman-echo.com\nContent-Type: text/plain\nContent-Length: 22\n\n\"<file contents here>\"",
"GET / HTTP/1.1\nHost: localhost:5050",
"GET /knockknock HTTP/1.1\nHost: localhost:5050"
],
"trimmedResult": [
"POST /post HTTP/1.1\nHost: postman-echo.com\nContent-Type: application/x-www-form-urlencoded\nContent-Length: 281\n\nDuis posuere augue vel cursus pharetra. In luctus a ex nec pretium. Praesent neque quam, tincidunt nec leo eget, rutrum vehicula magna.\nMaecenas consequat elementum elit, id semper sem tristique et. Integer pulvinar enim quis consectetur interdum volutpat.!@#$%^&*()+POL:},'';,[;[;",
"POST /post HTTP/1.1\nHost: postman-echo.com\nContent-Length: 597\nContent-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW\n\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"pl\"\n\n'a'\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"qu\"\n\n\"b\"\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"hdjkljh\"\n\nc\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"sa\"\n\nd\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"Special\"\n\n!@#$%&*()^_+=`~\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"more\"\n\n,./';[]}{\":?><|\\\\\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
"POST /post HTTP/1.1\nHost: postman-echo.com\nContent-Length: 583\nContent-Type: multipart/form-data; boundary=--WebKitFormBoundary7MA4YWxkTrZu0gW\n\n----WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"pl\"\n\n'a'\n----WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"qu\"\n\n\"b\"\n----WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"hdjkljh\"\n\nc\n----WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"sa\"\n\nd\n----WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"Special\"\n\n!@#$%&*()^_+=`~\n----WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"more\"\n\n,./';[]}{\":?><|\\\\\n----WebKitFormBoundary7MA4YWxkTrZu0gW--",
"POST /post HTTP/1.1\nHost: postman-echo.com\nContent-Type: application/x-www-form-urlencoded\nContent-Length: 123\n\n1='a'&2=%22b%22&'3'=c&%224%22=d&Special=!%40%23%24%25%26*()%5E_%3D%60~&more=%2C.%2F'%3B%5B%5D%7D%7B%22%3A%3F%3E%3C%7C%5C%5C"
]

Expand Down
2 changes: 1 addition & 1 deletion codegens/python-http.client/test/unit/converter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ describe('Python-http.client converter', function () {
});

it('should generate valid snippets when url uses http protocol', function () {
var request = new sdk.Request({
var request = new Request({
'method': 'GET',
'header': [],
'url': {
Expand Down
8 changes: 4 additions & 4 deletions test/codegen/newman/fixtures/formdataFileCollection.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
"key": "single file",
"value": "",
"type": "file",
"src": "/Users/vishalkumar.shingala@postman.com/pm/postman-code-generators/dummyFile1.txt"
"src": "/Users/saksham.gupta@postman.com/Desktop/postman/postman-code-generators/dummyFile1.txt"
},
{
"key": "multiple files",
"value": "",
"type": "file",
"src": [
"/Users/vishalkumar.shingala@postman.com/pm/postman-code-generators/dummyFile2.txt",
"/Users/vishalkumar.shingala@postman.com/pm/postman-code-generators/dummyFile3.txt"
"/Users/saksham.gupta@postman.com/Desktop/postman/postman-code-generators/dummyFile2.txt",
"/Users/saksham.gupta@postman.com/Desktop/postman/postman-code-generators/dummyFile3.txt"
]
}
]
Expand Down Expand Up @@ -55,7 +55,7 @@
"key": "binary file",
"value": "",
"type": "file",
"src": "/Users/vishalkumar.shingala@postman.com/pm/postman-code-generators/dummyBinaryFile"
"src": "/Users/saksham.gupta@postman.com/Desktop/postman/postman-code-generators/dummyBinaryFile"
}
]
},
Expand Down