Open apm963 opened 5 years ago
Here is an example of how this would be implemented:
index.js
module.exports = () => {
let unsanitizedCmdArgs = process.argv.slice(2);
const unsanitizedArgs = minimist(unsanitizedCmdArgs);
if (
!('H' in unsanitizedArgs)
|| (typeof unsanitizedArgs.H === 'object' && 'length' in unsanitizedArgs.H ? unsanitizedArgs.H : [unsanitizedArgs.H])
.filter(s => /Accept:\s*application\/json/i.test(s)).length === 0
) {
unsanitizedCmdArgs = [
'-H',
'Accept: application/json',
...unsanitizedCmdArgs
];
}
const cmdArgs = sanitizeCurlArgs(unsanitizedCmdArgs);
const args = minimist(cmdArgs);
unsanitizedArgs.H
can be either undefined (if no -H
arg used), a string (if only one -H
arg is used) or an array (if more than one -H
arg is used). This is the reason for the complexity of the condition.
Currently the
Accept
header is not set by default, which is fine by itself. However, most ofcurlx
expects the response to be in JSON format. I think it would be beneficial to set theAccept
header toapplication/json
by default and allow users to change or unset it.Alternately, this could be a toggleable / configurable setting.