| 1148 | } |
| 1149 | |
| 1150 | function wrapResponse(wrapped) { |
| 1151 | if (!$browser && timeout) { |
| 1152 | timeout.then ? timeout.then(handleTimeout) : $timeout(handleTimeout, timeout); |
| 1153 | } |
| 1154 | |
| 1155 | return handleResponse; |
| 1156 | |
| 1157 | function handleResponse() { |
| 1158 | var response = wrapped.response(method, url, data, headers); |
| 1159 | xhr.$$respHeaders = response[2]; |
| 1160 | callback(copy(response[0]), copy(response[1]), xhr.getAllResponseHeaders(), |
| 1161 | copy(response[3] || '')); |
| 1162 | } |
| 1163 | |
| 1164 | function handleTimeout() { |
| 1165 | for (var i = 0, ii = responses.length; i < ii; i++) { |
| 1166 | if (responses[i] === handleResponse) { |
| 1167 | responses.splice(i, 1); |
| 1168 | callback(-1, undefined, ''); |
| 1169 | break; |
| 1170 | } |
| 1171 | } |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | if (expectation && expectation.match(method, url)) { |
| 1176 | if (!expectation.matchData(data)) { |