Skip to content

Commit

Permalink
Merge pull request #130 from postmanlabs/bugfix/http-url-fix
Browse files Browse the repository at this point in the history
Added the parseUrlVariable function to resolve url variables in HTTP
  • Loading branch information
umeshp7 committed Nov 22, 2019
2 parents 9a810f8 + 9fb32f8 commit de09e99
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions codegens/http/lib/code-http-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function getOptions () {
function convert (request, options, callback) {
let snippet = '';
options = utils.sanitizeOptions(options, getOptions());
utils.parseURLVariable(request);
snippet = `${request.method} ${utils.getEndPoint(request)} HTTP/1.1\n`;
snippet += `Host: ${utils.getHost(request)}\n`;
if (request.body && !request.headers.has('Content-Type')) {
Expand Down
22 changes: 22 additions & 0 deletions codegens/http/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,27 @@ function convertPropertyListToString (propertyList, joinUsing, includeDisabled =
}), joinUsing);
}

/**
* parses variable of request url object and sets hostname, path and query in request object
*
* @param {Object} request - Postman SDK request object
*/
function parseURLVariable (request) {
const variableArray = _.get(request.toJSON(), 'url.variable', []);

if (!variableArray.length) {
return;
}

variableArray.forEach(function (variableArrayElement) {
request.url.path.forEach(function (pathArrayElement, pathArrayElementIndex) {
if (pathArrayElement === ':' + variableArrayElement.key) {
request.url.path[pathArrayElementIndex] = variableArrayElement.value;
}
});
});
}

/**
* Returns the request end-point as a string.
*
Expand Down Expand Up @@ -366,6 +387,7 @@ function addFormParam (array, key, type, val, disabled, contentType) {
}

module.exports = {
parseURLVariable: parseURLVariable,
getEndPoint: getEndPoint,
getHost: getHost,
getHeaders: getHeaders,
Expand Down
4 changes: 2 additions & 2 deletions codegens/http/test/resources/expected-http-messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"GET /headers HTTP/1.1\nHost: postman-echo.com\nmy-sample-header: Lorem ipsum dolor sit amet\nnot-disabled-header: ENABLED\n\n",
"GET /get?test=123&anotherone=232 HTTP/1.1\nHost: postman-echo.com\n\n\n",
"POST /post HTTP/1.1\nHost: postman-echo.com\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 /:action?a=!@$^*()_-`%26&b=,./';[]}{\":/?><|| HTTP/1.1\nHost: postman-echo.com\n\n\n",
"POST /post?a=!@$^*()_-`%26&b=,./';[]}{\":/?><|| HTTP/1.1\nHost: postman-echo.com\n\n\n",
"POST /post HTTP/1.1\nHost: postman-echo.com\nContent-Type: application/x-www-form-urlencoded\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\n\n1='a'&2=\"b\"&'3'=c&\"4\"=d&Special=!@#$%&*()^_=`~ &more=,./';[]}{\":?><|\\\\ ",
"POST /post HTTP/1.1\nHost: postman-echo.com\nContent-Type: application/json\n\n{\n \"json\": \"Test-Test!@#$%^&*()+POL:},'';,[;[;:>\"\n}",
"POST /post HTTP/1.1\nHost: postman-echo.com\nContent-Type: application/javascript\n\nvar val = 6;\nconsole.log(val);",
"POST /post HTTP/1.1\nHost: postman-echo.com\nContent-Type: text/xml\n\n<xml>\n\tTest Test!@#$%^&*()+POL:},'';,[;[;\n</xml>",
"POST /post HTTP/1.1\nHost: postman-echo.com\nContent-Type: text/html\n\n<html>\n Test Test !@#$%^&*()+POL:},'';,[;[;\n</html>",
"POST /:action?a=''&b=\"\" HTTP/1.1\nHost: postman-echo.com\n\n\n",
"POST /post?a=''&b=\"\" HTTP/1.1\nHost: postman-echo.com\n\n\n",
"PUT /put HTTP/1.1\nHost: postman-echo.com\nContent-Type: text/plain\n\nEtiam mi lacus, cursus vitae felis et, blandit pellentesque neque. Vestibulum eget nisi a tortor commodo dignissim.\nQuisque ipsum ligula, faucibus a felis a, commodo elementum nisl. Mauris vulputate sapien et tincidunt viverra. Donec vitae velit nec metus.",
"PATCH /patch HTTP/1.1\nHost: postman-echo.com\nContent-Type: text/plain\n\nCurabitur auctor, elit nec pulvinar porttitor, ex augue condimentum enim, eget suscipit urna felis quis neque.\nSuspendisse sit amet luctus massa, nec venenatis mi. Suspendisse tincidunt massa at nibh efficitur fringilla. Nam quis congue mi. Etiam volutpat.",
"DELETE /delete HTTP/1.1\nHost: postman-echo.com\nContent-Type: text/plain\n\nDonec fermentum, nisi sed cursus eleifend, nulla tortor ultricies tellus, ut vehicula orci arcu ut velit. In volutpat egestas dapibus.\nMorbi condimentum vestibulum sapien. Etiam dignissim diam quis eros lobortis gravida vel lobortis est. Etiam gravida sed.",
Expand Down

0 comments on commit de09e99

Please sign in to comment.