($browser, createXhr, $browserDefer, callbacks, rawDocument)
| 10429 | } |
| 10430 | |
| 10431 | function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDocument) { |
| 10432 | // TODO(vojta): fix the signature |
| 10433 | return function(method, url, post, callback, headers, timeout, withCredentials, responseType) { |
| 10434 | $browser.$$incOutstandingRequestCount(); |
| 10435 | url = url || $browser.url(); |
| 10436 | |
| 10437 | if (lowercase(method) == 'jsonp') { |
| 10438 | var callbackId = '_' + (callbacks.counter++).toString(36); |
| 10439 | callbacks[callbackId] = function(data) { |
| 10440 | callbacks[callbackId].data = data; |
| 10441 | callbacks[callbackId].called = true; |
| 10442 | }; |
| 10443 | |
| 10444 | var jsonpDone = jsonpReq(url.replace('JSON_CALLBACK', 'angular.callbacks.' + callbackId), |
| 10445 | callbackId, function(status, text) { |
| 10446 | completeRequest(callback, status, callbacks[callbackId].data, "", text); |
| 10447 | callbacks[callbackId] = noop; |
| 10448 | }); |
| 10449 | } else { |
| 10450 | |
| 10451 | var xhr = createXhr(); |
| 10452 | |
| 10453 | xhr.open(method, url, true); |
| 10454 | forEach(headers, function(value, key) { |
| 10455 | if (isDefined(value)) { |
| 10456 | xhr.setRequestHeader(key, value); |
| 10457 | } |
| 10458 | }); |
| 10459 | |
| 10460 | xhr.onload = function requestLoaded() { |
| 10461 | var statusText = xhr.statusText || ''; |
| 10462 | |
| 10463 | // responseText is the old-school way of retrieving response (supported by IE8 & 9) |
| 10464 | // response/responseType properties were introduced in XHR Level2 spec (supported by IE10) |
| 10465 | var response = ('response' in xhr) ? xhr.response : xhr.responseText; |
| 10466 | |
| 10467 | // normalize IE9 bug (http://bugs.jquery.com/ticket/1450) |
| 10468 | var status = xhr.status === 1223 ? 204 : xhr.status; |
| 10469 | |
| 10470 | // fix status code when it is 0 (0 status is undocumented). |
| 10471 | // Occurs when accessing file resources or on Android 4.1 stock browser |
| 10472 | // while retrieving files from application cache. |
| 10473 | if (status === 0) { |
| 10474 | status = response ? 200 : urlResolve(url).protocol == 'file' ? 404 : 0; |
| 10475 | } |
| 10476 | |
| 10477 | completeRequest(callback, |
| 10478 | status, |
| 10479 | response, |
| 10480 | xhr.getAllResponseHeaders(), |
| 10481 | statusText); |
| 10482 | }; |
| 10483 | |
| 10484 | var requestError = function() { |
| 10485 | // The response is always empty |
| 10486 | // See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error |
| 10487 | completeRequest(callback, -1, null, null, ''); |
| 10488 | }; |
no test coverage detected