Skip to content

Instantly share code, notes, and snippets.

@valer-cara
Last active August 29, 2015 14:24
Show Gist options
  • Save valer-cara/a4151f7ff38ac3490a90 to your computer and use it in GitHub Desktop.
Save valer-cara/a4151f7ff38ac3490a90 to your computer and use it in GitHub Desktop.
har2curl
#!/usr/bin/env node
var fs = require('fs');
var har = JSON.parse(fs.readFileSync(process.argv[2])),
cmds;
cmds = har.log.entries.map(function(entry) {
var cmd = [];
cmd.push("curl '" + entry.request.url + "'");
cmd = cmd.concat(
entry.request.headers
.sort(function(a, b) {
if(a.name > b.name) return 1;
else if(a.name < b.name) return -1;
else return 0;
})
.map(function(header) {
return "-H '" + header.name.replace(':', '') + ":" + header.value + "'";
})
);
cmd.push('--compressed');
return cmd.join(' ');
});
console.log(cmds.join("\n"));
#!/usr/bin/env fish
## Test if a page's assets are accessible via a proxy (main use case: China)
#
# Proxy-fetch from: https://github.com/valer-cara/proxy-fetch
#
# $ set proxy (proxy-fetch)
# $ ./tester.fish -I -s -x $proxy
# $ env GREP=maps ./tester.fish -I -s -x $proxy
set FILE /tmp/chrome-dump.har
#set HTTP_ONLY 1
#set GREP maps
#set GREPV png
har2curl.js $FILE |\
if test $GREP; grep $GREP; else; cat; end |\
if test $GREPV; grep -v $GREPV; else; cat; end |\
while read cmd
if test $HTTP_ONLY
set cmd (echo $cmd | sed -e 's/https/http/')
end
set cmd "$cmd $argv"
echo $cmd
echo (read -p 'echo -e \n[Hit Enter to curl / ^C to exit] ')
eval $cmd
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment