($browser, createXhr, $browserDefer, callbacks, rawDocument)
| 13464 | } |
| 13465 | |
| 13466 | function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDocument) { |
| 13467 | // TODO(vojta): fix the signature |
| 13468 | return function(method, url, post, callback, headers, timeout, withCredentials, responseType, eventHandlers, uploadEventHandlers) { |
| 13469 | url = url || $browser.url(); |
| 13470 | |
| 13471 | if (lowercase(method) === 'jsonp') { |
| 13472 | var callbackPath = callbacks.createCallback(url); |
| 13473 | var jsonpDone = jsonpReq(url, callbackPath, function(status, text) { |
| 13474 | // jsonpReq only ever sets status to 200 (OK), 404 (ERROR) or -1 (WAITING) |
| 13475 | var response = (status === 200) && callbacks.getResponse(callbackPath); |
| 13476 | completeRequest(callback, status, response, '', text, 'complete'); |
| 13477 | callbacks.removeCallback(callbackPath); |
| 13478 | }); |
| 13479 | } else { |
| 13480 | |
| 13481 | var xhr = createXhr(method, url); |
| 13482 | var abortedByTimeout = false; |
| 13483 | |
| 13484 | xhr.open(method, url, true); |
| 13485 | forEach(headers, function(value, key) { |
| 13486 | if (isDefined(value)) { |
| 13487 | xhr.setRequestHeader(key, value); |
| 13488 | } |
| 13489 | }); |
| 13490 | |
| 13491 | xhr.onload = function requestLoaded() { |
| 13492 | var statusText = xhr.statusText || ''; |
| 13493 | |
| 13494 | // responseText is the old-school way of retrieving response (supported by IE9) |
| 13495 | // response/responseType properties were introduced in XHR Level2 spec (supported by IE10) |
| 13496 | var response = ('response' in xhr) ? xhr.response : xhr.responseText; |
| 13497 | |
| 13498 | // normalize IE9 bug (http://bugs.jquery.com/ticket/1450) |
| 13499 | var status = xhr.status === 1223 ? 204 : xhr.status; |
| 13500 | |
| 13501 | // fix status code when it is 0 (0 status is undocumented). |
| 13502 | // Occurs when accessing file resources or on Android 4.1 stock browser |
| 13503 | // while retrieving files from application cache. |
| 13504 | if (status === 0) { |
| 13505 | status = response ? 200 : urlResolve(url).protocol === 'file' ? 404 : 0; |
| 13506 | } |
| 13507 | |
| 13508 | completeRequest(callback, |
| 13509 | status, |
| 13510 | response, |
| 13511 | xhr.getAllResponseHeaders(), |
| 13512 | statusText, |
| 13513 | 'complete'); |
| 13514 | }; |
| 13515 | |
| 13516 | var requestError = function() { |
| 13517 | // The response is always empty |
| 13518 | // See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error |
| 13519 | completeRequest(callback, -1, null, null, '', 'error'); |
| 13520 | }; |
| 13521 | |
| 13522 | var requestAborted = function() { |
| 13523 | completeRequest(callback, -1, null, null, '', abortedByTimeout ? 'timeout' : 'abort'); |
no test coverage detected