Fix(http): invalidStateError if response body without content (#11786)

Fix(http): invalidStateError if response body without content
If the responseType has been specified and other than 'text', responseText throw an InvalidStateError exception

See XHR doc => https://xhr.spec.whatwg.org/#the-responsetext-attribute

Unit Test to prevent invalidStateError
This commit is contained in:
Flounn
2016-09-23 22:44:01 +02:00
committed by Rado Kirov
parent f1b6c6efa1
commit 5ab5cc77bb
2 changed files with 19 additions and 3 deletions

View File

@ -54,9 +54,8 @@ export class XHRConnection implements Connection {
let onLoad = () => {
// responseText is the old-school way of retrieving response (supported by IE8 & 9)
// response/responseType properties were introduced in ResourceLoader Level2 spec (supported
// by
// IE10)
let body = isPresent(_xhr.response) ? _xhr.response : _xhr.responseText;
// by IE10)
let body = _xhr.response === undefined ? _xhr.responseText : _xhr.response;
// Implicitly strip a potential XSSI prefix.
if (isString(body)) body = body.replace(XSSI_PREFIX, '');
let headers = Headers.fromResponseHeaderString(_xhr.getAllResponseHeaders());