setPlainByDefault does not strip etag from responses

Author: luciopercaCreated Jan 14, 2017Updated Jan 30, 2019
Labelsbugwaiting for PR

Restangular is configured with setPlainByDefault(true). When running a query such as get() or getList() that retrieves a response with an ETag exposed, the result contains restangularEtag.

angular.module('app', ['restangular'])
  .config(function(RestangularProvider) {
    RestangularProvider.setBaseUrl('https://exposedetagresponder.org/');
    RestangularProvider.setPlainByDefault(true);
  })
  .controller('main', function($scope, Restangular) {
    Restangular.one('resource').get().then(elem => {
      console.log(elem.restangularEtag); // Outputs the response's etag
    });
    Restangular.all('resources').getList().then(list => {
      console.log(list.restangularEtag); // Outputs the response's etag
    });
  });

This is inconsistent with the behavior when calling plain() on the result directly, even though these are apparently intended to have the same outcome. (https://github.com/mgonto/restangular/commit/94ffaf0b72a9c10711cabec2d41ceae10282162c)

angular.module('app', ['restangular'])
  .config(function(RestangularProvider) {
    RestangularProvider.setBaseUrl('https://exposedetagresponder.org/');
  })
  .controller('main', function($scope, Restangular) {
    Restangular.one('resource').get().then(elem => {
      console.log(elem.plain().restangularEtag); // Outputs undefined
    });
    Restangular.all('resources').getList().then(list => {
      console.log(list.plain().restangularEtag); // Outputs undefined
    });
  });