@@ -466,15 +466,15 @@ exports.XMLHttpRequest = function() {
466466 + " responseText += chunk;"
467467 + "});"
468468 + "response.on('end', function() {"
469- + "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-STATUS:' + response.statusCode + ',' + responseText, 'utf8');"
469+ + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: null, data: {statusCode: response.statusCode, headers: response.headers, text: responseText}}) , 'utf8');"
470470 + "fs.unlinkSync('" + syncFile + "');"
471471 + "});"
472472 + "response.on('error', function(error) {"
473- + "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
473+ + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: error} ), 'utf8');"
474474 + "fs.unlinkSync('" + syncFile + "');"
475475 + "});"
476476 + "}).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 + ( data ? "req.write('" + data . replace ( / ' / g, "\\'" ) + "');" :"" )
@@ -485,19 +485,19 @@ exports.XMLHttpRequest = function() {
485485 while ( fs . existsSync ( syncFile ) ) {
486486 // Wait while the sync file is empty
487487 }
488- self . responseText = fs . readFileSync ( contentFile , 'utf8' ) ;
488+ var resp = JSON . parse ( fs . readFileSync ( contentFile , 'utf8' ) ) ;
489489 // Kill the child process once the file has data
490490 syncProc . stdin . end ( ) ;
491491 // Remove the temporary file
492492 fs . unlinkSync ( contentFile ) ;
493- 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 : / ) ) {
494- // If the file returned an error, handle it
495- 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 : / , "" ) ;
496- self . handleError ( errorObj ) ;
493+
494+ console . log ( self . responseText ) ;
495+ if ( resp . err ) {
496+ self . handleError ( resp . err ) ;
497497 } else {
498- // If the file returned okay, parse its data and move to the DONE state
499- 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 ) ;
500- 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" ) ;
498+ response = resp . data ;
499+ self . status = resp . data . statusCode ;
500+ self . responseText = resp . data . text ;
501501 setState ( self . DONE ) ;
502502 }
503503 }
0 commit comments