{"action":"created","issue":{"url":"https://api.github.com/repos/visionmedia/superagent/issues/846","repository_url":"https://api.github.com/repos/visionmedia/superagent","labels_url":"https://api.github.com/repos/visionmedia/superagent/issues/846/labels{/name}","comments_url":"https://api.github.com/repos/visionmedia/superagent/issues/846/comments","events_url":"https://api.github.com/repos/visionmedia/superagent/issues/846/events","html_url":"https://github.com/visionmedia/superagent/pull/846","id":126300686,"number":846,"title":"Add .dataFilter function prior to parsing of body","user":{"login":"tquetano-r7","id":13334725,"avatar_url":"https://avatars.githubusercontent.com/u/13334725?v=3","gravatar_id":"","url":"https://api.github.com/users/tquetano-r7","html_url":"https://github.com/tquetano-r7","followers_url":"https://api.github.com/users/tquetano-r7/followers","following_url":"https://api.github.com/users/tquetano-r7/following{/other_user}","gists_url":"https://api.github.com/users/tquetano-r7/gists{/gist_id}","starred_url":"https://api.github.com/users/tquetano-r7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tquetano-r7/subscriptions","organizations_url":"https://api.github.com/users/tquetano-r7/orgs","repos_url":"https://api.github.com/users/tquetano-r7/repos","events_url":"https://api.github.com/users/tquetano-r7/events{/privacy}","received_events_url":"https://api.github.com/users/tquetano-r7/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-01-12T23:13:29Z","updated_at":"2016-03-02T17:53:06Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/visionmedia/superagent/pulls/846","html_url":"https://github.com/visionmedia/superagent/pull/846","diff_url":"https://github.com/visionmedia/superagent/pull/846.diff","patch_url":"https://github.com/visionmedia/superagent/pull/846.patch"},"body":"This function allows you to transform the data prior to parsing of the body. It attempts not to be opinionated on the type of data or what you are trying to do to it. The basic application:\r\n```\r\nrequest\r\n  .get('url.com/foo')\r\n  .dataFilter((data) => {\r\n    return data.replace(/text_to_strip/g, '');\r\n  })\r\n  .end((err, res) => {\r\n    console.log(res.body); // will have text_to_strip removed globally from the data\r\n  });\r\n```\r\nThe original application I was striving for was stripping of XSS prefixes / postfixes, however I tried to make it more generalized so that it could be used for a multitude of purposes. This method is only applied in the parseBody function, and if nothing is returned from the callback passed then it falls back to the original str value passed to parseBody.\r\n\r\nApologies in advance for the lack of commit squashing."},"comment":{"url":"https://api.github.com/repos/visionmedia/superagent/issues/comments/191348900","html_url":"https://github.com/visionmedia/superagent/pull/846#issuecomment-191348900","issue_url":"https://api.github.com/repos/visionmedia/superagent/issues/846","id":191348900,"user":{"login":"focusaurus","id":482377,"avatar_url":"https://avatars.githubusercontent.com/u/482377?v=3","gravatar_id":"","url":"https://api.github.com/users/focusaurus","html_url":"https://github.com/focusaurus","followers_url":"https://api.github.com/users/focusaurus/followers","following_url":"https://api.github.com/users/focusaurus/following{/other_user}","gists_url":"https://api.github.com/users/focusaurus/gists{/gist_id}","starred_url":"https://api.github.com/users/focusaurus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/focusaurus/subscriptions","organizations_url":"https://api.github.com/users/focusaurus/orgs","repos_url":"https://api.github.com/users/focusaurus/repos","events_url":"https://api.github.com/users/focusaurus/events{/privacy}","received_events_url":"https://api.github.com/users/focusaurus/received_events","type":"User","site_admin":false},"created_at":"2016-03-02T17:53:06Z","updated_at":"2016-03-02T17:53:06Z","body":"I would prefer not to add more API surface for this. Is this not reasonably achievable already with `request.parse['application/json'] = stripPrefixes`?\r\n\r\nIn either case this would need consistency in the node/client code before merging."}}