mirror of
https://github.com/remy/inliner.git
synced 2024-08-16 20:00:35 +03:00
fix: header cli parsing
This commit is contained in:
parent
253a3173cd
commit
e61f7bd783
@ -59,7 +59,6 @@ function main() {
|
||||
if (argv.debug) {
|
||||
console.error(error.stack);
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ function options(args) {
|
||||
|
||||
argv.useStdin = !process.stdin.isTTY;
|
||||
|
||||
argv.verbose = !process.stdout.isTTY;
|
||||
argv.verbose = argv.verbose || !process.stdout.isTTY;
|
||||
|
||||
return argv;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ module.exports = function get(url, options) {
|
||||
|
||||
debug('request %s', url, settings);
|
||||
|
||||
cache[url] = new Promise(function promise(resolve, reject) {
|
||||
cache[url] = new Promise(function (resolve, reject) {
|
||||
request(url, settings, function response(error, res, body) {
|
||||
if (error) {
|
||||
debug('request failed: %s', error.message);
|
||||
|
17
lib/index.js
17
lib/index.js
@ -74,10 +74,25 @@ function Inliner(source, options, callback) {
|
||||
delete options.header;
|
||||
}
|
||||
|
||||
if (options.headers && !Array.isArray(options.headers)) {
|
||||
if (!Array.isArray(options.headers)) {
|
||||
options.headers = [options.headers];
|
||||
}
|
||||
|
||||
if (options.headers && Array.isArray(options.headers)) {
|
||||
options.headers = options.headers.reduce(function (acc, curr) {
|
||||
if (typeof curr === 'string') {
|
||||
var parts = curr.split(':').map(function (s) {
|
||||
return s.trim();
|
||||
});
|
||||
acc[parts[0]] = parts[1];
|
||||
} else {
|
||||
var key = Object.keys(curr);
|
||||
acc[key] = curr[key];
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
if (options.headers && typeof options.headers[0] === 'string') {
|
||||
// convert to an object of key/value pairs
|
||||
options.headers = options.headers.reduce(function (acc, curr) {
|
||||
|
Loading…
Reference in New Issue
Block a user