zones/requests/xhr-cookies.js
function(httpMethod, xhrURL){
			var cookie = headers["cookie"] || "";

			// Monkey patch URL onto xhr for cookie origin checking in the send method.
			var reqURL = url.parse(xhrURL);
			this.__url = reqURL;

			if (options.auth && cookie) {
				var domainIsApproved = options.auth.domains.reduce(function(prev, domain){
					return prev || reqURL.host.indexOf(domain) >= 0;
				}, false);
			}

			// fix: if proxy is specified, use proxy-hostname instead of request-hostname for xhrURL
			var args = Array.prototype.slice.call(arguments);
			if (
				options &&
				options.proxy &&
				options.proxyTo &&
				(xhrURL.indexOf(options.proxyTo) === 0)
			) {
				args[1] = url.resolve(options.proxy, xhrURL);
			}
			var res = oldOpen.apply(this, args);

			// If on an approved domain copy the jwt from a cookie to the request headers.
			if (domainIsApproved) {
				var jwtCookie = cookieReg.exec(cookie);
				if(jwtCookie && !this.getRequestHeader('authorization')){
					this.setRequestHeader('authorization', 'Bearer ' + jwtCookie[1]);
				}
			}

			return res;
		}
function(httpMethod, xhrURL){
			var cookie = headers["cookie"] || "";

			// Monkey patch URL onto xhr for cookie origin checking in the send method.
			var reqURL = url.parse(xhrURL);
			this.__url = reqURL;

			if (options.auth && cookie) {
				var domainIsApproved = options.auth.domains.reduce(function(prev, domain){
					return prev || reqURL.host.indexOf(domain) >= 0;
				}, false);
			}

			// fix: if proxy is specified, use proxy-hostname instead of request-hostname for xhrURL
			var args = Array.prototype.slice.call(arguments);
			if (
				options &&
				options.proxy &&
				options.proxyTo &&
				(xhrURL.indexOf(options.proxyTo) === 0)
			) {
				args[1] = url.resolve(options.proxy, xhrURL);
			}
			var res = oldOpen.apply(this, args);

			// If on an approved domain copy the jwt from a cookie to the request headers.
			if (domainIsApproved) {
				var jwtCookie = cookieReg.exec(cookie);
				if(jwtCookie && !this.getRequestHeader('authorization')){
					this.setRequestHeader('authorization', 'Bearer ' + jwtCookie[1]);
				}
			}

			return res;
		}
function ( httpMethod , xhrURL ) { var cookie = headers [ "cookie" ] || "" ; // Monkey patch URL onto xhr for cookie origin checking in the send method. var reqURL = url . parse ( xhrURL ) ; this . __url = reqURL ; if ( options . auth && cookie ) { var domainIsApproved = options . auth . domains . reduce ( function ( prev , domain ) { return prev || reqURL . host . indexOf ( domain ) >= 0 ; } , false ) ; } // fix: if proxy is specified, use proxy-hostname instead of request-hostname for xhrURL var args = Array . prototype . slice . call ( arguments ) ; if ( options && options . proxy && options . proxyTo && ( xhrURL . indexOf ( options . proxyTo ) === 0 ) ) { args [ 1 ] = url . resolve ( options . proxy , xhrURL ) ; } var res = oldOpen . apply ( this , args ) ; // If on an approved domain copy the jwt from a cookie to the request headers. if ( domainIsApproved ) { var jwtCookie = cookieReg . exec ( cookie ) ; if ( jwtCookie && ! this . getRequestHeader ( 'authorization' ) ) { this . setRequestHeader ( 'authorization' , 'Bearer ' + jwtCookie [ 1 ] ) ; } } return res ; }
Override open to attach auth header if the domain is approved.
Override open to attach auth header if the domain is approved .