@@ -470,38 +470,36 @@ exports.XMLHttpRequest = function() {
470
470
+ " responseText += chunk;"
471
471
+ "});"
472
472
+ "response.on('end', function() {"
473
- + "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-STATUS:' + response.statusCode + ',' + responseText, 'utf8');"
473
+ + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: null, data: {statusCode: response.statusCode, headers: response.headers, text: responseText}}) , 'utf8');"
474
474
+ "fs.unlinkSync('" + syncFile + "');"
475
475
+ "});"
476
476
+ "response.on('error', function(error) {"
477
- + "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
477
+ + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: error} ), 'utf8');"
478
478
+ "fs.unlinkSync('" + syncFile + "');"
479
479
+ "});"
480
480
+ "}).on('error', function(error) {"
481
- + "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
481
+ + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: error} ), 'utf8');"
482
482
+ "fs.unlinkSync('" + syncFile + "');"
483
483
+ "});"
484
484
+ ( data ? "req.write('" + JSON . stringify ( data ) . slice ( 1 , - 1 ) . replace ( / ' / g, "\\'" ) + "');" :"" )
485
485
+ "req.end();" ;
486
486
// Start the other Node Process, executing this string
487
487
var syncProc = spawn ( process . argv [ 0 ] , [ "-e" , execString ] ) ;
488
- var statusText ;
489
488
while ( fs . existsSync ( syncFile ) ) {
490
489
// Wait while the sync file is empty
491
490
}
492
- self . responseText = fs . readFileSync ( contentFile , " utf8" ) ;
491
+ var resp = JSON . parse ( fs . readFileSync ( contentFile , ' utf8' ) ) ;
493
492
// Kill the child process once the file has data
494
493
syncProc . stdin . end ( ) ;
495
494
// Remove the temporary file
496
495
fs . unlinkSync ( contentFile ) ;
497
- if ( self . responseText . match ( / ^ N O D E - X M L H T T P R E Q U E S T - E R R O R : / ) ) {
498
- // If the file returned an error, handle it
499
- var errorObj = self . responseText . replace ( / ^ N O D E - X M L H T T P R E Q U E S T - E R R O R : / , "" ) ;
500
- self . handleError ( errorObj ) ;
496
+
497
+ if ( resp . err ) {
498
+ self . handleError ( resp . err ) ;
501
499
} else {
502
- // If the file returned okay, parse its data and move to the DONE state
503
- self . status = parseInt ( self . responseText . replace ( / ^ N O D E - X M L H T T P R E Q U E S T - S T A T U S : ( [ 0 - 9 ] * ) , . * / , "$1" ) , 10 ) ;
504
- self . responseText = self . responseText . replace ( / ^ N O D E - X M L H T T P R E Q U E S T - S T A T U S : [ 0 - 9 ] * , ( . * ) / , "$1" ) ;
500
+ response = resp . data ;
501
+ self . status = resp . data . statusCode ;
502
+ self . responseText = resp . data . text ;
505
503
setState ( self . DONE ) ;
506
504
}
507
505
}
0 commit comments