Skip to content

Instantly share code, notes, and snippets.

@bobpace
Last active August 29, 2015 14:17
Show Gist options
  • Save bobpace/8bb1843363f654f74953 to your computer and use it in GitHub Desktop.
Save bobpace/8bb1843363f654f74953 to your computer and use it in GitHub Desktop.
Koa.js curl proxy with ntlm authentication
var spawn = require('child_process').spawn;
var eventStream = require('./event-stream');
var compose = require('koa-compose');
//get username / password from somewhere
var username = ...;
var password = ...;
var credential = username + ':' + password;
//8 hour timeout
var timeout = 8 * 60 * 60;
module.exports = function curlProxy(url) {
return compose([
eventStream(),
function *() {
var child = spawn('curl', ['--ntlm', '-u', credential, '-N', '-m', timeout.toString(), url], {
//ignore stdio and stderr so they don't fill up and cause stdout to pause
stdio: ['ignore', 'pipe', 'ignore']
});
this.body = child.stdout;
}
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment