@@ -41,6 +41,7 @@ class MockBrowserXHR extends BrowserXhr {
4141 callbacks = new Map < string , Function > ( ) ;
4242 status : number ;
4343 responseHeaders : string ;
44+ responseURL : string ;
4445 constructor ( ) {
4546 super ( ) ;
4647 var spy = new SpyObject ( ) ;
@@ -56,10 +57,14 @@ class MockBrowserXHR extends BrowserXhr {
5657
5758 setResponseText ( value ) { this . responseText = value ; }
5859
60+ setResponseURL ( value ) { this . responseURL = value ; }
61+
5962 setResponseHeaders ( value ) { this . responseHeaders = value ; }
6063
6164 getAllResponseHeaders ( ) { return this . responseHeaders || '' ; }
6265
66+ getResponseHeader ( key ) { return Headers . fromResponseHeaderString ( this . responseHeaders ) . get ( key ) ; }
67+
6368 addEventListener ( type : string , cb : Function ) { this . callbacks . set ( type , cb ) ; }
6469
6570 removeEventListener ( type : string , cb : Function ) { this . callbacks . delete ( type ) ; }
@@ -285,6 +290,39 @@ export function main() {
285290 existingXHRs [ 0 ] . setStatusCode ( statusCode ) ;
286291 existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
287292 } ) ) ;
293+
294+ it ( 'should add the responseURL to the response' , inject ( [ AsyncTestCompleter ] , async => {
295+ var statusCode = 200 ;
296+ var connection = new XHRConnection ( sampleRequest , new MockBrowserXHR ( ) ,
297+ new ResponseOptions ( { status : statusCode } ) ) ;
298+
299+ connection . response . subscribe ( res => {
300+ expect ( res . url ) . toEqual ( 'http://google.com' ) ;
301+ async . done ( ) ;
302+ } ) ;
303+
304+ existingXHRs [ 0 ] . setResponseURL ( 'http://google.com' ) ;
305+ existingXHRs [ 0 ] . setStatusCode ( statusCode ) ;
306+ existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
307+ } ) ) ;
308+
309+ it ( 'should add use the X-Request-URL in CORS situations' ,
310+ inject ( [ AsyncTestCompleter ] , async => {
311+ var statusCode = 200 ;
312+ var connection = new XHRConnection ( sampleRequest , new MockBrowserXHR ( ) ,
313+ new ResponseOptions ( { status : statusCode } ) ) ;
314+ var responseHeaders = `X-Request-URL: http://somedomain.com
315+ Foo: Bar`
316+
317+ connection . response . subscribe ( res => {
318+ expect ( res . url ) . toEqual ( 'http://somedomain.com' ) ;
319+ async . done ( ) ;
320+ } ) ;
321+
322+ existingXHRs [ 0 ] . setResponseHeaders ( responseHeaders ) ;
323+ existingXHRs [ 0 ] . setStatusCode ( statusCode ) ;
324+ existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
325+ } ) ) ;
288326 } ) ;
289327 } ) ;
290328}
0 commit comments