| 1261 | } |
| 1262 | |
| 1263 | function wrapResponse(wrapped) { |
| 1264 | if (!$browser && timeout) { |
| 1265 | timeout.then ? timeout.then(handleTimeout) : $timeout(handleTimeout, timeout); |
| 1266 | } |
| 1267 | |
| 1268 | return handleResponse; |
| 1269 | |
| 1270 | function handleResponse() { |
| 1271 | var response = wrapped.response(method, url, data, headers); |
| 1272 | xhr.$$respHeaders = response[2]; |
| 1273 | callback(copy(response[0]), copy(response[1]), xhr.getAllResponseHeaders(), |
| 1274 | copy(response[3] || '')); |
| 1275 | } |
| 1276 | |
| 1277 | function handleTimeout() { |
| 1278 | for (var i = 0, ii = responses.length; i < ii; i++) { |
| 1279 | if (responses[i] === handleResponse) { |
| 1280 | responses.splice(i, 1); |
| 1281 | callback(-1, undefined, ''); |
| 1282 | break; |
| 1283 | } |
| 1284 | } |
| 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | if (expectation && expectation.match(method, url)) { |
| 1289 | if (!expectation.matchData(data)) { |