@@ -207,6 +207,8 @@ exports.XMLHttpRequest = function() {
207207 this . getResponseHeader = function ( header ) {
208208 if ( typeof header === "string"
209209 && this . readyState > this . OPENED
210+ && response
211+ && response . headers
210212 && response . headers [ header . toLowerCase ( ) ]
211213 && ! errorFlag
212214 ) {
@@ -385,7 +387,7 @@ exports.XMLHttpRequest = function() {
385387 response = resp ;
386388 // Check for redirect
387389 // @TODO Prevent looped redirects
388- if ( response . statusCode === 302 || response . statusCode === 303 || response . statusCode === 307 ) {
390+ if ( response . statusCode === 301 || response . statusCode === 302 || response . statusCode === 303 || response . statusCode === 307 ) {
389391 // Change URL to the redirect location
390392 settings . url = response . headers . location ;
391393 var url = Url . parse ( settings . url ) ;
@@ -479,7 +481,7 @@ exports.XMLHttpRequest = function() {
479481 + "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
480482 + "fs.unlinkSync('" + syncFile + "');"
481483 + "});"
482- + ( data ? "req.write('" + data . replace ( / ' / g, "\\'" ) + "');" :"" )
484+ + ( data ? "req.write('" + JSON . stringify ( data ) . slice ( 1 , - 1 ) . replace ( / ' / g, "\\'" ) + "');" :"" )
483485 + "req.end();" ;
484486 // Start the other Node Process, executing this string
485487 var syncProc = spawn ( process . argv [ 0 ] , [ "-e" , execString ] ) ;
@@ -498,7 +500,7 @@ exports.XMLHttpRequest = function() {
498500 self . handleError ( errorObj ) ;
499501 } else {
500502 // If the file returned okay, parse its data and move to the DONE state
501- self . status = 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" ) ;
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 ) ;
502504 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" ) ;
503505 setState ( self . DONE ) ;
504506 }
@@ -584,7 +586,7 @@ exports.XMLHttpRequest = function() {
584586 * @param int state New state
585587 */
586588 var setState = function ( state ) {
587- if ( self . readyState !== state ) {
589+ if ( state == self . LOADING || self . readyState !== state ) {
588590 self . readyState = state ;
589591
590592 if ( settings . async || self . readyState < self . OPENED || self . readyState === self . DONE ) {
0 commit comments