($browser, createXhr, $browserDefer, callbacks, rawDocument)
| 13529 | } |
| 13530 | |
| 13531 | function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDocument) { |
| 13532 | // TODO(vojta): fix the signature |
| 13533 | return function(method, url, post, callback, headers, timeout, withCredentials, responseType, eventHandlers, uploadEventHandlers) { |
| 13534 | url = url || $browser.url(); |
| 13535 | |
| 13536 | if (lowercase(method) === 'jsonp') { |
| 13537 | var callbackPath = callbacks.createCallback(url); |
| 13538 | var jsonpDone = jsonpReq(url, callbackPath, function(status, text) { |
| 13539 | // jsonpReq only ever sets status to 200 (OK), 404 (ERROR) or -1 (WAITING) |
| 13540 | var response = (status === 200) && callbacks.getResponse(callbackPath); |
| 13541 | completeRequest(callback, status, response, '', text, 'complete'); |
| 13542 | callbacks.removeCallback(callbackPath); |
| 13543 | }); |
| 13544 | } else { |
| 13545 | |
| 13546 | var xhr = createXhr(method, url); |
| 13547 | var abortedByTimeout = false; |
| 13548 | |
| 13549 | xhr.open(method, url, true); |
| 13550 | forEach(headers, function(value, key) { |
| 13551 | if (isDefined(value)) { |
| 13552 | xhr.setRequestHeader(key, value); |
| 13553 | } |
| 13554 | }); |
| 13555 | |
| 13556 | xhr.onload = function requestLoaded() { |
| 13557 | var statusText = xhr.statusText || ''; |
| 13558 | |
| 13559 | // responseText is the old-school way of retrieving response (supported by IE9) |
| 13560 | // response/responseType properties were introduced in XHR Level2 spec (supported by IE10) |
| 13561 | var response = ('response' in xhr) ? xhr.response : xhr.responseText; |
| 13562 | |
| 13563 | // normalize IE9 bug (http://bugs.jquery.com/ticket/1450) |
| 13564 | var status = xhr.status === 1223 ? 204 : xhr.status; |
| 13565 | |
| 13566 | // fix status code when it is 0 (0 status is undocumented). |
| 13567 | // Occurs when accessing file resources or on Android 4.1 stock browser |
| 13568 | // while retrieving files from application cache. |
| 13569 | if (status === 0) { |
| 13570 | status = response ? 200 : urlResolve(url).protocol === 'file' ? 404 : 0; |
| 13571 | } |
| 13572 | |
| 13573 | completeRequest(callback, |
| 13574 | status, |
| 13575 | response, |
| 13576 | xhr.getAllResponseHeaders(), |
| 13577 | statusText, |
| 13578 | 'complete'); |
| 13579 | }; |
| 13580 | |
| 13581 | var requestError = function() { |
| 13582 | // The response is always empty |
| 13583 | // See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error |
| 13584 | completeRequest(callback, -1, null, null, '', 'error'); |
| 13585 | }; |
| 13586 | |
| 13587 | var requestAborted = function() { |
| 13588 | completeRequest(callback, -1, null, null, '', abortedByTimeout ? 'timeout' : 'abort'); |
no test coverage detected