MCPcopy Index your code
hub / github.com/angular-ui/ui-router / defaultHttpResponseTransform

Function defaultHttpResponseTransform

test/angular/1.7/angular.js:12010–12034  ·  view source on GitHub ↗
(data, headers)

Source from the content-addressed store, hash-verified

12008}
12009
12010function 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
12036function isJsonLike(str) {
12037 var jsonStart = str.match(JSON_START);

Callers

nothing calls this directly

Calls 3

isStringFunction · 0.70
isJsonLikeFunction · 0.70
fromJsonFunction · 0.70

Tested by

no test coverage detected