DefaultTransformDataHttpInterceptor class
The default transform data interceptor.abstract
For requests, this interceptor will automatically stringify any non-string non-file objects.
For responses, this interceptor will unwrap JSON objects and parse them into Maps.
class DefaultTransformDataHttpInterceptor implements HttpInterceptor { Function request = (HttpResponseConfig config) { if (config.data != null && config.data is! String && config.data is! dom.File) { config.data = json.stringify(config.data); } return config; }; static var _JSON_START = new RegExp(r'^\s*(\[|\{[^\{])'); static var _JSON_END = new RegExp(r'[\}\]]\s*$'); static var _PROTECTION_PREFIX = new RegExp('^\\)\\]\\}\',?\\n'); Function response = (HttpResponse r) { if (r.data is String) { var d = r.data; d = d.replaceFirst(_PROTECTION_PREFIX, ''); if (d.contains(_JSON_START) && d.contains(_JSON_END)) { d = json.parse(d); } return new HttpResponse.copy(r, data: d); } return r; }; Function requestError, responseError; }
Implements
Properties
Function request #
Function request = (HttpResponseConfig config) { if (config.data != null && config.data is! String && config.data is! dom.File) { config.data = json.stringify(config.data); } return config; }
Function requestError #
Function requestError
Function response #
Function response = (HttpResponse r) { if (r.data is String) { var d = r.data; d = d.replaceFirst(_PROTECTION_PREFIX, ''); if (d.contains(_JSON_START) && d.contains(_JSON_END)) { d = json.parse(d); } return new HttpResponse.copy(r, data: d); } return r; }
Function responseError #
Function requestError, responseError