Created
April 6, 2012 18:02
-
-
Save coderarity/2321679 to your computer and use it in GitHub Desktop.
this is very broken and i'm not sure why
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var path = require('path'), | |
spawn = require('child_process').spawn, | |
http = require('http'); | |
var PORT = 8080; | |
var PROXY_PORT = 8090; | |
var test = process.argv[2]; | |
if (!test) { | |
return console.error('Need test to run'); | |
} | |
console.log('Running test ' + test); | |
var proxyserver = http.createServer(function (req, res) { | |
var self = this, | |
outgoing = {}, | |
reverseProxy; | |
outgoing.host = 'localhost'; | |
outgoing.port = PORT; | |
outgoing.method = req.method; | |
outgoing.path = req.url; | |
outgoing.headers = req.headers; | |
reverseProxy = http.request(outgoing, function (response) { | |
res.writeHead(response.statusCode, response.headers); | |
response.pipe(res); | |
}); | |
req.pipe(reverseProxy); | |
}); | |
proxyserver.listen(PROXY_PORT); | |
proxyserver.on('listening', function () { | |
console.log('Proxy server listening on ' + PROXY_PORT); | |
var testProcess = spawn(process.argv[0], [ process.argv[2] ]); | |
testProcess.stdout.pipe(process.stdout); | |
testProcess.stderr.pipe(process.stderr); | |
testProcess.on('exit', process.exit); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright Joyent, Inc. and other Node contributors. | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a | |
// copy of this software and associated documentation files (the | |
// "Software"), to deal in the Software without restriction, including | |
// without limitation the rights to use, copy, modify, merge, publish, | |
// distribute, sublicense, and/or sell copies of the Software, and to permit | |
// persons to whom the Software is furnished to do so, subject to the | |
// following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included | |
// in all copies or substantial portions of the Software. | |
// | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | |
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | |
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | |
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | |
// USE OR OTHER DEALINGS IN THE SOFTWARE. | |
var assert = require('assert'); | |
var net = require('net'); | |
var http = require('http'); | |
var url = require('url'); | |
var PORT = 8080; | |
var PROXY_PORT = 8090; | |
// Make sure no exceptions are thrown when receiving malformed HTTP | |
// requests. | |
var nrequests_completed = 0; | |
var nrequests_expected = 1; | |
var server = http.createServer(function(req, res) { | |
console.log('req: ' + JSON.stringify(url.parse(req.url))); | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.write('Hello World'); | |
res.end(); | |
if (++nrequests_completed == nrequests_expected) server.close(); | |
}); | |
server.listen(PORT); | |
server.on('listening', function() { | |
var c = net.createConnection(PROXY_PORT); | |
c.on('connect', function() { | |
c.write('GET /hello?foo=%99bar HTTP/1.1\r\n\r\n'); | |
c.end(); | |
}); | |
// TODO add more! | |
}); | |
process.on('exit', function() { | |
assert.equal(nrequests_expected, nrequests_completed); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment