PATH_INFO is sticky
avdd opened this issue · comments
With normal usage, PATH_INFO is being set once on the first request and subsequent requests do not change. This can be worked around by re-initialising a fresh cgi object on each request.
This smells like there is some incorrect usage of globals, and indeed cgi.js#103 looks suspicous:
options.env = env;
options
here is the config object passed to cgi()
. I don't think it should be updated with per-request state.
I'm not really sure what you mean here. env
is not a global.
The options
object belongs to the outermost scope of cgi()
, but you
modify it with the request environment. That modification remains
persistent in the options
object for subsequent requests.
var connect = require('connect');
var request = require('request');
var http = require('http');
var cgi = require('cgi');
var server = http.createServer(
cgi('/bin/sh', {
args: ['-c', 'echo "content-type: text/plain\n\n$PATH_INFO"']
})
)
.listen(5555, function () {
console.log('server listening');
function get(path, f) {
var rqOpts = {
url: 'http://localhost:5555/' + path
};
return request(rqOpts, f);
}
get('first', function (e, rs, body) {
console.log('first response: ' + body);
get('second', function (e, rs, body) {
console.log('second response: ' + body);
setTimeout(function() {
server.close();
}, 1000);
});
})
});
output:
server listening
first response: /first
second response: /first
Thanks for the report. Fixed in v0.3.1 I believe! 🍻
Good work!