| 1353 | } |
| 1354 | |
| 1355 | function wrapResponse(wrapped) { |
| 1356 | if (!$browser && timeout) { |
| 1357 | if (timeout.then) { |
| 1358 | timeout.then(handleTimeout); |
| 1359 | } else { |
| 1360 | $timeout(handleTimeout, timeout); |
| 1361 | } |
| 1362 | } |
| 1363 | |
| 1364 | return handleResponse; |
| 1365 | |
| 1366 | function handleResponse() { |
| 1367 | var response = wrapped.response(method, url, data, headers, wrapped.params(url)); |
| 1368 | xhr.$$respHeaders = response[2]; |
| 1369 | callback(copy(response[0]), copy(response[1]), xhr.getAllResponseHeaders(), |
| 1370 | copy(response[3] || '')); |
| 1371 | } |
| 1372 | |
| 1373 | function handleTimeout() { |
| 1374 | for (var i = 0, ii = responses.length; i < ii; i++) { |
| 1375 | if (responses[i] === handleResponse) { |
| 1376 | responses.splice(i, 1); |
| 1377 | callback(-1, undefined, ''); |
| 1378 | break; |
| 1379 | } |
| 1380 | } |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | if (expectation && expectation.match(method, url)) { |
| 1385 | if (!expectation.matchData(data)) { |