Skip to content

Commit 9a34717

Browse files
author
Admin
committed
..
1 parent 4d008f1 commit 9a34717

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

main.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function runPHP(req, response, next, phpdir){
2121
else pathinfo = parts.pathname;
2222

2323
var env = {
24+
SERVER_SIGNATURE: "NodeJS server at localhost",
2425
PATH_INFO: pathinfo, //The extra path information, as given in the requested URL. In fact, scripts can be accessed by their virtual path, followed by extra information at the end of this path. The extra information is sent in PATH_INFO.
2526
PATH_TRANSLATED: "", //The virtual-to-real mapped version of PATH_INFO.
2627
SCRIPT_NAME: parts.pathname, //The virtual path of the script being executed.
@@ -31,8 +32,8 @@ function runPHP(req, response, next, phpdir){
3132
SCRIPT_URL: req.url,
3233
REQUEST_URI: req.url, //The original request URI sent by the client.
3334
REQUEST_METHOD: req.method, //The method used by the current request; usually set to GET or POST.
34-
QUERY_STRING: parts.query, //The information which follows the ? character in the requested URL.
35-
CONTENT_TYPE: "application/x-www-form-urlencoded", //The MIME type of the request body; set only for POST or PUT requests.
35+
QUERY_STRING: parts.query||"", //The information which follows the ? character in the requested URL.
36+
CONTENT_TYPE: req.get("Content-type"), //"multipart/form-data", //"application/x-www-form-urlencoded", //The MIME type of the request body; set only for POST or PUT requests.
3637
CONTENT_LENGTH: req.rawBody.length||0, //The length in bytes of the request body; set only for POST or PUT requests.
3738
AUTH_TYPE: "", //The authentication type if the client has authenticated itself to access the script.
3839
AUTH_USER: "",
@@ -59,7 +60,7 @@ function runPHP(req, response, next, phpdir){
5960

6061
//console.log(env);
6162
//console.log("ALL: "+env.ALL_HTTP);
62-
console.log("GET: "+file);
63+
//console.log("GET: "+file);
6364
//console.log("RAW BODY: "+req.rawBody);
6465

6566
if(/.*?\.php$/.test(file)){
@@ -70,7 +71,8 @@ function runPHP(req, response, next, phpdir){
7071
});
7172

7273
//php.stdin.resume();
73-
php.stdin.write(req.rawBody+"\n");
74+
//console.log(req.rawBody);
75+
php.stdin.write(req.rawBody);
7476
php.stdin.end();
7577

7678
php.stdout.on("data", function(data){
@@ -93,7 +95,7 @@ function runPHP(req, response, next, phpdir){
9395
var m = lines[line].split(": ");
9496
if(m[0] === "") break;
9597

96-
//console.log("HEADER: "+m[0]+": "+m[1]);
98+
console.log("HEADER: "+m[0]+": "+m[1]);
9799
if(m[0] == "Status"){
98100
response.statusCode = parseInt(m[1]);
99101
}
@@ -102,12 +104,13 @@ function runPHP(req, response, next, phpdir){
102104
}
103105
line++;
104106
} while(lines[line] !== "");
107+
105108
html = lines.splice(line+1).join("\n");
106109
} else {
107110
html = res;
108111
}
109112
//console.log("STATUS: "+response.statusCode);
110-
113+
//console.log(html);
111114
response.send(html, response.statusCode);
112115
response.end();
113116
});
@@ -121,13 +124,19 @@ function runPHP(req, response, next, phpdir){
121124

122125
exports.cgi = function(phproot){
123126
return function(req, res, next){
124-
var data = '';
125-
req.setEncoding('utf8');
127+
var data = null;
128+
129+
//req.setEncoding('utf8');
126130
req.on('data', function(chunk) {
127-
data += chunk;
131+
//data.write(chunk.toString('binary'), data.length, chunk.length, 'binary');
132+
//console.log(chunk);
133+
if(!data) data = chunk;
134+
else data = data+chunk;
135+
//data = data.concat(chunk);
128136
});
129137
req.on('end', function() {
130-
req.rawBody = data;
138+
req.rawBody = data||"";
139+
//console.log("ENCODING: "+req.get("Content-type")+", len: "+req.rawBody.length);
131140
runPHP(req, res, next, phproot);
132141
});
133142
}

0 commit comments

Comments
 (0)