httpsnippet
Advanced tools
Comparing version 1.0.0-beta.5 to 1.0.0-beta.6
{ | ||
"version": "1.0.0-beta.5", | ||
"version": "1.0.0-beta.6", | ||
"name": "httpsnippet", | ||
@@ -4,0 +4,0 @@ "description": "HTTP Request snippet generator for *most* languages", |
@@ -21,20 +21,18 @@ 'use strict'; | ||
// construct headers | ||
this.source.headers.map(function (header) { | ||
code.push(util.format('%s "%s: %s"', opts.short ? '-H' : '--header', header.name, header.value)); | ||
}); | ||
// construct cookies | ||
if (this.source.cookies && this.source.cookies.length) { | ||
var cookies = this.source.cookies.map(function (cookie) { | ||
return encodeURIComponent(cookie.name) + '=' + encodeURIComponent(cookie.value); | ||
}); | ||
var cookies = this.source.cookies.map(function (cookie) { | ||
return encodeURIComponent(cookie.name) + '=' + encodeURIComponent(cookie.value); | ||
}); | ||
if (cookies.length) { | ||
code.push(util.format('%s "%s"', opts.short ? '-b' : '--cookie', cookies.join('; '))); | ||
} | ||
// construct headers | ||
if (this.source.headers && this.source.headers.length) { | ||
this.source.headers.map(function (header) { | ||
code.push(util.format('%s "%s: %s"', opts.short ? '-H' : '--header', header.name, header.value)); | ||
}); | ||
} | ||
// request body | ||
if (this.source.postData && this.source.postData.text) { | ||
if (this.source.postData.text) { | ||
code.push(util.format('%s %s', opts.short ? '-F' : '--form', JSON.stringify(this.source.postData.text))); | ||
@@ -44,3 +42,3 @@ } | ||
// construct post params | ||
if (this.source.postData && !this.source.postData.text && this.source.postData.params && this.source.postData.params.length) { | ||
if (!this.source.postData.text && this.source.postData.params && this.source.postData.params.length) { | ||
this.source.postData.params.map(function (param) { | ||
@@ -47,0 +45,0 @@ code.push(util.format('%s "%s=%s"', opts.short ? '-d' : '--data', param.name, param.value)); |
@@ -71,24 +71,15 @@ 'use strict'; | ||
// construct query params | ||
if (opts.queryParams && this.source.queryString) { | ||
if (opts.queryParams) { | ||
var queryStringKeys = Object.keys(this.source.queryString); | ||
if (queryStringKeys.length) { | ||
queryStringKeys.map(function (name) { | ||
var value = self.source.queryString[name]; | ||
queryStringKeys.map(function (name) { | ||
var value = self.source.queryString[name]; | ||
if (util.isArray(value)) { | ||
value.map(function (val) { | ||
code.push(util.format('%s==%s', name, val)); | ||
}); | ||
} else { | ||
code.push(util.format('%s==%s', name, value)); | ||
} | ||
}); | ||
} | ||
} | ||
// construct post params | ||
if (this.source.postData && !this.source.postData.text && this.source.postData.params && this.source.postData.params.length) { | ||
this.source.postData.params.map(function (param) { | ||
code.push(util.format('%s:%s', param.name, param.value)); | ||
if (util.isArray(value)) { | ||
value.map(function (val) { | ||
code.push(util.format('%s==%s', name, val)); | ||
}); | ||
} else { | ||
code.push(util.format('%s==%s', name, value)); | ||
} | ||
}); | ||
@@ -98,17 +89,22 @@ } | ||
// construct headers | ||
if (this.source.headers && this.source.headers.length) { | ||
this.source.headers.map(function (header) { | ||
code.push(util.format('%s:%s', header.name, header.value)); | ||
}); | ||
} | ||
this.source.headers.map(function (header) { | ||
code.push(util.format('%s:%s', header.name, header.value)); | ||
}); | ||
// construct cookies argument | ||
if (this.source.cookies && this.source.cookies.length) { | ||
var cookies = this.source.cookies.map(function (cookie) { | ||
return encodeURIComponent(cookie.name) + '=' + encodeURIComponent(cookie.value); | ||
}); | ||
var cookies = this.source.cookies.map(function (cookie) { | ||
return encodeURIComponent(cookie.name) + '=' + encodeURIComponent(cookie.value); | ||
}); | ||
if (cookies.length) { | ||
code.push(util.format('Cookie:%s', cookies.join('; '))); | ||
} | ||
// construct post params | ||
if (!this.source.postData.text && this.source.postData.params && this.source.postData.params.length) { | ||
this.source.postData.params.map(function (param) { | ||
code.push(util.format('%s:%s', param.name, param.value)); | ||
}); | ||
} | ||
return code.join(opts.indent !== false ? ' \\\n' + opts.indent : ' '); | ||
@@ -115,0 +111,0 @@ }; |
@@ -21,7 +21,7 @@ 'use strict'; | ||
// construct cookies argument | ||
if (this.source.cookies && this.source.cookies.length) { | ||
var cookies = this.source.cookies.map(function (cookie) { | ||
return encodeURIComponent(cookie.name) + '=' + encodeURIComponent(cookie.value); | ||
}); | ||
var cookies = this.source.cookies.map(function (cookie) { | ||
return encodeURIComponent(cookie.name) + '=' + encodeURIComponent(cookie.value); | ||
}); | ||
if (cookies.length) { | ||
reqOpts.headers.Cookie = cookies.join('; '); | ||
@@ -28,0 +28,0 @@ } |
@@ -73,7 +73,7 @@ 'use strict'; | ||
// construct cookies | ||
if (this.source.cookies && this.source.cookies.length) { | ||
var cookies = this.source.cookies.map(function (cookie) { | ||
return encodeURIComponent(cookie.name) + '=' + encodeURIComponent(cookie.value); | ||
}); | ||
var cookies = this.source.cookies.map(function (cookie) { | ||
return encodeURIComponent(cookie.name) + '=' + encodeURIComponent(cookie.value); | ||
}); | ||
if (cookies.length) { | ||
curlopts.push(util.format('CURLOPT_COOKIE => "%s",', cookies.join('; '))); | ||
@@ -83,7 +83,7 @@ } | ||
// construct cookies | ||
if (this.source.headers && this.source.headers.length) { | ||
var headers = this.source.headers.map(function (header) { | ||
return util.format('"%s: %s"', header.name, header.value); | ||
}); | ||
var headers = this.source.headers.map(function (header) { | ||
return util.format('"%s: %s"', header.name, header.value); | ||
}); | ||
if (headers.length) { | ||
curlopts.push(util.format('CURLOPT_HTTPHEADER => array(\n%s%s%s\n%s),', opts.indent, opts.indent, headers.join(',\n' + opts.indent + opts.indent), opts.indent)); | ||
@@ -90,0 +90,0 @@ } |
@@ -23,15 +23,13 @@ 'use strict'; | ||
// construct cookies argument | ||
if (this.source.cookies && this.source.cookies.length) { | ||
var cookies = this.source.cookies.map(function (cookie) { | ||
return encodeURIComponent(cookie.name) + '=' + encodeURIComponent(cookie.value); | ||
}); | ||
var cookies = this.source.cookies.map(function (cookie) { | ||
return encodeURIComponent(cookie.name) + '=' + encodeURIComponent(cookie.value); | ||
}); | ||
if (cookies.length) { | ||
code.push(util.format('--header "Cookie: %s"', cookies.join('; '))); | ||
} | ||
if (this.source.headers && this.source.headers.length) { | ||
this.source.headers.map(function (header) { | ||
code.push(util.format('--header "%s: %s"', header.name, header.value)); | ||
}); | ||
} | ||
this.source.headers.map(function (header) { | ||
code.push(util.format('--header "%s: %s"', header.name, header.value)); | ||
}); | ||
@@ -38,0 +36,0 @@ if (this.source.postData) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60
2
2
2
7
34634
52683
16
510