| 1203 | } |
| 1204 | |
| 1205 | function wrapResponse(wrapped) { |
| 1206 | if (!$browser && timeout) { |
| 1207 | timeout.then ? timeout.then(handleTimeout) : $timeout(handleTimeout, timeout); |
| 1208 | } |
| 1209 | |
| 1210 | return handleResponse; |
| 1211 | |
| 1212 | function handleResponse() { |
| 1213 | var response = wrapped.response(method, url, data, headers); |
| 1214 | xhr.$$respHeaders = response[2]; |
| 1215 | callback(copy(response[0]), copy(response[1]), xhr.getAllResponseHeaders(), |
| 1216 | copy(response[3] || '')); |
| 1217 | } |
| 1218 | |
| 1219 | function handleTimeout() { |
| 1220 | for (var i = 0, ii = responses.length; i < ii; i++) { |
| 1221 | if (responses[i] === handleResponse) { |
| 1222 | responses.splice(i, 1); |
| 1223 | callback(-1, undefined, ''); |
| 1224 | break; |
| 1225 | } |
| 1226 | } |
| 1227 | } |
| 1228 | } |
| 1229 | |
| 1230 | if (expectation && expectation.match(method, url)) { |
| 1231 | if (!expectation.matchData(data)) |