(data, headers)
| 12008 | } |
| 12009 | |
| 12010 | function defaultHttpResponseTransform(data, headers) { |
| 12011 | if (isString(data)) { |
| 12012 | // Strip json vulnerability protection prefix and trim whitespace |
| 12013 | var tempData = data.replace(JSON_PROTECTION_PREFIX, '').trim(); |
| 12014 | |
| 12015 | if (tempData) { |
| 12016 | var contentType = headers('Content-Type'); |
| 12017 | var hasJsonContentType = contentType && (contentType.indexOf(APPLICATION_JSON) === 0); |
| 12018 | |
| 12019 | if (hasJsonContentType || isJsonLike(tempData)) { |
| 12020 | try { |
| 12021 | data = fromJson(tempData); |
| 12022 | } catch (e) { |
| 12023 | if (!hasJsonContentType) { |
| 12024 | return data; |
| 12025 | } |
| 12026 | throw $httpMinErr('baddata', 'Data must be a valid JSON object. Received: "{0}". ' + |
| 12027 | 'Parse error: "{1}"', data, e); |
| 12028 | } |
| 12029 | } |
| 12030 | } |
| 12031 | } |
| 12032 | |
| 12033 | return data; |
| 12034 | } |
| 12035 | |
| 12036 | function isJsonLike(str) { |
| 12037 | var jsonStart = str.match(JSON_START); |
nothing calls this directly
no test coverage detected