@@ -80,6 +80,7 @@ exports.XMLHttpRequest = function() {
8080 /**
8181 * Constants
8282 */
83+
8384 this . UNSENT = 0 ;
8485 this . OPENED = 1 ;
8586 this . HEADERS_RECEIVED = 2 ;
@@ -89,6 +90,7 @@ exports.XMLHttpRequest = function() {
8990 /**
9091 * Public vars
9192 */
93+
9294 // Current state
9395 this . readyState = this . UNSENT ;
9496
@@ -198,7 +200,7 @@ exports.XMLHttpRequest = function() {
198200 /**
199201 * Gets all the response headers.
200202 *
201- * @return string
203+ * @return string A string with all response headers separated by CR+LF
202204 */
203205 this . getAllResponseHeaders = function ( ) {
204206 if ( this . readyState < this . HEADERS_RECEIVED || errorFlag ) {
@@ -207,7 +209,11 @@ exports.XMLHttpRequest = function() {
207209 var result = "" ;
208210
209211 for ( var i in response . headers ) {
210- result += i + ": " + response . headers [ i ] + "\r\n" ;
212+ var headerName = i . toLowerCase ( ) ;
213+ // Cookie headers are excluded
214+ if ( headerName !== "set-cookie" && headerName !== "set-cookie2" ) {
215+ result += i + ": " + response . headers [ i ] + "\r\n" ;
216+ }
211217 }
212218 return result . substr ( 0 , result . length - 2 ) ;
213219 } ;
@@ -254,7 +260,7 @@ exports.XMLHttpRequest = function() {
254260 var uri = url . pathname + ( url . search ? url . search : '' ) ;
255261
256262 // Set the Host header or the server may reject the request
257- this . setRequestHeader ( "Host" , host ) ;
263+ headers [ "Host" ] = host ;
258264
259265 // Set Basic Auth if necessary
260266 if ( settings . user ) {
@@ -269,10 +275,10 @@ exports.XMLHttpRequest = function() {
269275 if ( settings . method == "GET" || settings . method == "HEAD" ) {
270276 data = null ;
271277 } else if ( data ) {
272- this . setRequestHeader ( "Content-Length" , Buffer . byteLength ( data ) ) ;
278+ headers [ "Content-Length" ] = Buffer . byteLength ( data ) ;
273279
274280 if ( ! headers [ "Content-Type" ] ) {
275- this . setRequestHeader ( "Content-Type" , "text/plain;charset=UTF-8" ) ;
281+ headers [ "Content-Type" ] = "text/plain;charset=UTF-8" ;
276282 }
277283 }
278284
0 commit comments