@@ -470,38 +470,36 @@ exports.XMLHttpRequest = function() {
470470 + " responseText += chunk;"
471471 + "});"
472472 + "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');"
474474 + "fs.unlinkSync('" + syncFile + "');"
475475 + "});"
476476 + "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');"
478478 + "fs.unlinkSync('" + syncFile + "');"
479479 + "});"
480480 + "}).on('error', function(error) {"
481- + "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
481+ + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: error} ), 'utf8');"
482482 + "fs.unlinkSync('" + syncFile + "');"
483483 + "});"
484484 + ( data ? "req.write('" + JSON . stringify ( data ) . slice ( 1 , - 1 ) . replace ( / ' / g, "\\'" ) + "');" :"" )
485485 + "req.end();" ;
486486 // Start the other Node Process, executing this string
487487 var syncProc = spawn ( process . argv [ 0 ] , [ "-e" , execString ] ) ;
488- var statusText ;
489488 while ( fs . existsSync ( syncFile ) ) {
490489 // Wait while the sync file is empty
491490 }
492- self . responseText = fs . readFileSync ( contentFile , " utf8" ) ;
491+ var resp = JSON . parse ( fs . readFileSync ( contentFile , ' utf8' ) ) ;
493492 // Kill the child process once the file has data
494493 syncProc . stdin . end ( ) ;
495494 // Remove the temporary file
496495 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 ) ;
501499 } 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 ;
505503 setState ( self . DONE ) ;
506504 }
507505 }
0 commit comments