88
99import { Injectable } from '@angular/core' ;
1010import { __platform_browser_private__ } from '@angular/platform-browser' ;
11+ import { Observable } from 'rxjs/Observable' ;
12+ import { Observer } from 'rxjs/Observer' ;
1113import { ResponseOptions } from '../base_response_options' ;
1214import { ContentType , ReadyState , RequestMethod , ResponseContentType , ResponseType } from '../enums' ;
1315import { Headers } from '../headers' ;
@@ -16,8 +18,6 @@ import {Connection, ConnectionBackend, XSRFStrategy} from '../interfaces';
1618import { Request } from '../static_request' ;
1719import { Response } from '../static_response' ;
1820import { BrowserXhr } from './browser_xhr' ;
19- import { Observable } from 'rxjs/Observable' ;
20- import { Observer } from 'rxjs/Observer' ;
2121
2222const XSSI_PREFIX = / ^ \) \] \} ' , ? \n / ;
2323
@@ -49,27 +49,36 @@ export class XHRConnection implements Connection {
4949 }
5050 // load event handler
5151 const onLoad = ( ) => {
52- // responseText is the old-school way of retrieving response (supported by IE8 & 9)
53- // response/responseType properties were introduced in ResourceLoader Level2 spec (supported
54- // by IE10)
55- let body = _xhr . response === undefined ? _xhr . responseText : _xhr . response ;
56- // Implicitly strip a potential XSSI prefix.
57- if ( typeof body === 'string' ) body = body . replace ( XSSI_PREFIX , '' ) ;
58- const headers = Headers . fromResponseHeaderString ( _xhr . getAllResponseHeaders ( ) ) ;
59-
60- const url = getResponseURL ( _xhr ) ;
61-
6252 // normalize IE9 bug (http://bugs.jquery.com/ticket/1450)
6353 let status : number = _xhr . status === 1223 ? 204 : _xhr . status ;
6454
55+ let body : any = null ;
56+
57+ // HTTP 204 means no content
58+ if ( status !== 204 ) {
59+ // responseText is the old-school way of retrieving response (supported by IE8 & 9)
60+ // response/responseType properties were introduced in ResourceLoader Level2 spec
61+ // (supported by IE10)
62+ body = _xhr . response == null ? _xhr . responseText : _xhr . response ;
63+
64+ // Implicitly strip a potential XSSI prefix.
65+ if ( typeof body === 'string' ) {
66+ body = body . replace ( XSSI_PREFIX , '' ) ;
67+ }
68+ }
69+
6570 // fix status code when it is 0 (0 status is undocumented).
6671 // Occurs when accessing file resources or on Android 4.1 stock browser
6772 // while retrieving files from application cache.
6873 if ( status === 0 ) {
6974 status = body ? 200 : 0 ;
7075 }
7176
72- const statusText = _xhr . statusText || 'OK' ;
77+ const headers : Headers = Headers . fromResponseHeaderString ( _xhr . getAllResponseHeaders ( ) ) ;
78+
79+ const url : string = getResponseURL ( _xhr ) ;
80+
81+ const statusText : string = _xhr . statusText || 'OK' ;
7382
7483 let responseOptions = new ResponseOptions ( { body, status, headers, statusText, url} ) ;
7584 if ( baseResponseOptions != null ) {
@@ -86,7 +95,7 @@ export class XHRConnection implements Connection {
8695 responseObserver . error ( response ) ;
8796 } ;
8897 // error event handler
89- const onError = ( err : any ) => {
98+ const onError = ( err : ErrorEvent ) => {
9099 let responseOptions = new ResponseOptions ( {
91100 body : err ,
92101 type : ResponseType . Error ,
@@ -138,7 +147,7 @@ export class XHRConnection implements Connection {
138147 } ) ;
139148 }
140149
141- setDetectedContentType ( req : any /** TODO #9100 */ , _xhr : XMLHttpRequest ) {
150+ setDetectedContentType ( req : any /** TODO Request */ , _xhr : any /** XMLHttpRequest */ ) {
142151 // Skip if a custom Content-Type header is provided
143152 if ( req . headers != null && req . headers . get ( 'Content-Type' ) != null ) {
144153 return ;
0 commit comments