-
-
Save ncb000gt/899254 to your computer and use it in GitHub Desktop.
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
function serve_cgi(filename, res, get, post, method, vhost, port, pinfo, get, sname, uri, droot) { | |
var env = { | |
CONTENT_LENGTH: post.length, | |
CONTENT_TYPE: 'application/x-www-form-urlencoded', | |
DOCUMENT_ROOT: droot, | |
GATEWAY_INTERFACE: 'CGI/1.1', | |
HTTP_HOST: vhost, | |
QUERY_STRING: get, | |
REDIRECT_STATUS: '200', | |
REQUEST_METHOD: method, | |
REQUEST_URI: uri, | |
SCRIPT_FILENAME: filename, | |
SCRIPT_NAME: sname, | |
SERVER_NAME: vhost, | |
SERVER_PORT: port, | |
SERVER_PROTOCOL: 'HTTP/1.1', | |
SERVER_SOFTWARE: 'Node/'+process.version+' (Nodality/20110402)', | |
} | |
var chunks = []; | |
var total = 0; | |
var headers = {}; | |
var cgi = spawn(filename, [], env); | |
cgi.stdout.on('data', function (data) { | |
chunks.push(data); | |
total += data.length; | |
}); | |
cgi.on('exit', function (code) { | |
var buf = new Buffer(length); | |
var offset = 0; | |
chunks.forEach(function(chunk) { | |
chunk.copy(buf, offset, 0); | |
offset += chunk.length; | |
}); | |
//chop your headers out here. | |
//build the headers object up. | |
res.writeHead(200, headers); | |
res.write(data, 'binary'); | |
res.end(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment