diff --git a/index.js b/index.js index 321af31..cbc2e68 100644 --- a/index.js +++ b/index.js @@ -4,9 +4,9 @@ var request = require('superagent'); // patch superagent to attach CSRF-token to all requests try { - var csrf = document.cookie.match(/csrftoken=(.*?)(?:$|;)/)[1]; var end = request.Request.prototype.end; request.Request.prototype.end = function(fn) { + var csrf = document.cookie.match(/csrftoken=(.*?)(?:$|;)/)[1]; this.set('X-CSRFToken', csrf); return end.call(this, fn); }; diff --git a/package.json b/package.json index 952f73c..5e42c60 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "superagent-django-csrf", - "version": "0.1.3", + "version": "0.1.4", "description": "Patch to add `csrftoken` from cookies as `X-CSRFToken` header to every superagent's request", "main": "index.js", "scripts": {