Skip to content

Commit 1cba20a

Browse files
author
Admin
committed
Added support for multipart uploads
1 parent 9a34717 commit 1cba20a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

main.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function runPHP(req, response, next, phpdir){
3333
REQUEST_URI: req.url, //The original request URI sent by the client.
3434
REQUEST_METHOD: req.method, //The method used by the current request; usually set to GET or POST.
3535
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.
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.
3737
CONTENT_LENGTH: req.rawBody.length||0, //The length in bytes of the request body; set only for POST or PUT requests.
3838
AUTH_TYPE: "", //The authentication type if the client has authenticated itself to access the script.
3939
AUTH_USER: "",
@@ -58,11 +58,6 @@ function runPHP(req, response, next, phpdir){
5858

5959
Object.keys(req.headers).map(function(x){return env["HTTP_"+x.toUpperCase().replace("-", "_")] = req.headers[x];});
6060

61-
//console.log(env);
62-
//console.log("ALL: "+env.ALL_HTTP);
63-
//console.log("GET: "+file);
64-
//console.log("RAW BODY: "+req.rawBody);
65-
6661
if(/.*?\.php$/.test(file)){
6762
var res = "", err = "";
6863

@@ -72,8 +67,12 @@ function runPHP(req, response, next, phpdir){
7267

7368
//php.stdin.resume();
7469
//console.log(req.rawBody);
70+
//(new Stream(req.rawBody)).pipe(php.stdin);
71+
/*.on("error", function(){}); */
7572
php.stdin.write(req.rawBody);
76-
php.stdin.end();
73+
//php.stdin.write("\n");
74+
75+
//php.stdin.end();
7776

7877
php.stdout.on("data", function(data){
7978
//console.log(data.toString());
@@ -87,6 +86,8 @@ function runPHP(req, response, next, phpdir){
8786
});
8887
php.on("exit", function(){
8988
// extract headers
89+
php.stdin.end();
90+
9091
var lines = res.split("\r\n");
9192
var line = 0;
9293
var html = "";
@@ -95,7 +96,7 @@ function runPHP(req, response, next, phpdir){
9596
var m = lines[line].split(": ");
9697
if(m[0] === "") break;
9798

98-
console.log("HEADER: "+m[0]+": "+m[1]);
99+
//console.log("HEADER: "+m[0]+": "+m[1]);
99100
if(m[0] == "Status"){
100101
response.statusCode = parseInt(m[1]);
101102
}
@@ -136,6 +137,7 @@ exports.cgi = function(phproot){
136137
});
137138
req.on('end', function() {
138139
req.rawBody = data||"";
140+
//console.log(req.rawBody);
139141
//console.log("ENCODING: "+req.get("Content-type")+", len: "+req.rawBody.length);
140142
runPHP(req, res, next, phproot);
141143
});

0 commit comments

Comments
 (0)